Skip to content

Commit

Permalink
Return empty list instead of null if attribute is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
kberzinch committed Sep 19, 2024
1 parent 11ca6ec commit 0b42f0a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ public abstract class AbstractAttributeMapper extends AbstractIdentityProviderMa

public static List<String> getAttributeValue(
final IdentityProviderMapperModel mapperModel, final BrokeredIdentityContext user) {
String attributeName = mapperModel.getConfig().get(ATTRIBUTE);
@SuppressWarnings("unchecked")
Map<String, List<String>> userAttributes =
(Map<String, List<String>>) user.getContextData().get(CasIdentityProvider.USER_ATTRIBUTES);
logger.debug("getAttributeValue attributes: " + userAttributes);
return userAttributes.get(attributeName);
return userAttributes.getOrDefault(
mapperModel.getConfig().get(ATTRIBUTE), Collections.emptyList());
}

protected boolean hasAttributeValue(
final IdentityProviderMapperModel mapperModel, final BrokeredIdentityContext context) {
List<String> value = getAttributeValue(mapperModel, context);
String desiredValue = mapperModel.getConfig().get(ATTRIBUTE_VALUE);
return CollectionUtil.collectionEquals(Collections.singletonList(desiredValue), value);
return CollectionUtil.collectionEquals(
Collections.singletonList(mapperModel.getConfig().get(ATTRIBUTE_VALUE)),
getAttributeValue(mapperModel, context));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ public void preprocessFederatedIdentity(

List<String> value = getAttributeValue(mapperModel, context);

if (value != null) {
logger.debug("Values: " + value);
} else {
logger.debug("Values: null");
}
logger.debug("Values: " + value);

if (EMAIL.equalsIgnoreCase(attribute)) {
setIfNotEmpty(context::setEmail, value);
Expand Down Expand Up @@ -124,11 +120,7 @@ public void updateBrokeredUser(

List<String> value = getAttributeValue(mapperModel, context);

if (value != null) {
logger.debug("Values: " + value);
} else {
logger.debug("Values: null");
}
logger.debug("Values: " + value);

if (EMAIL.equalsIgnoreCase(attribute)) {
setIfNotEmpty(user::setEmail, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public static UriBuilder createValidateServiceUrl(

public static UriBuilder createLogoutUrl(
final CasIdentityProviderConfig config, final RealmModel realm, final UriInfo uriInfo) {
final String redirect =
RealmsResource.brokerUrl(uriInfo)
.path(IdentityBrokerService.class, "getEndpoint")
.path(CasIdentityProvider.Endpoint.class, "logoutResponse")
.build(realm.getName(), config.getAlias())
.toString();
return UriBuilder.fromUri(config.getCasServerLogoutUrl())
.queryParam(PROVIDER_PARAMETER_SERVICE, redirect);
.queryParam(
PROVIDER_PARAMETER_SERVICE,
RealmsResource.brokerUrl(uriInfo)
.path(IdentityBrokerService.class, "getEndpoint")
.path(CasIdentityProvider.Endpoint.class, "logoutResponse")
.build(realm.getName(), config.getAlias())
.toString());
}
}

0 comments on commit 0b42f0a

Please sign in to comment.