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