114 boolean singleAttribute = Boolean.parseBoolean(single);
116 List<SamlProtocol.ProtocolMapperProcessor<SAMLRoleNameMapper>> roleNameMappers =
new LinkedList<>();
117 KeycloakSessionFactory sessionFactory = session.getKeycloakSessionFactory();
118 AttributeType singleAttributeType = null;
119 Set<ProtocolMapperModel> requestedProtocolMappers = clientSessionCtx.getProtocolMappers();
120 for (ProtocolMapperModel mapping : requestedProtocolMappers) {
122 ProtocolMapper mapper = (ProtocolMapper)sessionFactory.getProviderFactory(ProtocolMapper.class, mapping.getProtocolMapper());
123 if (mapper == null)
continue;
125 if (mapper instanceof SAMLRoleNameMapper) {
126 roleNameMappers.add(
new SamlProtocol.ProtocolMapperProcessor<>((SAMLRoleNameMapper) mapper,mapping));
129 if (mapper instanceof HardcodedRole) {
130 AttributeType attributeType;
131 if (singleAttribute) {
132 if (singleAttributeType == null) {
133 singleAttributeType = AttributeStatementHelper.createAttributeType(mappingModel);
134 roleAttributeStatement.addAttribute(
new AttributeStatementType.ASTChoiceType(singleAttributeType));
136 attributeType = singleAttributeType;
138 attributeType = AttributeStatementHelper.createAttributeType(mappingModel);
139 roleAttributeStatement.addAttribute(
new AttributeStatementType.ASTChoiceType(attributeType));
142 attributeType.addAttributeValue(mapping.getConfig().get(HardcodedRole.ROLE_ATTRIBUTE));
146 List<String> allRoleNames = clientSessionCtx.getRoles().stream()
148 .flatMap(RoleUtils::expandCompositeRolesStream)
149 .map(roleModel -> roleNameMappers.stream()
150 .map(entry -> entry.mapper.mapName(entry.model, roleModel))
151 .filter(Objects::nonNull)
153 .orElse(roleModel.getName())
154 ).collect(Collectors.toList());
156 for (String roleName : allRoleNames) {
157 AttributeType attributeType;
158 if (singleAttribute) {
159 if (singleAttributeType == null) {
160 singleAttributeType = AttributeStatementHelper.createAttributeType(mappingModel);
161 roleAttributeStatement.addAttribute(
new AttributeStatementType.ASTChoiceType(singleAttributeType));
163 attributeType = singleAttributeType;
165 attributeType = AttributeStatementHelper.createAttributeType(mappingModel);
166 roleAttributeStatement.addAttribute(
new AttributeStatementType.ASTChoiceType(attributeType));
169 attributeType.addAttributeValue(roleName);
static final String SINGLE_ROLE_ATTRIBUTE
Definition: RoleListMapper.java:47