Search in sources :

Example 1 with AlgorithmSuite

use of org.apache.wss4j.common.crypto.AlgorithmSuite in project cxf by apache.

the class AlgorithmSuiteTranslater method translateAlgorithmSuites.

public void translateAlgorithmSuites(AssertionInfoMap aim, RequestData data) throws WSSecurityException {
    if (aim == null) {
        return;
    }
    List<org.apache.wss4j.policy.model.AlgorithmSuite> algorithmSuites = getAlgorithmSuites(getBindings(aim));
    if (!algorithmSuites.isEmpty()) {
        // Translate into WSS4J's AlgorithmSuite class
        AlgorithmSuite algorithmSuite = translateAlgorithmSuites(algorithmSuites);
        data.setAlgorithmSuite(algorithmSuite);
    }
    // Now look for an AlgorithmSuite for a SAML Assertion
    Collection<AssertionInfo> ais = PolicyUtils.getAllAssertionsByLocalname(aim, SPConstants.SAML_TOKEN);
    if (!ais.isEmpty()) {
        List<org.apache.wss4j.policy.model.AlgorithmSuite> samlAlgorithmSuites = new ArrayList<>();
        for (AssertionInfo ai : ais) {
            SamlToken samlToken = (SamlToken) ai.getAssertion();
            AbstractSecurityAssertion parentAssertion = samlToken.getParentAssertion();
            if (parentAssertion instanceof SupportingTokens && ((SupportingTokens) parentAssertion).getAlgorithmSuite() != null) {
                samlAlgorithmSuites.add(((SupportingTokens) parentAssertion).getAlgorithmSuite());
            }
        }
        if (!samlAlgorithmSuites.isEmpty()) {
            data.setSamlAlgorithmSuite(translateAlgorithmSuites(samlAlgorithmSuites));
        }
    }
}
Also used : SupportingTokens(org.apache.wss4j.policy.model.SupportingTokens) AlgorithmSuite(org.apache.wss4j.common.crypto.AlgorithmSuite) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) SamlToken(org.apache.wss4j.policy.model.SamlToken) ArrayList(java.util.ArrayList) AbstractSecurityAssertion(org.apache.wss4j.policy.model.AbstractSecurityAssertion)

Example 2 with AlgorithmSuite

use of org.apache.wss4j.common.crypto.AlgorithmSuite in project cxf by apache.

the class AlgorithmSuiteTranslater method translateAlgorithmSuites.

/**
 * Translate a list of CXF AlgorithmSuite objects into a single WSS4J AlgorithmSuite object
 */
private AlgorithmSuite translateAlgorithmSuites(List<org.apache.wss4j.policy.model.AlgorithmSuite> algorithmSuites) {
    AlgorithmSuite algorithmSuite = null;
    for (org.apache.wss4j.policy.model.AlgorithmSuite cxfAlgorithmSuite : algorithmSuites) {
        if (cxfAlgorithmSuite == null) {
            continue;
        }
        // Translate into WSS4J's AlgorithmSuite class
        if (algorithmSuite == null) {
            algorithmSuite = new AlgorithmSuite();
        }
        AlgorithmSuiteType algorithmSuiteType = cxfAlgorithmSuite.getAlgorithmSuiteType();
        if (algorithmSuiteType != null) {
            // Set asymmetric key lengths
            if (algorithmSuite.getMaximumAsymmetricKeyLength() < algorithmSuiteType.getMaximumAsymmetricKeyLength()) {
                algorithmSuite.setMaximumAsymmetricKeyLength(algorithmSuiteType.getMaximumAsymmetricKeyLength());
            }
            if (algorithmSuite.getMinimumAsymmetricKeyLength() > algorithmSuiteType.getMinimumAsymmetricKeyLength()) {
                algorithmSuite.setMinimumAsymmetricKeyLength(algorithmSuiteType.getMinimumAsymmetricKeyLength());
            }
            // Set symmetric key lengths
            if (algorithmSuite.getMaximumSymmetricKeyLength() < algorithmSuiteType.getMaximumSymmetricKeyLength()) {
                algorithmSuite.setMaximumSymmetricKeyLength(algorithmSuiteType.getMaximumSymmetricKeyLength());
            }
            if (algorithmSuite.getMinimumSymmetricKeyLength() > algorithmSuiteType.getMinimumSymmetricKeyLength()) {
                algorithmSuite.setMinimumSymmetricKeyLength(algorithmSuiteType.getMinimumSymmetricKeyLength());
            }
            algorithmSuite.addEncryptionMethod(algorithmSuiteType.getEncryption());
            algorithmSuite.addKeyWrapAlgorithm(algorithmSuiteType.getSymmetricKeyWrap());
            algorithmSuite.addKeyWrapAlgorithm(algorithmSuiteType.getAsymmetricKeyWrap());
            algorithmSuite.addDigestAlgorithm(algorithmSuiteType.getDigest());
        }
        algorithmSuite.addSignatureMethod(cxfAlgorithmSuite.getAsymmetricSignature());
        algorithmSuite.addSignatureMethod(cxfAlgorithmSuite.getSymmetricSignature());
        algorithmSuite.addC14nAlgorithm(cxfAlgorithmSuite.getC14n().getValue());
        algorithmSuite.addTransformAlgorithm(cxfAlgorithmSuite.getC14n().getValue());
        algorithmSuite.addTransformAlgorithm(SPConstants.STRT10);
        algorithmSuite.addTransformAlgorithm(WSS4JConstants.C14N_EXCL_OMIT_COMMENTS);
        algorithmSuite.addTransformAlgorithm(WSS4JConstants.NS_XMLDSIG_ENVELOPED_SIGNATURE);
        algorithmSuite.addTransformAlgorithm(WSS4JConstants.SWA_ATTACHMENT_CONTENT_SIG_TRANS);
        algorithmSuite.addTransformAlgorithm(WSS4JConstants.SWA_ATTACHMENT_COMPLETE_SIG_TRANS);
        algorithmSuite.addDerivedKeyAlgorithm(SPConstants.P_SHA1);
        algorithmSuite.addDerivedKeyAlgorithm(SPConstants.P_SHA1_L128);
    }
    return algorithmSuite;
}
Also used : AlgorithmSuite(org.apache.wss4j.common.crypto.AlgorithmSuite) AlgorithmSuiteType(org.apache.wss4j.policy.model.AlgorithmSuite.AlgorithmSuiteType)

Aggregations

AlgorithmSuite (org.apache.wss4j.common.crypto.AlgorithmSuite)2 ArrayList (java.util.ArrayList)1 AssertionInfo (org.apache.cxf.ws.policy.AssertionInfo)1 AbstractSecurityAssertion (org.apache.wss4j.policy.model.AbstractSecurityAssertion)1 AlgorithmSuiteType (org.apache.wss4j.policy.model.AlgorithmSuite.AlgorithmSuiteType)1 SamlToken (org.apache.wss4j.policy.model.SamlToken)1 SupportingTokens (org.apache.wss4j.policy.model.SupportingTokens)1