Skip to content
This repository was archived by the owner on Oct 12, 2020. It is now read-only.

Commit e85007f

Browse files
committed
update for KEYCLOAK-8708 Provide aggregation of group attributes for mappers
1 parent ebda00d commit e85007f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/main/java/org/keycloak/protocol/cas/mappers/UserAttributeMapper.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.keycloak.provider.ProviderConfigProperty;
1010

1111
import java.util.ArrayList;
12+
import java.util.Collection;
1213
import java.util.List;
1314
import java.util.Map;
1415

@@ -33,6 +34,12 @@ public class UserAttributeMapper extends AbstractCASProtocolMapper {
3334
property.setType(ProviderConfigProperty.BOOLEAN_TYPE);
3435
configProperties.add(property);
3536

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);
3643
}
3744

3845
public static final String PROVIDER_ID = "cas-usermodel-attribute-mapper";
@@ -62,19 +69,29 @@ public String getHelpText() {
6269
public void setAttribute(Map<String, Object> attributes, ProtocolMapperModel mappingModel, UserSessionModel userSession) {
6370
UserModel user = userSession.getUser();
6471
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);
6674
setMappedAttribute(attributes, mappingModel, attributeValue);
6775
}
6876

6977
public static ProtocolMapperModel create(String name, String userAttribute,
7078
String tokenClaimName, String claimType,
7179
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) {
7286
ProtocolMapperModel mapper = CASAttributeMapperHelper.createClaimMapper(name, tokenClaimName,
7387
claimType, PROVIDER_ID);
7488
mapper.getConfig().put(ProtocolMapperUtils.USER_ATTRIBUTE, userAttribute);
7589
if (multivalued) {
7690
mapper.getConfig().put(ProtocolMapperUtils.MULTIVALUED, "true");
7791
}
92+
if (aggregateAttrs) {
93+
mapper.getConfig().put(ProtocolMapperUtils.AGGREGATE_ATTRS, "true");
94+
}
7895
return mapper;
7996
}
8097
}

0 commit comments

Comments
 (0)