commit | author | age
|
7f7e0c
|
1 |
package org.keycloak.protocol.cas.mappers; |
MP |
2 |
|
|
3 |
import org.keycloak.models.ProtocolMapperModel; |
513246
|
4 |
import org.keycloak.models.UserModel; |
MP |
5 |
import org.keycloak.models.UserSessionModel; |
7f7e0c
|
6 |
import org.keycloak.protocol.cas.CASLoginProtocol; |
MP |
7 |
import org.keycloak.protocol.oidc.mappers.OIDCAttributeMapperHelper; |
|
8 |
import org.keycloak.provider.ProviderConfigProperty; |
|
9 |
|
|
10 |
import java.util.ArrayList; |
|
11 |
import java.util.HashMap; |
|
12 |
import java.util.List; |
|
13 |
import java.util.Map; |
|
14 |
|
|
15 |
import static org.keycloak.protocol.oidc.mappers.OIDCAttributeMapperHelper.TOKEN_CLAIM_NAME; |
|
16 |
|
|
17 |
public class FullNameMapper extends AbstractCASProtocolMapper { |
|
18 |
private static final List<ProviderConfigProperty> configProperties = new ArrayList<ProviderConfigProperty>(); |
|
19 |
|
|
20 |
static { |
|
21 |
OIDCAttributeMapperHelper.addTokenClaimNameConfig(configProperties); |
|
22 |
} |
|
23 |
|
|
24 |
public static final String PROVIDER_ID = "cas-full-name-mapper"; |
|
25 |
|
|
26 |
|
|
27 |
@Override |
|
28 |
public List<ProviderConfigProperty> getConfigProperties() { |
|
29 |
return configProperties; |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
public String getId() { |
|
34 |
return PROVIDER_ID; |
|
35 |
} |
|
36 |
|
|
37 |
@Override |
|
38 |
public String getDisplayType() { |
|
39 |
return "User's full name"; |
|
40 |
} |
|
41 |
|
|
42 |
@Override |
|
43 |
public String getHelpText() { |
|
44 |
return "Maps the user's first and last name to the OpenID Connect 'name' claim. Format is <first> + ' ' + <last>"; |
|
45 |
} |
|
46 |
|
513246
|
47 |
@Override |
MP |
48 |
public void setAttribute(Map<String, Object> attributes, ProtocolMapperModel mappingModel, UserSessionModel userSession) { |
|
49 |
UserModel user = userSession.getUser(); |
|
50 |
String protocolClaim = mappingModel.getConfig().get(TOKEN_CLAIM_NAME); |
|
51 |
if (protocolClaim == null) { |
|
52 |
return; |
|
53 |
} |
|
54 |
String first = user.getFirstName() == null ? "" : user.getFirstName() + " "; |
|
55 |
String last = user.getLastName() == null ? "" : user.getLastName(); |
|
56 |
attributes.put(protocolClaim, first + last); |
|
57 |
} |
|
58 |
|
7f7e0c
|
59 |
public static ProtocolMapperModel create(String name, String tokenClaimName, |
MP |
60 |
boolean consentRequired, String consentText) { |
|
61 |
ProtocolMapperModel mapper = new ProtocolMapperModel(); |
|
62 |
mapper.setName(name); |
|
63 |
mapper.setProtocolMapper(PROVIDER_ID); |
|
64 |
mapper.setProtocol(CASLoginProtocol.LOGIN_PROTOCOL); |
|
65 |
mapper.setConsentRequired(consentRequired); |
|
66 |
mapper.setConsentText(consentText); |
|
67 |
Map<String, String> config = new HashMap<String, String>(); |
|
68 |
config.put(TOKEN_CLAIM_NAME, tokenClaimName); |
|
69 |
mapper.setConfig(config); |
|
70 |
return mapper; |
|
71 |
} |
|
72 |
} |