commit | author | age
|
7f7e0c
|
1 |
package org.keycloak.protocol.cas.mappers; |
MP |
2 |
|
513246
|
3 |
import org.keycloak.models.ProtocolMapperModel; |
MP |
4 |
import org.keycloak.models.UserSessionModel; |
7f7e0c
|
5 |
import org.keycloak.protocol.oidc.mappers.OIDCAttributeMapperHelper; |
MP |
6 |
import org.keycloak.provider.ProviderConfigProperty; |
|
7 |
|
|
8 |
import java.util.ArrayList; |
|
9 |
import java.util.List; |
513246
|
10 |
import java.util.Map; |
MP |
11 |
|
|
12 |
import static org.keycloak.protocol.oidc.mappers.OIDCAttributeMapperHelper.TOKEN_CLAIM_NAME; |
7f7e0c
|
13 |
|
MP |
14 |
public class HardcodedClaim extends AbstractCASProtocolMapper { |
|
15 |
private static final List<ProviderConfigProperty> configProperties = new ArrayList<ProviderConfigProperty>(); |
|
16 |
|
|
17 |
public static final String CLAIM_VALUE = "claim.value"; |
|
18 |
|
|
19 |
static { |
|
20 |
OIDCAttributeMapperHelper.addTokenClaimNameConfig(configProperties); |
|
21 |
|
|
22 |
ProviderConfigProperty property = new ProviderConfigProperty(); |
|
23 |
property.setName(CLAIM_VALUE); |
|
24 |
property.setLabel("Claim value"); |
|
25 |
property.setType(ProviderConfigProperty.STRING_TYPE); |
|
26 |
property.setHelpText("Value of the claim you want to hard code. 'true' and 'false can be used for boolean values."); |
|
27 |
configProperties.add(property); |
|
28 |
|
|
29 |
OIDCAttributeMapperHelper.addJsonTypeConfig(configProperties); |
|
30 |
} |
|
31 |
|
|
32 |
public static final String PROVIDER_ID = "cas-hardcoded-claim-mapper"; |
|
33 |
|
|
34 |
|
|
35 |
@Override |
|
36 |
public List<ProviderConfigProperty> getConfigProperties() { |
|
37 |
return configProperties; |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
public String getId() { |
|
42 |
return PROVIDER_ID; |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
public String getDisplayType() { |
|
47 |
return "Hardcoded claim"; |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
public String getHelpText() { |
|
52 |
return "Hardcode a claim into the token."; |
|
53 |
} |
|
54 |
|
513246
|
55 |
@Override |
MP |
56 |
public void setAttribute(Map<String, Object> attributes, ProtocolMapperModel mappingModel, UserSessionModel userSession) { |
|
57 |
String protocolClaim = mappingModel.getConfig().get(TOKEN_CLAIM_NAME); |
|
58 |
if (protocolClaim == null) { |
|
59 |
return; |
|
60 |
} |
|
61 |
String attributeValue = mappingModel.getConfig().get(CLAIM_VALUE); |
|
62 |
if (attributeValue == null) return; |
|
63 |
attributes.put(protocolClaim, OIDCAttributeMapperHelper.mapAttributeValue(mappingModel, attributeValue)); |
|
64 |
} |
|
65 |
|
7f7e0c
|
66 |
} |