9
9
import org .keycloak .provider .ProviderConfigProperty ;
10
10
11
11
import java .util .ArrayList ;
12
+ import java .util .Collection ;
12
13
import java .util .List ;
13
14
import java .util .Map ;
14
15
@@ -33,6 +34,12 @@ public class UserAttributeMapper extends AbstractCASProtocolMapper {
33
34
property .setType (ProviderConfigProperty .BOOLEAN_TYPE );
34
35
configProperties .add (property );
35
36
37
+ property = new ProviderConfigProperty ();
38
+ property .setName (ProtocolMapperUtils .AGGREGATE_ATTRS );
39
+ property .setLabel (ProtocolMapperUtils .AGGREGATE_ATTRS_LABEL );
40
+ property .setHelpText (ProtocolMapperUtils .AGGREGATE_ATTRS_HELP_TEXT );
41
+ property .setType (ProviderConfigProperty .BOOLEAN_TYPE );
42
+ configProperties .add (property );
36
43
}
37
44
38
45
public static final String PROVIDER_ID = "cas-usermodel-attribute-mapper" ;
@@ -62,19 +69,29 @@ public String getHelpText() {
62
69
public void setAttribute (Map <String , Object > attributes , ProtocolMapperModel mappingModel , UserSessionModel userSession ) {
63
70
UserModel user = userSession .getUser ();
64
71
String attributeName = mappingModel .getConfig ().get (ProtocolMapperUtils .USER_ATTRIBUTE );
65
- List <String > attributeValue = KeycloakModelUtils .resolveAttribute (user , attributeName );
72
+ boolean aggregateAttrs = Boolean .valueOf (mappingModel .getConfig ().get (ProtocolMapperUtils .AGGREGATE_ATTRS ));
73
+ Collection <String > attributeValue = KeycloakModelUtils .resolveAttribute (user , attributeName , aggregateAttrs );
66
74
setMappedAttribute (attributes , mappingModel , attributeValue );
67
75
}
68
76
69
77
public static ProtocolMapperModel create (String name , String userAttribute ,
70
78
String tokenClaimName , String claimType ,
71
79
boolean multivalued ) {
80
+ return create (name , userAttribute , tokenClaimName , claimType , multivalued , false );
81
+ }
82
+
83
+ public static ProtocolMapperModel create (String name , String userAttribute ,
84
+ String tokenClaimName , String claimType ,
85
+ boolean multivalued , boolean aggregateAttrs ) {
72
86
ProtocolMapperModel mapper = CASAttributeMapperHelper .createClaimMapper (name , tokenClaimName ,
73
87
claimType , PROVIDER_ID );
74
88
mapper .getConfig ().put (ProtocolMapperUtils .USER_ATTRIBUTE , userAttribute );
75
89
if (multivalued ) {
76
90
mapper .getConfig ().put (ProtocolMapperUtils .MULTIVALUED , "true" );
77
91
}
92
+ if (aggregateAttrs ) {
93
+ mapper .getConfig ().put (ProtocolMapperUtils .AGGREGATE_ATTRS , "true" );
94
+ }
78
95
return mapper ;
79
96
}
80
97
}
0 commit comments