Search in sources :

Example 1 with SecurityTokenServiceClient

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);
}
Also used : lombok.val(lombok.val) DOMSource(javax.xml.transform.dom.DOMSource) SneakyThrows(lombok.SneakyThrows) CipherExecutor(org.apereo.cas.util.crypto.CipherExecutor) StreamResult(javax.xml.transform.stream.StreamResult) RequiredArgsConstructor(lombok.RequiredArgsConstructor) WSFederationRequest(org.apereo.cas.ws.idp.web.WSFederationRequest) BooleanUtils(org.apache.commons.lang3.BooleanUtils) Assertion(org.jasig.cas.client.validation.Assertion) ProtocolAttributeEncoder(org.apereo.cas.authentication.ProtocolAttributeEncoder) LoggingUtils(org.apereo.cas.util.LoggingUtils) HttpServletRequest(javax.servlet.http.HttpServletRequest) CollectionUtils(org.apereo.cas.util.CollectionUtils) XMLConstants(javax.xml.XMLConstants) ProcessingException(org.apache.cxf.fediz.core.exception.ProcessingException) Unchecked(org.jooq.lambda.Unchecked) WSFederationConstants(org.apereo.cas.ws.idp.WSFederationConstants) STSUtils(org.apache.cxf.ws.security.trust.STSUtils) StringWriter(java.io.StringWriter) lombok.val(lombok.val) Set(java.util.Set) SecurityConstants(org.apache.cxf.rt.security.SecurityConstants) OutputKeys(javax.xml.transform.OutputKeys) WSFederationClaims(org.apereo.cas.ws.idp.WSFederationClaims) W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) Slf4j(lombok.extern.slf4j.Slf4j) Element(org.w3c.dom.Element) SecurityTokenServiceClientBuilder(org.apereo.cas.authentication.SecurityTokenServiceClientBuilder) SecurityTokenServiceClient(org.apereo.cas.authentication.SecurityTokenServiceClient) TransformerFactory(javax.xml.transform.TransformerFactory) SoapFault(org.apache.cxf.binding.soap.SoapFault) W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) SneakyThrows(lombok.SneakyThrows)

Aggregations

StringWriter (java.io.StringWriter)1 Set (java.util.Set)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 XMLConstants (javax.xml.XMLConstants)1 OutputKeys (javax.xml.transform.OutputKeys)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 SneakyThrows (lombok.SneakyThrows)1 Slf4j (lombok.extern.slf4j.Slf4j)1 lombok.val (lombok.val)1 BooleanUtils (org.apache.commons.lang3.BooleanUtils)1 SoapFault (org.apache.cxf.binding.soap.SoapFault)1 ProcessingException (org.apache.cxf.fediz.core.exception.ProcessingException)1 SecurityConstants (org.apache.cxf.rt.security.SecurityConstants)1 W3CDOMStreamWriter (org.apache.cxf.staxutils.W3CDOMStreamWriter)1 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)1 STSUtils (org.apache.cxf.ws.security.trust.STSUtils)1 ProtocolAttributeEncoder (org.apereo.cas.authentication.ProtocolAttributeEncoder)1