Search in sources :

Example 1 with EffectivePolicy

use of org.apache.cxf.ws.policy.EffectivePolicy in project cxf by apache.

the class AbstractSTSClient method findOperation.

protected BindingOperationInfo findOperation(String suffix) {
    BindingInfo bi = client.getEndpoint().getBinding().getBindingInfo();
    for (BindingOperationInfo boi : bi.getOperations()) {
        SoapOperationInfo soi = boi.getExtensor(SoapOperationInfo.class);
        String soapAction = soi != null ? soi.getAction() : null;
        Object o = boi.getOperationInfo().getInput().getExtensionAttribute(new QName("http://www.w3.org/2007/05/addressing/metadata", "Action"));
        if (o instanceof QName) {
            o = ((QName) o).getLocalPart();
        }
        String wsamAction = o == null ? null : o.toString();
        if ((soapAction != null && soapAction.endsWith(suffix)) || (wsamAction != null && wsamAction.endsWith(suffix))) {
            PolicyEngine pe = bus.getExtension(PolicyEngine.class);
            Conduit conduit = client.getConduit();
            EffectivePolicy effectivePolicy = pe.getEffectiveClientRequestPolicy(client.getEndpoint().getEndpointInfo(), boi, conduit, PhaseInterceptorChain.getCurrentMessage());
            setPolicyInternal(effectivePolicy.getPolicy());
            return boi;
        }
    }
    // we can at least find it by name and then set the action and such manually later.
    for (BindingOperationInfo boi : bi.getOperations()) {
        if (suffix.endsWith(boi.getName().getLocalPart())) {
            return boi;
        }
    }
    // Still didn't find anything useful
    for (BindingOperationInfo boi : bi.getOperations()) {
        if (boi.getInput().getMessageInfo().getMessagePartsNumber() > 0) {
            MessagePartInfo mpi = boi.getInput().getMessageInfo().getFirstMessagePart();
            if ("RequestSecurityToken".equals(mpi.getConcreteName().getLocalPart())) {
                return boi;
            }
        }
    }
    return null;
}
Also used : EffectivePolicy(org.apache.cxf.ws.policy.EffectivePolicy) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) QName(javax.xml.namespace.QName) Conduit(org.apache.cxf.transport.Conduit) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 2 with EffectivePolicy

use of org.apache.cxf.ws.policy.EffectivePolicy in project cxf by apache.

the class PolicyBasedWSS4JStaxInInterceptor method createPolicyEnforcer.

private PolicyEnforcer createPolicyEnforcer(EndpointInfo endpointInfo, SoapMessage msg) throws WSSPolicyException {
    EffectivePolicy dispatchPolicy = null;
    List<OperationPolicy> operationPolicies = new ArrayList<>();
    Collection<BindingOperationInfo> bindingOperationInfos = endpointInfo.getBinding().getOperations();
    for (Iterator<BindingOperationInfo> bindingOperationInfoIterator = bindingOperationInfos.iterator(); bindingOperationInfoIterator.hasNext(); ) {
        BindingOperationInfo bindingOperationInfo = bindingOperationInfoIterator.next();
        QName operationName = bindingOperationInfo.getName();
        // todo: I'm not sure what the effectivePolicy exactly contains,
        // a) only the operation policy,
        // or b) all policies for the service,
        // or c) all policies which applies for the current operation.
        // c) is that what we need for stax.
        EffectivePolicy policy = (EffectivePolicy) bindingOperationInfo.getProperty("policy-engine-info-serve-request");
        // PolicyEngineImpl.POLICY_INFO_REQUEST_SERVER);
        if (MessageUtils.isRequestor(msg)) {
            policy = (EffectivePolicy) bindingOperationInfo.getProperty("policy-engine-info-client-response");
            // Save the Dispatch Policy as it may be used on another BindingOperationInfo
            if (policy != null && "http://cxf.apache.org/jaxws/dispatch".equals(operationName.getNamespaceURI())) {
                dispatchPolicy = policy;
            }
            if (bindingOperationInfo.getOutput() != null) {
                MessageInfo messageInfo = bindingOperationInfo.getOutput().getMessageInfo();
                operationName = messageInfo.getName();
                if (messageInfo.getMessagePartsNumber() > 0) {
                    QName cn = messageInfo.getFirstMessagePart().getConcreteName();
                    if (cn != null) {
                        operationName = cn;
                    }
                }
            }
        } else {
            if (bindingOperationInfo.getInput() != null) {
                MessageInfo messageInfo = bindingOperationInfo.getInput().getMessageInfo();
                operationName = messageInfo.getName();
                if (messageInfo.getMessagePartsNumber() > 0) {
                    QName cn = messageInfo.getFirstMessagePart().getConcreteName();
                    if (cn != null) {
                        operationName = cn;
                    }
                }
            }
        }
        SoapOperationInfo soapOperationInfo = bindingOperationInfo.getExtensor(SoapOperationInfo.class);
        if (soapOperationInfo != null && policy == null && dispatchPolicy != null) {
            policy = dispatchPolicy;
        }
        if (policy != null && soapOperationInfo != null) {
            String soapNS;
            BindingInfo bindingInfo = bindingOperationInfo.getBinding();
            if (bindingInfo instanceof SoapBindingInfo) {
                soapNS = ((SoapBindingInfo) bindingInfo).getSoapVersion().getNamespace();
            } else {
                // most probably throw an exception:
                throw new IllegalArgumentException("BindingInfo is not an instance of SoapBindingInfo");
            }
            OperationPolicy operationPolicy = new OperationPolicy(operationName);
            operationPolicy.setPolicy(policy.getPolicy());
            operationPolicy.setOperationAction(soapOperationInfo.getAction());
            operationPolicy.setSoapMessageVersionNamespace(soapNS);
            operationPolicies.add(operationPolicy);
        }
    }
    String soapAction = SoapActionInInterceptor.getSoapAction(msg);
    if (soapAction == null) {
        soapAction = "";
    }
    String actor = (String) msg.getContextualProperty(SecurityConstants.ACTOR);
    final Collection<org.apache.cxf.message.Attachment> attachments = msg.getAttachments();
    int attachmentCount = 0;
    if (attachments != null && !attachments.isEmpty()) {
        attachmentCount = attachments.size();
    }
    return new PolicyEnforcer(operationPolicies, soapAction, isRequestor(msg), actor, attachmentCount, new WSS4JPolicyAsserter(msg.get(AssertionInfoMap.class)));
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Endpoint(org.apache.cxf.endpoint.Endpoint) MessageInfo(org.apache.cxf.service.model.MessageInfo) EffectivePolicy(org.apache.cxf.ws.policy.EffectivePolicy) OperationPolicy(org.apache.wss4j.policy.stax.OperationPolicy) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) PolicyEnforcer(org.apache.wss4j.policy.stax.enforcer.PolicyEnforcer)

Example 3 with EffectivePolicy

use of org.apache.cxf.ws.policy.EffectivePolicy in project cxf by apache.

the class PolicyLoggingInterceptor method handleMessage.

public void handleMessage(Message message) throws Fault {
    EndpointInfo ei = message.getExchange().getEndpoint().getEndpointInfo();
    BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();
    LOG.fine("Getting effective server request policy for endpoint " + ei + " and binding operation " + boi);
    EffectivePolicy ep = bus.getExtension(PolicyEngine.class).getEffectiveServerRequestPolicy(ei, boi, message);
    for (Iterator<List<Assertion>> it = ep.getPolicy().getAlternatives(); it.hasNext(); ) {
        Collection<Assertion> as = it.next();
        LOG.fine("Checking alternative with " + as.size() + " assertions.");
        for (Assertion a : as) {
            LOG.fine("Assertion: " + a.getClass().getName());
            HTTPServerPolicy p = (JaxbAssertion.cast(a, HTTPServerPolicy.class)).getData();
            LOG.fine("server policy: " + ServerPolicyCalculator.toString(p));
        }
    }
}
Also used : EffectivePolicy(org.apache.cxf.ws.policy.EffectivePolicy) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) JaxbAssertion(org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion) Assertion(org.apache.neethi.Assertion) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) List(java.util.List)

Example 4 with EffectivePolicy

use of org.apache.cxf.ws.policy.EffectivePolicy in project cxf by apache.

the class SimpleBatchSTSClient method findOperation.

protected BindingOperationInfo findOperation(String suffix) {
    BindingInfo bi = client.getEndpoint().getBinding().getBindingInfo();
    for (BindingOperationInfo boi : bi.getOperations()) {
        SoapOperationInfo soi = boi.getExtensor(SoapOperationInfo.class);
        if (soi != null && soi.getAction() != null && soi.getAction().endsWith(suffix)) {
            PolicyEngine pe = bus.getExtension(PolicyEngine.class);
            Conduit conduit = client.getConduit();
            EffectivePolicy effectivePolicy = pe.getEffectiveClientRequestPolicy(client.getEndpoint().getEndpointInfo(), boi, conduit, PhaseInterceptorChain.getCurrentMessage());
            setPolicyInternal(effectivePolicy.getPolicy());
            return boi;
        }
    }
    // we can at least find it by name and then set the action and such manually later.
    for (BindingOperationInfo boi : bi.getOperations()) {
        if (boi.getInput().getMessageInfo().getMessageParts().size() > 0) {
            MessagePartInfo mpi = boi.getInput().getMessageInfo().getMessagePart(0);
            if ("RequestSecurityToken".equals(mpi.getConcreteName().getLocalPart())) {
                return boi;
            }
        }
    }
    return null;
}
Also used : EffectivePolicy(org.apache.cxf.ws.policy.EffectivePolicy) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Conduit(org.apache.cxf.transport.Conduit) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Aggregations

BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)4 EffectivePolicy (org.apache.cxf.ws.policy.EffectivePolicy)4 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)3 BindingInfo (org.apache.cxf.service.model.BindingInfo)3 PolicyEngine (org.apache.cxf.ws.policy.PolicyEngine)3 QName (javax.xml.namespace.QName)2 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)2 Conduit (org.apache.cxf.transport.Conduit)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SoapBindingInfo (org.apache.cxf.binding.soap.model.SoapBindingInfo)1 Endpoint (org.apache.cxf.endpoint.Endpoint)1 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)1 MessageInfo (org.apache.cxf.service.model.MessageInfo)1 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)1 HTTPServerPolicy (org.apache.cxf.transports.http.configuration.HTTPServerPolicy)1 JaxbAssertion (org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion)1 Assertion (org.apache.neethi.Assertion)1 OperationPolicy (org.apache.wss4j.policy.stax.OperationPolicy)1 PolicyEnforcer (org.apache.wss4j.policy.stax.enforcer.PolicyEnforcer)1