Search in sources :

Example 16 with AttributeBean

use of org.apache.wss4j.common.saml.bean.AttributeBean in project cxf by apache.

the class SamlRoleCallbackHandler method handle.

public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof SAMLCallback) {
            SAMLCallback callback = (SAMLCallback) callbacks[i];
            if (saml2) {
                callback.setSamlVersion(Version.SAML_20);
            } else {
                callback.setSamlVersion(Version.SAML_11);
            }
            callback.setIssuer("sts");
            String subjectName = "uid=sts-client,o=mock-sts.com";
            String subjectQualifier = "www.mock-sts.com";
            if (!saml2 && SAML2Constants.CONF_SENDER_VOUCHES.equals(confirmationMethod)) {
                confirmationMethod = SAML1Constants.CONF_SENDER_VOUCHES;
            }
            SubjectBean subjectBean = new SubjectBean(subjectName, subjectQualifier, confirmationMethod);
            if (SAML2Constants.CONF_HOLDER_KEY.equals(confirmationMethod) || SAML1Constants.CONF_HOLDER_KEY.equals(confirmationMethod)) {
                try {
                    KeyInfoBean keyInfo = createKeyInfo();
                    subjectBean.setKeyInfo(keyInfo);
                } catch (Exception ex) {
                    throw new IOException("Problem creating KeyInfo: " + ex.getMessage());
                }
            }
            callback.setSubject(subjectBean);
            AttributeStatementBean attrBean = new AttributeStatementBean();
            attrBean.setSubject(subjectBean);
            AttributeBean attributeBean = new AttributeBean();
            attributeBean.setNameFormat(SAML2Constants.ATTRNAME_FORMAT_UNSPECIFIED);
            if (saml2) {
                attributeBean.setQualifiedName(ROLE_URI);
                attributeBean.setNameFormat(SAML2Constants.ATTRNAME_FORMAT_UNSPECIFIED);
            } else {
                String uri = ROLE_URI.toString();
                int lastSlash = uri.lastIndexOf("/");
                if (lastSlash == (uri.length() - 1)) {
                    uri = uri.substring(0, lastSlash);
                    lastSlash = uri.lastIndexOf("/");
                }
                String namespace = uri.substring(0, lastSlash);
                String name = uri.substring(lastSlash + 1, uri.length());
                attributeBean.setSimpleName(name);
                attributeBean.setQualifiedName(namespace);
            }
            attributeBean.addAttributeValue(roleName);
            attrBean.setSamlAttributes(Collections.singletonList(attributeBean));
            callback.setAttributeStatementData(Collections.singletonList(attrBean));
            try {
                Crypto crypto = CryptoFactory.getInstance(cryptoPropertiesFile);
                callback.setIssuerCrypto(crypto);
                callback.setIssuerKeyName(cryptoAlias);
                callback.setIssuerKeyPassword(cryptoPassword);
                callback.setSignAssertion(signAssertion);
            } catch (Exception ex) {
                throw new IOException("Problem creating KeyInfo: " + ex.getMessage());
            }
        }
    }
}
Also used : SubjectBean(org.apache.wss4j.common.saml.bean.SubjectBean) KeyInfoBean(org.apache.wss4j.common.saml.bean.KeyInfoBean) AttributeStatementBean(org.apache.wss4j.common.saml.bean.AttributeStatementBean) Crypto(org.apache.wss4j.common.crypto.Crypto) SAMLCallback(org.apache.wss4j.common.saml.SAMLCallback) IOException(java.io.IOException) AttributeBean(org.apache.wss4j.common.saml.bean.AttributeBean) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) IOException(java.io.IOException)

Example 17 with AttributeBean

use of org.apache.wss4j.common.saml.bean.AttributeBean in project cxf by apache.

the class ActAsAttributeStatementProvider method getStatement.

/**
 * Get an AttributeStatementBean using the given parameters.
 */
public AttributeStatementBean getStatement(TokenProviderParameters providerParameters) {
    AttributeStatementBean attrBean = new AttributeStatementBean();
    TokenRequirements tokenRequirements = providerParameters.getTokenRequirements();
    ReceivedToken actAs = tokenRequirements.getActAs();
    try {
        if (actAs != null) {
            List<AttributeBean> attributeList = new ArrayList<>();
            String tokenType = tokenRequirements.getTokenType();
            AttributeBean parameterBean = handleAdditionalParameters(actAs.getToken(), tokenType);
            if (!parameterBean.getAttributeValues().isEmpty()) {
                attributeList.add(parameterBean);
            }
            attrBean.setSamlAttributes(attributeList);
        }
    } catch (WSSecurityException ex) {
        throw new STSException(ex.getMessage(), ex);
    }
    return attrBean;
}
Also used : AttributeStatementBean(org.apache.wss4j.common.saml.bean.AttributeStatementBean) TokenRequirements(org.apache.cxf.sts.request.TokenRequirements) ArrayList(java.util.ArrayList) STSException(org.apache.cxf.ws.security.sts.provider.STSException) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) ReceivedToken(org.apache.cxf.sts.request.ReceivedToken) AttributeBean(org.apache.wss4j.common.saml.bean.AttributeBean)

Example 18 with AttributeBean

use of org.apache.wss4j.common.saml.bean.AttributeBean in project cxf by apache.

the class ClaimsAttributeStatementProvider method getStatement.

public AttributeStatementBean getStatement(TokenProviderParameters providerParameters) {
    // Handle Claims
    ProcessedClaimCollection retrievedClaims = ClaimsUtils.processClaims(providerParameters);
    if (retrievedClaims == null) {
        return null;
    }
    Iterator<ProcessedClaim> claimIterator = retrievedClaims.iterator();
    if (!claimIterator.hasNext()) {
        return null;
    }
    List<AttributeBean> attributeList = new ArrayList<>();
    String tokenType = providerParameters.getTokenRequirements().getTokenType();
    AttributeStatementBean attrBean = new AttributeStatementBean();
    while (claimIterator.hasNext()) {
        ProcessedClaim claim = claimIterator.next();
        AttributeBean attributeBean = new AttributeBean();
        URI claimType = claim.getClaimType();
        if (WSS4JConstants.WSS_SAML2_TOKEN_TYPE.equals(tokenType) || WSS4JConstants.SAML2_NS.equals(tokenType)) {
            attributeBean.setQualifiedName(claimType.toString());
            attributeBean.setNameFormat(nameFormat);
        } else {
            String uri = claimType.toString();
            int lastSlash = uri.lastIndexOf("/");
            if (lastSlash == (uri.length() - 1)) {
                uri = uri.substring(0, lastSlash);
                lastSlash = uri.lastIndexOf("/");
            }
            String namespace = uri.substring(0, lastSlash);
            String name = uri.substring(lastSlash + 1, uri.length());
            attributeBean.setSimpleName(name);
            attributeBean.setQualifiedName(namespace);
        }
        attributeBean.setAttributeValues(claim.getValues());
        attributeList.add(attributeBean);
    }
    attrBean.setSamlAttributes(attributeList);
    return attrBean;
}
Also used : AttributeStatementBean(org.apache.wss4j.common.saml.bean.AttributeStatementBean) ArrayList(java.util.ArrayList) AttributeBean(org.apache.wss4j.common.saml.bean.AttributeBean) URI(java.net.URI)

Example 19 with AttributeBean

use of org.apache.wss4j.common.saml.bean.AttributeBean in project cxf by apache.

the class CustomAttributeProvider method createDefaultAttribute.

/**
 * Create a default attribute
 */
private AttributeBean createDefaultAttribute(String tokenType) {
    AttributeBean attributeBean = new AttributeBean();
    if (WSS4JConstants.WSS_SAML2_TOKEN_TYPE.equals(tokenType) || WSS4JConstants.SAML2_NS.equals(tokenType)) {
        attributeBean.setQualifiedName("token-requestor");
        attributeBean.setNameFormat("http://cxf.apache.org/sts/custom");
    } else {
        attributeBean.setSimpleName("token-requestor");
        attributeBean.setQualifiedName("http://cxf.apache.org/sts/custom");
    }
    attributeBean.addAttributeValue("authenticated");
    return attributeBean;
}
Also used : AttributeBean(org.apache.wss4j.common.saml.bean.AttributeBean)

Example 20 with AttributeBean

use of org.apache.wss4j.common.saml.bean.AttributeBean in project cxf by apache.

the class CustomAttributeStatementProvider method getStatement.

public AttributeStatementBean getStatement(TokenProviderParameters providerParameters) {
    // Handle Claims
    ClaimsManager claimsManager = providerParameters.getClaimsManager();
    ProcessedClaimCollection retrievedClaims = new ProcessedClaimCollection();
    if (claimsManager != null) {
        ClaimsParameters params = new ClaimsParameters();
        params.setAdditionalProperties(providerParameters.getAdditionalProperties());
        params.setAppliesToAddress(providerParameters.getAppliesToAddress());
        params.setEncryptionProperties(providerParameters.getEncryptionProperties());
        params.setKeyRequirements(providerParameters.getKeyRequirements());
        params.setPrincipal(providerParameters.getPrincipal());
        params.setRealm(providerParameters.getRealm());
        params.setStsProperties(providerParameters.getStsProperties());
        params.setTokenRequirements(providerParameters.getTokenRequirements());
        params.setTokenStore(providerParameters.getTokenStore());
        params.setMessageContext(providerParameters.getMessageContext());
        retrievedClaims = claimsManager.retrieveClaimValues(providerParameters.getRequestedPrimaryClaims(), providerParameters.getRequestedSecondaryClaims(), params);
    }
    if (retrievedClaims == null) {
        return null;
    }
    Iterator<ProcessedClaim> claimIterator = retrievedClaims.iterator();
    if (!claimIterator.hasNext()) {
        return null;
    }
    List<AttributeBean> attributeList = new ArrayList<>();
    String tokenType = providerParameters.getTokenRequirements().getTokenType();
    AttributeStatementBean attrBean = new AttributeStatementBean();
    while (claimIterator.hasNext()) {
        ProcessedClaim claim = claimIterator.next();
        AttributeBean attributeBean = new AttributeBean();
        URI claimType = claim.getClaimType();
        if (WSS4JConstants.WSS_SAML2_TOKEN_TYPE.equals(tokenType) || WSS4JConstants.SAML2_NS.equals(tokenType)) {
            attributeBean.setQualifiedName(claimType.toString());
            attributeBean.setNameFormat(nameFormat);
        } else {
            String uri = claimType.toString();
            int lastSlash = uri.lastIndexOf("/");
            if (lastSlash == (uri.length() - 1)) {
                uri = uri.substring(0, lastSlash);
                lastSlash = uri.lastIndexOf("/");
            }
            String namespace = uri.substring(0, lastSlash);
            String name = uri.substring(lastSlash + 1, uri.length());
            attributeBean.setSimpleName(name);
            attributeBean.setQualifiedName(namespace);
        }
        attributeBean.setAttributeValues(claim.getValues());
        attributeList.add(attributeBean);
    }
    attrBean.setSamlAttributes(attributeList);
    return attrBean;
}
Also used : AttributeStatementBean(org.apache.wss4j.common.saml.bean.AttributeStatementBean) ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) ArrayList(java.util.ArrayList) ClaimsManager(org.apache.cxf.sts.claims.ClaimsManager) AttributeBean(org.apache.wss4j.common.saml.bean.AttributeBean) URI(java.net.URI) ClaimsParameters(org.apache.cxf.sts.claims.ClaimsParameters)

Aggregations

AttributeBean (org.apache.wss4j.common.saml.bean.AttributeBean)24 AttributeStatementBean (org.apache.wss4j.common.saml.bean.AttributeStatementBean)15 SAMLCallback (org.apache.wss4j.common.saml.SAMLCallback)12 ArrayList (java.util.ArrayList)8 SubjectBean (org.apache.wss4j.common.saml.bean.SubjectBean)8 IOException (java.io.IOException)7 Crypto (org.apache.wss4j.common.crypto.Crypto)7 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)7 SamlAssertionWrapper (org.apache.wss4j.common.saml.SamlAssertionWrapper)6 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)5 KeyInfoBean (org.apache.wss4j.common.saml.bean.KeyInfoBean)5 Principal (java.security.Principal)4 ClaimCollection (org.apache.cxf.rt.security.claims.ClaimCollection)4 ActionBean (org.apache.wss4j.common.saml.bean.ActionBean)4 AuthDecisionStatementBean (org.apache.wss4j.common.saml.bean.AuthDecisionStatementBean)4 AuthenticationStatementBean (org.apache.wss4j.common.saml.bean.AuthenticationStatementBean)4 Document (org.w3c.dom.Document)4 Claim (org.apache.cxf.rt.security.claims.Claim)3 TokenRequirements (org.apache.cxf.sts.request.TokenRequirements)3 URI (java.net.URI)2