Search in sources :

Example 1 with CoverageType

use of org.apache.cxf.ws.security.wss4j.CryptoCoverageUtil.CoverageType in project cxf by apache.

the class AbstractPolicySecurityTest method runInInterceptorAndValidateWss.

protected void runInInterceptorAndValidateWss(Document document, AssertionInfoMap aim, List<CoverageType> types) throws Exception {
    PolicyBasedWSS4JInInterceptor inHandler = this.getInInterceptor(types);
    SoapMessage inmsg = this.getSoapMessageForDom(document, aim);
    Element securityHeaderElem = WSSecurityUtil.getSecurityHeader(document, "");
    if (securityHeaderElem != null) {
        SoapHeader securityHeader = new SoapHeader(new QName(securityHeaderElem.getNamespaceURI(), securityHeaderElem.getLocalName()), securityHeaderElem);
        inmsg.getHeaders().add(securityHeader);
    }
    final Endpoint endpoint = inmsg.getExchange().getEndpoint();
    if (endpoint != null && endpoint.getEndpointInfo().getProperty(TokenStore.class.getName()) == null) {
        inmsg.put(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE, new MemoryTokenStore());
    }
    inHandler.handleMessage(inmsg);
    for (CoverageType type : types) {
        switch(type) {
            case SIGNED:
                this.verifyWss4jSigResults(inmsg);
                break;
            case ENCRYPTED:
                this.verifyWss4jEncResults(inmsg);
                break;
            default:
                fail("Unsupported coverage type.");
        }
    }
}
Also used : MemoryTokenStore(org.apache.cxf.ws.security.tokenstore.MemoryTokenStore) Endpoint(org.apache.cxf.endpoint.Endpoint) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) CoverageType(org.apache.cxf.ws.security.wss4j.CryptoCoverageUtil.CoverageType) TokenStore(org.apache.cxf.ws.security.tokenstore.TokenStore) MemoryTokenStore(org.apache.cxf.ws.security.tokenstore.MemoryTokenStore) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Example 2 with CoverageType

use of org.apache.cxf.ws.security.wss4j.CryptoCoverageUtil.CoverageType in project cxf by apache.

the class PolicyBasedSamlTest method runInInterceptorAndValidateWss.

@Override
protected void runInInterceptorAndValidateWss(Document document, AssertionInfoMap aim, List<CoverageType> types) throws Exception {
    PolicyBasedWSS4JInInterceptor inHandler = this.getInInterceptor(types);
    SoapMessage inmsg = this.getSoapMessageForDom(document, aim);
    Element securityHeaderElem = WSSecurityUtil.getSecurityHeader(document, "");
    if (securityHeaderElem != null) {
        SoapHeader securityHeader = new SoapHeader(new QName(securityHeaderElem.getNamespaceURI(), securityHeaderElem.getLocalName()), securityHeaderElem);
        inmsg.getHeaders().add(securityHeader);
    }
    // Necessary because the Bearer Assertion does not have an internal signature
    SamlAssertionValidator assertionValidator = new SamlAssertionValidator();
    assertionValidator.setRequireBearerSignature(false);
    inmsg.put(SecurityConstants.SAML2_TOKEN_VALIDATOR, assertionValidator);
    inmsg.put(SecurityConstants.SAML1_TOKEN_VALIDATOR, assertionValidator);
    inHandler.handleMessage(inmsg);
    for (CoverageType type : types) {
        switch(type) {
            case SIGNED:
                this.verifyWss4jSigResults(inmsg);
                break;
            case ENCRYPTED:
                this.verifyWss4jEncResults(inmsg);
                break;
            default:
                fail("Unsupported coverage type.");
        }
    }
}
Also used : PolicyBasedWSS4JInInterceptor(org.apache.cxf.ws.security.wss4j.PolicyBasedWSS4JInInterceptor) SamlAssertionValidator(org.apache.wss4j.dom.validate.SamlAssertionValidator) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) CoverageType(org.apache.cxf.ws.security.wss4j.CryptoCoverageUtil.CoverageType) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Example 3 with CoverageType

use of org.apache.cxf.ws.security.wss4j.CryptoCoverageUtil.CoverageType in project cxf by apache.

the class PluggablePolicyValidatorTest method runInInterceptorAndValidateWss.

private void runInInterceptorAndValidateWss(Document document, AssertionInfoMap aim, List<CoverageType> types, Map<QName, SecurityPolicyValidator> validators) throws Exception {
    PolicyBasedWSS4JInInterceptor inHandler = this.getInInterceptor(types);
    SoapMessage inmsg = this.getSoapMessageForDom(document, aim);
    Element securityHeaderElem = WSSecurityUtil.getSecurityHeader(document, "");
    if (securityHeaderElem != null) {
        SoapHeader securityHeader = new SoapHeader(new QName(securityHeaderElem.getNamespaceURI(), securityHeaderElem.getLocalName()), securityHeaderElem);
        inmsg.getHeaders().add(securityHeader);
    }
    if (validators != null) {
        inmsg.put(SecurityConstants.POLICY_VALIDATOR_MAP, validators);
    }
    inHandler.handleMessage(inmsg);
    for (CoverageType type : types) {
        switch(type) {
            case SIGNED:
                this.verifyWss4jSigResults(inmsg);
                break;
            case ENCRYPTED:
                this.verifyWss4jEncResults(inmsg);
                break;
            default:
                fail("Unsupported coverage type.");
        }
    }
}
Also used : QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) CoverageType(org.apache.cxf.ws.security.wss4j.CryptoCoverageUtil.CoverageType) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Example 4 with CoverageType

use of org.apache.cxf.ws.security.wss4j.CryptoCoverageUtil.CoverageType in project cxf by apache.

the class AbstractPolicySecurityTest method getInInterceptor.

protected PolicyBasedWSS4JInInterceptor getInInterceptor(List<CoverageType> types) {
    PolicyBasedWSS4JInInterceptor inHandler = new PolicyBasedWSS4JInInterceptor();
    String action = "";
    for (CoverageType type : types) {
        switch(type) {
            case SIGNED:
                action += " " + ConfigurationConstants.SIGNATURE;
                break;
            case ENCRYPTED:
                action += " " + ConfigurationConstants.ENCRYPTION;
                break;
            default:
                fail("Unsupported coverage type.");
        }
    }
    inHandler.setProperty(ConfigurationConstants.ACTION, action);
    inHandler.setProperty(ConfigurationConstants.SIG_VER_PROP_FILE, "insecurity.properties");
    inHandler.setProperty(ConfigurationConstants.DEC_PROP_FILE, "insecurity.properties");
    inHandler.setProperty(ConfigurationConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
    inHandler.setProperty(ConfigurationConstants.IS_BSP_COMPLIANT, "false");
    return inHandler;
}
Also used : CoverageType(org.apache.cxf.ws.security.wss4j.CryptoCoverageUtil.CoverageType)

Aggregations

CoverageType (org.apache.cxf.ws.security.wss4j.CryptoCoverageUtil.CoverageType)4 QName (javax.xml.namespace.QName)3 SoapHeader (org.apache.cxf.binding.soap.SoapHeader)3 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)3 Element (org.w3c.dom.Element)3 Endpoint (org.apache.cxf.endpoint.Endpoint)1 MemoryTokenStore (org.apache.cxf.ws.security.tokenstore.MemoryTokenStore)1 TokenStore (org.apache.cxf.ws.security.tokenstore.TokenStore)1 PolicyBasedWSS4JInInterceptor (org.apache.cxf.ws.security.wss4j.PolicyBasedWSS4JInInterceptor)1 SamlAssertionValidator (org.apache.wss4j.dom.validate.SamlAssertionValidator)1