commit | author | age
|
7f7e0c
|
1 |
package org.keycloak.protocol.cas.mappers; |
MP |
2 |
|
89e3d7
|
3 |
import org.keycloak.models.*; |
7f7e0c
|
4 |
import org.keycloak.protocol.oidc.mappers.OIDCAttributeMapperHelper; |
MP |
5 |
import org.keycloak.provider.ProviderConfigProperty; |
|
6 |
|
|
7 |
import java.util.ArrayList; |
|
8 |
import java.util.List; |
|
9 |
import java.util.Map; |
|
10 |
|
|
11 |
public class FullNameMapper extends AbstractCASProtocolMapper { |
|
12 |
private static final List<ProviderConfigProperty> configProperties = new ArrayList<ProviderConfigProperty>(); |
|
13 |
|
|
14 |
static { |
|
15 |
OIDCAttributeMapperHelper.addTokenClaimNameConfig(configProperties); |
|
16 |
} |
|
17 |
|
|
18 |
public static final String PROVIDER_ID = "cas-full-name-mapper"; |
|
19 |
|
|
20 |
|
|
21 |
@Override |
|
22 |
public List<ProviderConfigProperty> getConfigProperties() { |
|
23 |
return configProperties; |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
public String getId() { |
|
28 |
return PROVIDER_ID; |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
public String getDisplayType() { |
|
33 |
return "User's full name"; |
|
34 |
} |
|
35 |
|
|
36 |
@Override |
|
37 |
public String getHelpText() { |
|
38 |
return "Maps the user's first and last name to the OpenID Connect 'name' claim. Format is <first> + ' ' + <last>"; |
|
39 |
} |
|
40 |
|
513246
|
41 |
@Override |
89e3d7
|
42 |
public void setAttribute(Map<String, Object> attributes, ProtocolMapperModel mappingModel, UserSessionModel userSession, |
MP |
43 |
KeycloakSession session, ClientSessionContext clientSessionCt) { |
513246
|
44 |
UserModel user = userSession.getUser(); |
MP |
45 |
String first = user.getFirstName() == null ? "" : user.getFirstName() + " "; |
|
46 |
String last = user.getLastName() == null ? "" : user.getLastName(); |
0ad1a9
|
47 |
setMappedAttribute(attributes, mappingModel, first + last); |
513246
|
48 |
} |
MP |
49 |
|
b8d686
|
50 |
public static ProtocolMapperModel create(String name, String tokenClaimName) { |
0ad1a9
|
51 |
return CASAttributeMapperHelper.createClaimMapper(name, tokenClaimName, |
b8d686
|
52 |
"String", PROVIDER_ID); |
7f7e0c
|
53 |
} |
MP |
54 |
} |