Search in sources :

Example 1 with SamlCallbackHandler

use of org.apache.cxf.sts.token.provider.SamlCallbackHandler in project cxf by apache.

the class SCTSAMLTokenProvider method createCallbackHandler.

public SamlCallbackHandler createCallbackHandler(TokenProviderParameters tokenParameters, byte[] secret, Document doc) throws Exception {
    // Parse the AttributeStatements
    List<AttributeStatementBean> attrBeanList = null;
    if (attributeStatementProviders != null && !attributeStatementProviders.isEmpty()) {
        attrBeanList = new ArrayList<>();
        for (AttributeStatementProvider statementProvider : attributeStatementProviders) {
            AttributeStatementBean statementBean = statementProvider.getStatement(tokenParameters);
            if (statementBean != null) {
                LOG.fine("AttributeStatements" + statementBean.toString() + "returned by AttributeStatementProvider " + statementProvider.getClass().getName());
                attrBeanList.add(statementBean);
            }
        }
    }
    // If no statements, then default to the DefaultAttributeStatementProvider
    if (attrBeanList == null || attrBeanList.isEmpty()) {
        attrBeanList = new ArrayList<>();
        AttributeStatementProvider attributeProvider = new DefaultAttributeStatementProvider();
        AttributeStatementBean attributeBean = attributeProvider.getStatement(tokenParameters);
        attrBeanList.add(attributeBean);
    }
    // Get the Subject and Conditions
    SubjectProviderParameters subjectProviderParameters = new SubjectProviderParameters();
    subjectProviderParameters.setProviderParameters(tokenParameters);
    subjectProviderParameters.setDoc(doc);
    subjectProviderParameters.setSecret(secret);
    subjectProviderParameters.setAttrBeanList(attrBeanList);
    SubjectBean subjectBean = subjectProvider.getSubject(subjectProviderParameters);
    ConditionsBean conditionsBean = conditionsProvider.getConditions(tokenParameters);
    // Set all of the beans on the SamlCallbackHandler
    SamlCallbackHandler handler = new SamlCallbackHandler();
    handler.setTokenProviderParameters(tokenParameters);
    handler.setSubjectBean(subjectBean);
    handler.setConditionsBean(conditionsBean);
    handler.setAttributeBeans(attrBeanList);
    return handler;
}
Also used : SubjectBean(org.apache.wss4j.common.saml.bean.SubjectBean) SamlCallbackHandler(org.apache.cxf.sts.token.provider.SamlCallbackHandler) AttributeStatementBean(org.apache.wss4j.common.saml.bean.AttributeStatementBean) ConditionsBean(org.apache.wss4j.common.saml.bean.ConditionsBean) DefaultAttributeStatementProvider(org.apache.cxf.sts.token.provider.DefaultAttributeStatementProvider) AttributeStatementProvider(org.apache.cxf.sts.token.provider.AttributeStatementProvider) DefaultAttributeStatementProvider(org.apache.cxf.sts.token.provider.DefaultAttributeStatementProvider) SubjectProviderParameters(org.apache.cxf.sts.token.provider.SubjectProviderParameters)

Example 2 with SamlCallbackHandler

use of org.apache.cxf.sts.token.provider.SamlCallbackHandler in project cxf by apache.

the class SCTSAMLTokenProvider method createSamlToken.

private SamlAssertionWrapper createSamlToken(TokenProviderParameters tokenParameters, byte[] secret, Document doc) throws Exception {
    SamlCallbackHandler handler = createCallbackHandler(tokenParameters, secret, doc);
    SAMLCallback samlCallback = new SAMLCallback();
    SAMLUtil.doSAMLCallback(handler, samlCallback);
    SamlAssertionWrapper assertion = new SamlAssertionWrapper(samlCallback);
    if (signToken) {
        STSPropertiesMBean stsProperties = tokenParameters.getStsProperties();
        // Get the password
        String alias = stsProperties.getSignatureUsername();
        WSPasswordCallback[] cb = { new WSPasswordCallback(alias, WSPasswordCallback.SIGNATURE) };
        LOG.fine("Creating SAML Token");
        stsProperties.getCallbackHandler().handle(cb);
        String password = cb[0].getPassword();
        LOG.fine("Signing SAML Token");
        boolean useKeyValue = stsProperties.getSignatureProperties().isUseKeyValue();
        assertion.signAssertion(alias, password, stsProperties.getSignatureCrypto(), useKeyValue);
    }
    return assertion;
}
Also used : SamlCallbackHandler(org.apache.cxf.sts.token.provider.SamlCallbackHandler) STSPropertiesMBean(org.apache.cxf.sts.STSPropertiesMBean) SamlAssertionWrapper(org.apache.wss4j.common.saml.SamlAssertionWrapper) SAMLCallback(org.apache.wss4j.common.saml.SAMLCallback) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback)

Aggregations

SamlCallbackHandler (org.apache.cxf.sts.token.provider.SamlCallbackHandler)2 STSPropertiesMBean (org.apache.cxf.sts.STSPropertiesMBean)1 AttributeStatementProvider (org.apache.cxf.sts.token.provider.AttributeStatementProvider)1 DefaultAttributeStatementProvider (org.apache.cxf.sts.token.provider.DefaultAttributeStatementProvider)1 SubjectProviderParameters (org.apache.cxf.sts.token.provider.SubjectProviderParameters)1 WSPasswordCallback (org.apache.wss4j.common.ext.WSPasswordCallback)1 SAMLCallback (org.apache.wss4j.common.saml.SAMLCallback)1 SamlAssertionWrapper (org.apache.wss4j.common.saml.SamlAssertionWrapper)1 AttributeStatementBean (org.apache.wss4j.common.saml.bean.AttributeStatementBean)1 ConditionsBean (org.apache.wss4j.common.saml.bean.ConditionsBean)1 SubjectBean (org.apache.wss4j.common.saml.bean.SubjectBean)1