@Override
public Map<String, Object> getAttributesInternal(final Principal principal, final Map<String, Object> attributes, final RegisteredService service) {
val applicationContext = ApplicationContextProvider.getApplicationContext();
if (applicationContext == null) {
LOGGER.warn("Could not locate the application context to process attributes");
return new HashMap<>();
}
val resolvedAttributes = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
resolvedAttributes.putAll(attributes);
val attributesToRelease = Maps.<String, Object>newHashMapWithExpectedSize(attributes.size());
LOGGER.debug("Attempting to map and filter claims based on resolved attributes [{}]", resolvedAttributes);
val properties = applicationContext.getBean(CasConfigurationProperties.class);
val supportedClaims = properties.getAuthn().getOidc().getClaims();
val allowedClaims = new LinkedHashSet<String>(getAllowedAttributes());
allowedClaims.retainAll(supportedClaims);
LOGGER.debug("[{}] is designed to allow claims [{}] for scope [{}]. After cross-checking with "
+ "supported claims [{}], the final collection of allowed attributes is [{}]", getClass().getSimpleName(),
getAllowedAttributes(), getScopeName(), supportedClaims, allowedClaims);
allowedClaims.stream()
.map(claim -> mapClaimToAttribute(claim, resolvedAttributes))
.filter(p -> p.getValue() != null)
.forEach(p -> attributesToRelease.put(p.getKey(), p.getValue()));
return attributesToRelease;
}