use of org.apereo.cas.authentication.SecurityTokenServiceClient in project cas by apereo.
the class DefaultRelyingPartyTokenProducer method mapAttributesToRequestedClaims.
@SneakyThrows
private void mapAttributesToRequestedClaims(final WSFederationRegisteredService service, final SecurityTokenServiceClient sts, final Assertion assertion) {
val writer = new W3CDOMStreamWriter();
writer.writeStartElement("wst", "Claims", STSUtils.WST_NS_05_12);
writer.writeNamespace("wst", STSUtils.WST_NS_05_12);
writer.writeNamespace("ic", WSFederationConstants.HTTP_SCHEMAS_XMLSOAP_ORG_WS_2005_05_IDENTITY);
writer.writeAttribute("Dialect", WSFederationConstants.HTTP_SCHEMAS_XMLSOAP_ORG_WS_2005_05_IDENTITY);
val attributes = assertion.getPrincipal().getAttributes();
LOGGER.debug("Mapping principal attributes [{}] to claims for service [{}]", attributes, service);
attributes.forEach(Unchecked.biConsumer((k, v) -> {
val claimName = ProtocolAttributeEncoder.decodeAttribute(k);
if (WSFederationClaims.contains(claimName)) {
val uri = WSFederationClaims.valueOf(k).getUri();
LOGGER.debug("Requested claim [{}] mapped to [{}]", k, uri);
writeAttributeValue(writer, uri, v, service);
} else if (WSFederationClaims.containsUri(claimName)) {
LOGGER.debug("Requested claim [{}] directly mapped to [{}]", k, claimName);
writeAttributeValue(writer, claimName, v, service);
} else if (customClaims.contains(claimName)) {
LOGGER.debug("Requested custom claim [{}]", claimName);
writeAttributeValue(writer, claimName, v, service);
} else {
LOGGER.debug("Requested claim [{}] is not defined/supported by CAS", claimName);
writeAttributeValue(writer, WSFederationConstants.getClaimInCasNamespace(claimName), v, service);
}
}));
writer.writeEndElement();
val claims = writer.getDocument().getDocumentElement();
sts.setClaims(claims);
}
Aggregations