Search in sources :

Example 66 with Policy

use of org.apache.neethi.Policy in project cxf by apache.

the class AbstractSTSClient method setPolicyInternal.

protected void setPolicyInternal(String policyReference) {
    PolicyBuilder builder = bus.getExtension(PolicyBuilder.class);
    ReferenceResolver resolver = new RemoteReferenceResolver(null, builder);
    PolicyRegistry registry = bus.getExtension(PolicyEngine.class).getRegistry();
    Policy resolved = registry.lookup(policyReference);
    if (null != resolved) {
        this.setPolicyInternal(resolved);
    } else {
        this.setPolicyInternal(resolver.resolveReference(policyReference));
    }
}
Also used : Policy(org.apache.neethi.Policy) EffectivePolicy(org.apache.cxf.ws.policy.EffectivePolicy) RemoteReferenceResolver(org.apache.cxf.ws.policy.attachment.reference.RemoteReferenceResolver) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) PolicyBuilder(org.apache.cxf.ws.policy.PolicyBuilder) PolicyRegistry(org.apache.neethi.PolicyRegistry) RemoteReferenceResolver(org.apache.cxf.ws.policy.attachment.reference.RemoteReferenceResolver) ReferenceResolver(org.apache.cxf.ws.policy.attachment.reference.ReferenceResolver)

Example 67 with Policy

use of org.apache.neethi.Policy in project cxf by apache.

the class AbstractSTSClient method cancel.

/**
 * Make an "Cancel" invocation and return the response as a STSResponse Object
 */
protected STSResponse cancel(SecurityToken token) throws Exception {
    createClient();
    client.getRequestContext().clear();
    client.getRequestContext().putAll(ctx);
    client.getRequestContext().put(SecurityConstants.TOKEN, token);
    BindingOperationInfo boi = findOperation("/RST/Cancel");
    boolean attachTokenDirectly = true;
    if (boi == null) {
        attachTokenDirectly = false;
        boi = findOperation("/RST/Issue");
        Policy cancelPolicy = new Policy();
        ExactlyOne one = new ExactlyOne();
        cancelPolicy.addPolicyComponent(one);
        All all = new All();
        one.addPolicyComponent(all);
        all.addAssertion(getAddressingAssertion());
        final SecureConversationToken secureConversationToken = new SecureConversationToken(SPConstants.SPVersion.SP12, SPConstants.IncludeTokenType.INCLUDE_TOKEN_ALWAYS_TO_RECIPIENT, null, null, null, null);
        secureConversationToken.setOptional(true);
        class InternalProtectionToken extends ProtectionToken {

            InternalProtectionToken(SPVersion version, Policy nestedPolicy) {
                super(version, nestedPolicy);
                super.setToken(secureConversationToken);
            }
        }
        DefaultSymmetricBinding binding = new DefaultSymmetricBinding(SPConstants.SPVersion.SP12, new Policy());
        all.addAssertion(binding);
        all.addAssertion(getAddressingAssertion());
        binding.setProtectionToken(new InternalProtectionToken(SPConstants.SPVersion.SP12, new Policy()));
        binding.setIncludeTimestamp(true);
        binding.setOnlySignEntireHeadersAndBody(true);
        binding.setProtectTokens(false);
        String addrNamespace = addressingNamespace;
        if (addrNamespace == null) {
            addrNamespace = "http://www.w3.org/2005/08/addressing";
        }
        List<Header> headers = new ArrayList<>();
        headers.add(new Header("To", addrNamespace));
        headers.add(new Header("From", addrNamespace));
        headers.add(new Header("FaultTo", addrNamespace));
        headers.add(new Header("ReplyTo", addrNamespace));
        headers.add(new Header("Action", addrNamespace));
        headers.add(new Header("MessageID", addrNamespace));
        headers.add(new Header("RelatesTo", addrNamespace));
        SignedParts parts = new SignedParts(SPConstants.SPVersion.SP12, true, null, headers, false);
        parts.setOptional(true);
        all.addPolicyComponent(parts);
        client.getRequestContext().put(PolicyConstants.POLICY_OVERRIDE, cancelPolicy);
    }
    if (isSecureConv) {
        client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION, namespace + "/RST/SCT/Cancel");
    } else {
        client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION, namespace + "/RST/Cancel");
    }
    W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
    writer.writeStartElement("wst", "RequestSecurityToken", namespace);
    writer.writeNamespace("wst", namespace);
    writer.writeStartElement("wst", "RequestType", namespace);
    writer.writeCharacters(namespace + "/Cancel");
    writer.writeEndElement();
    writer.writeStartElement("wst", "CancelTarget", namespace);
    Element el = null;
    if (attachTokenDirectly) {
        el = token.getToken();
    } else {
        el = token.getUnattachedReference();
        if (el == null) {
            el = token.getAttachedReference();
        }
    }
    StaxUtils.copy(el, writer);
    writer.writeEndElement();
    writer.writeEndElement();
    Object[] obj = client.invoke(boi, new DOMSource(writer.getDocument().getDocumentElement()));
    return new STSResponse((DOMSource) obj[0], null);
}
Also used : Policy(org.apache.neethi.Policy) EffectivePolicy(org.apache.cxf.ws.policy.EffectivePolicy) All(org.apache.neethi.All) SPVersion(org.apache.wss4j.policy.SPConstants.SPVersion) W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) DOMSource(javax.xml.transform.dom.DOMSource) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) ModCountCopyOnWriteArrayList(org.apache.cxf.common.util.ModCountCopyOnWriteArrayList) ExactlyOne(org.apache.neethi.ExactlyOne) SecureConversationToken(org.apache.wss4j.policy.model.SecureConversationToken) Header(org.apache.wss4j.policy.model.Header) SignedParts(org.apache.wss4j.policy.model.SignedParts) ProtectionToken(org.apache.wss4j.policy.model.ProtectionToken)

Example 68 with Policy

use of org.apache.neethi.Policy in project cxf by apache.

the class AbstractPolicySecurityTest method runInInterceptorAndValidate.

protected void runInInterceptorAndValidate(String document, String policyDocument, List<QName> assertedInAssertions, List<QName> notAssertedInAssertions, List<CoverageType> types) throws Exception {
    final Policy policy = this.policyBuilder.getPolicy(this.readDocument(policyDocument).getDocumentElement());
    final Document doc = this.readDocument(document);
    this.runInInterceptorAndValidate(doc, policy, assertedInAssertions, notAssertedInAssertions, types);
}
Also used : Policy(org.apache.neethi.Policy) Document(org.w3c.dom.Document)

Example 69 with Policy

use of org.apache.neethi.Policy in project cxf by apache.

the class WSPolicyFeature method resolveExternal.

protected Policy resolveExternal(PolicyReference ref, String baseURI, Bus bus) {
    PolicyBuilder builder = bus.getExtension(PolicyBuilder.class);
    ReferenceResolver resolver = new RemoteReferenceResolver(baseURI, builder);
    PolicyRegistry registry = bus.getExtension(PolicyEngine.class).getRegistry();
    Policy resolved = registry.lookup(ref.getURI());
    if (null != resolved) {
        return resolved;
    }
    return resolver.resolveReference(ref.getURI());
}
Also used : Policy(org.apache.neethi.Policy) RemoteReferenceResolver(org.apache.cxf.ws.policy.attachment.reference.RemoteReferenceResolver) PolicyRegistry(org.apache.neethi.PolicyRegistry) ReferenceResolver(org.apache.cxf.ws.policy.attachment.reference.ReferenceResolver) RemoteReferenceResolver(org.apache.cxf.ws.policy.attachment.reference.RemoteReferenceResolver)

Example 70 with Policy

use of org.apache.neethi.Policy in project cxf by apache.

the class WSPolicyFeature method initializeEndpointPolicy.

private Policy initializeEndpointPolicy(Endpoint endpoint, Bus bus) {
    initialize(bus);
    DescriptionInfo i = endpoint.getEndpointInfo().getDescription();
    Collection<Policy> loadedPolicies = null;
    if (policyElements != null || policyReferenceElements != null) {
        loadedPolicies = new ArrayList<>();
        PolicyBuilder builder = bus.getExtension(PolicyBuilder.class);
        if (null != policyElements) {
            for (Element e : policyElements) {
                loadedPolicies.add(builder.getPolicy(e));
            }
        }
        if (null != policyReferenceElements) {
            for (Element e : policyReferenceElements) {
                PolicyReference pr = builder.getPolicyReference(e);
                Policy resolved = resolveReference(pr, builder, bus, i);
                if (null != resolved) {
                    loadedPolicies.add(resolved);
                }
            }
        }
    }
    Policy thePolicy = new Policy();
    if (policies != null) {
        for (Policy p : policies) {
            thePolicy = thePolicy.merge(p);
        }
    }
    if (loadedPolicies != null) {
        for (Policy p : loadedPolicies) {
            thePolicy = thePolicy.merge(p);
        }
    }
    return thePolicy;
}
Also used : Policy(org.apache.neethi.Policy) Element(org.w3c.dom.Element) DescriptionInfo(org.apache.cxf.service.model.DescriptionInfo) PolicyReference(org.apache.neethi.PolicyReference)

Aggregations

Policy (org.apache.neethi.Policy)122 Test (org.junit.Test)47 Assertion (org.apache.neethi.Assertion)27 QName (javax.xml.namespace.QName)23 ArrayList (java.util.ArrayList)21 All (org.apache.neethi.All)18 ExactlyOne (org.apache.neethi.ExactlyOne)18 Message (org.apache.cxf.message.Message)15 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)14 Element (org.w3c.dom.Element)13 Bus (org.apache.cxf.Bus)12 PrimitiveAssertion (org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion)12 List (java.util.List)9 Interceptor (org.apache.cxf.interceptor.Interceptor)9 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)9 HashMap (java.util.HashMap)7 OMElement (org.apache.axiom.om.OMElement)7 MessageImpl (org.apache.cxf.message.MessageImpl)7 ReferenceResolver (org.apache.cxf.ws.policy.attachment.reference.ReferenceResolver)6 InputStream (java.io.InputStream)5