commit | author | age
|
7f7e0c
|
1 |
package org.keycloak.protocol.cas.mappers; |
MP |
2 |
|
|
3 |
import org.keycloak.models.ProtocolMapperModel; |
|
4 |
import org.keycloak.protocol.ProtocolMapperUtils; |
|
5 |
import org.keycloak.protocol.cas.CASLoginProtocol; |
|
6 |
import org.keycloak.protocol.oidc.mappers.OIDCAttributeMapperHelper; |
|
7 |
import org.keycloak.provider.ProviderConfigProperty; |
|
8 |
|
|
9 |
import java.util.ArrayList; |
|
10 |
import java.util.HashMap; |
|
11 |
import java.util.List; |
|
12 |
import java.util.Map; |
|
13 |
|
|
14 |
import static org.keycloak.protocol.oidc.mappers.OIDCAttributeMapperHelper.JSON_TYPE; |
|
15 |
import static org.keycloak.protocol.oidc.mappers.OIDCAttributeMapperHelper.TOKEN_CLAIM_NAME; |
|
16 |
|
|
17 |
public class UserAttributeMapper extends AbstractCASProtocolMapper { |
|
18 |
private static final List<ProviderConfigProperty> configProperties = new ArrayList<ProviderConfigProperty>(); |
|
19 |
|
|
20 |
static { |
|
21 |
ProviderConfigProperty property; |
|
22 |
property = new ProviderConfigProperty(); |
|
23 |
property.setName(ProtocolMapperUtils.USER_ATTRIBUTE); |
|
24 |
property.setLabel(ProtocolMapperUtils.USER_MODEL_ATTRIBUTE_LABEL); |
|
25 |
property.setHelpText(ProtocolMapperUtils.USER_MODEL_ATTRIBUTE_HELP_TEXT); |
|
26 |
property.setType(ProviderConfigProperty.STRING_TYPE); |
|
27 |
configProperties.add(property); |
|
28 |
OIDCAttributeMapperHelper.addTokenClaimNameConfig(configProperties); |
|
29 |
OIDCAttributeMapperHelper.addJsonTypeConfig(configProperties); |
|
30 |
|
|
31 |
property = new ProviderConfigProperty(); |
|
32 |
property.setName(ProtocolMapperUtils.MULTIVALUED); |
|
33 |
property.setLabel(ProtocolMapperUtils.MULTIVALUED_LABEL); |
|
34 |
property.setHelpText(ProtocolMapperUtils.MULTIVALUED_HELP_TEXT); |
|
35 |
property.setType(ProviderConfigProperty.BOOLEAN_TYPE); |
|
36 |
configProperties.add(property); |
|
37 |
|
|
38 |
} |
|
39 |
|
|
40 |
public static final String PROVIDER_ID = "cas-usermodel-attribute-mapper"; |
|
41 |
|
|
42 |
|
|
43 |
@Override |
|
44 |
public List<ProviderConfigProperty> getConfigProperties() { |
|
45 |
return configProperties; |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public String getId() { |
|
50 |
return PROVIDER_ID; |
|
51 |
} |
|
52 |
|
|
53 |
@Override |
|
54 |
public String getDisplayType() { |
|
55 |
return "User Attribute"; |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public String getHelpText() { |
|
60 |
return "Map a custom user attribute to a token claim."; |
|
61 |
} |
|
62 |
|
|
63 |
public static ProtocolMapperModel create(String name, String userAttribute, |
|
64 |
String tokenClaimName, String claimType, |
|
65 |
boolean consentRequired, String consentText, boolean multivalued) { |
|
66 |
ProtocolMapperModel mapper = new ProtocolMapperModel(); |
|
67 |
mapper.setName(name); |
|
68 |
mapper.setProtocolMapper(PROVIDER_ID); |
|
69 |
mapper.setProtocol(CASLoginProtocol.LOGIN_PROTOCOL); |
|
70 |
mapper.setConsentRequired(consentRequired); |
|
71 |
mapper.setConsentText(consentText); |
|
72 |
Map<String, String> config = new HashMap<String, String>(); |
|
73 |
config.put(ProtocolMapperUtils.USER_ATTRIBUTE, userAttribute); |
|
74 |
config.put(TOKEN_CLAIM_NAME, tokenClaimName); |
|
75 |
config.put(JSON_TYPE, claimType); |
|
76 |
if (multivalued) { |
|
77 |
mapper.getConfig().put(ProtocolMapperUtils.MULTIVALUED, "true"); |
|
78 |
} |
|
79 |
mapper.setConfig(config); |
|
80 |
return mapper; |
|
81 |
} |
|
82 |
} |