Search in sources :

Example 96 with AssertionInfo

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

the class SCTTokenValidator method validate.

public Credential validate(Credential credential, RequestData data) throws WSSecurityException {
    // Sleep to make sure token gets replicated
    try {
        Thread.sleep(2 * 1000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Credential validatedCredential = super.validate(credential, data);
    // Hack to verify the IssuedToken assertion, as this is not done by default in CXF for a
    // SecurityContextToken
    SoapMessage soapMessage = (SoapMessage) data.getMsgContext();
    AssertionInfoMap aim = soapMessage.get(AssertionInfoMap.class);
    Collection<AssertionInfo> ais = aim.get(SP12Constants.ISSUED_TOKEN);
    for (AssertionInfo ai : ais) {
        ai.setAsserted(true);
    }
    return validatedCredential;
}
Also used : Credential(org.apache.wss4j.dom.validate.Credential) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 97 with AssertionInfo

use of org.apache.cxf.ws.policy.AssertionInfo in project tesb-rt-se by Talend.

the class SchemaValidationPolicyAbstractInterceptor method handleMessageWithAssertionInfo.

protected void handleMessageWithAssertionInfo(Message message) throws Fault {
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    if (null == aim) {
        return;
    }
    Collection<AssertionInfo> ais = aim.get(SchemaValidationPolicyBuilder.SCHEMA_VALIDATION);
    if (null == ais) {
        return;
    }
    for (AssertionInfo ai : ais) {
        if (ai.getAssertion() instanceof SchemaValidationPolicy) {
            SchemaValidationPolicy vPolicy = (SchemaValidationPolicy) ai.getAssertion();
            ValidationType vldType = vPolicy.getValidationType();
            AppliesToType appliesToType = vPolicy.getApplyToType();
            MessageType msgType = vPolicy.getMessageType();
            String customSchemaPath = vPolicy.getCustomSchemaPath();
            if (vldType != ValidationType.WSDLSchema) {
                ai.setAsserted(true);
            }
            if (shouldSchemaValidate(message, msgType, appliesToType)) {
                if (vldType == ValidationType.CustomSchema) {
                    // load custom schema from external source
                    try {
                        loadCustomSchema(message, customSchemaPath, this.getClass());
                    } catch (IOException ex) {
                        throw new RuntimeException("Can not load custom schema", ex);
                    }
                }
                // do schema validation by setting value to
                // "schema-validation-enabled" property
                validateBySettingProperty(message);
            }
            ai.setAsserted(true);
        }
        ai.setAsserted(true);
    }
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) SchemaValidationPolicy(org.talend.esb.policy.schemavalidate.SchemaValidationPolicy) AppliesToType(org.talend.esb.policy.schemavalidate.SchemaValidationPolicy.AppliesToType) ValidationType(org.talend.esb.policy.schemavalidate.SchemaValidationPolicy.ValidationType) IOException(java.io.IOException) MessageType(org.talend.esb.policy.schemavalidate.SchemaValidationPolicy.MessageType) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 98 with AssertionInfo

use of org.apache.cxf.ws.policy.AssertionInfo in project tesb-rt-se by Talend.

the class SamEnablingInterceptorProvider method process.

static void process(Message message) {
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    if (aim != null) {
        Collection<AssertionInfo> ais = aim.get(SamEnablingPolicyBuilder.SAM_ENABLE);
        if (ais != null) {
            for (AssertionInfo ai : ais) {
                if (ai.getAssertion() instanceof SamEnablingPolicy) {
                    SamEnablingPolicy vPolicy = (SamEnablingPolicy) ai.getAssertion();
                    AppliesToType appliesToType = vPolicy.getAppliesToType();
                    // Service service = ServiceModelUtil.getService(message
                    // .getExchange());
                    Exchange ex = message.getExchange();
                    Bus b = ex.getBus();
                    if (b.getFeatures().contains(EventFeature.class)) {
                        ai.setAsserted(true);
                        return;
                    }
                    Endpoint ep = ex.getEndpoint();
                    Bundle bundle = FrameworkUtil.getBundle(SamEnablingInterceptorProvider.class);
                    EventFeature eventFeature = null;
                    if (bundle != null) {
                        // OSGi
                        BundleContext context = FrameworkUtil.getBundle(SamEnablingInterceptorProvider.class).getBundleContext();
                        ServiceReference sref = context.getServiceReference(EventFeature.class.getName());
                        eventFeature = (EventFeature) context.getService(sref);
                    } else {
                        // non-OSGi
                        if (springContext == null) {
                            throw springContextException;
                        }
                        eventFeature = (EventFeature) springContext.getBean("eventFeature");
                    }
                    if (MessageUtils.isRequestor(message)) {
                        if (MessageUtils.isOutbound(message)) {
                            // REQ_OUT
                            if ((appliesToType == AppliesToType.consumer || appliesToType == AppliesToType.always)) {
                                Client cli = ex.get(Client.class);
                                if (!cli.getOutInterceptors().contains(WireTapOut.class)) {
                                    eventFeature.initialize(cli, b);
                                    List<Interceptor<? extends Message>> outInterceptors = cli.getOutInterceptors();
                                    message.getInterceptorChain().add(outInterceptors);
                                    outInterceptors.getClass();
                                }
                            }
                        } else {
                            // RESP_IN
                            if ((appliesToType == AppliesToType.consumer || appliesToType == AppliesToType.always)) {
                                Client cli = ex.get(Client.class);
                                eventFeature.initialize(cli, b);
                            }
                        }
                    } else {
                        ServerRegistry registry = b.getExtension(ServerRegistry.class);
                        List<Server> servers = registry.getServers();
                        if (MessageUtils.isOutbound(message)) {
                            // RESP_OUT
                            if ((appliesToType == AppliesToType.provider || appliesToType == AppliesToType.always)) {
                                for (Server sr : servers) {
                                    EndpointInfo ei = sr.getEndpoint().getEndpointInfo();
                                    if (null != ei && ei.getAddress().equals(ep.getEndpointInfo().getAddress())) {
                                        eventFeature.initialize(sr, b);
                                    }
                                }
                            }
                        } else {
                            // REQ_IN
                            if ((appliesToType == AppliesToType.provider || appliesToType == AppliesToType.always)) {
                                for (Server sr : servers) {
                                    EndpointInfo ei = sr.getEndpoint().getEndpointInfo();
                                    if (null != ei && ei.getAddress().equals(ep.getEndpointInfo().getAddress()) && (!sr.getEndpoint().getInInterceptors().contains(WireTapIn.class))) {
                                        eventFeature.initialize(sr, b);
                                        List<Interceptor<? extends Message>> inInterceptors = sr.getEndpoint().getInInterceptors();
                                        message.getInterceptorChain().add(inInterceptors);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        for (AssertionInfo ai : ais) {
            ai.setAsserted(true);
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) Message(org.apache.cxf.message.Message) Server(org.apache.cxf.endpoint.Server) Bundle(org.osgi.framework.Bundle) ServerRegistry(org.apache.cxf.endpoint.ServerRegistry) WireTapIn(org.talend.esb.sam.agent.wiretap.WireTapIn) EventFeature(org.talend.esb.sam.agent.feature.EventFeature) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap) ServiceReference(org.osgi.framework.ServiceReference) Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) WireTapOut(org.talend.esb.sam.agent.wiretap.WireTapOut) AppliesToType(org.talend.esb.policy.samenabling.SamEnablingPolicy.AppliesToType) Client(org.apache.cxf.endpoint.Client) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) BundleContext(org.osgi.framework.BundleContext)

Example 99 with AssertionInfo

use of org.apache.cxf.ws.policy.AssertionInfo in project tesb-rt-se by Talend.

the class CorrelationIDInterceptorProvider method process.

static void process(Message message) throws SAXException, IOException, ParserConfigurationException {
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    if (aim != null) {
        Collection<AssertionInfo> ais = aim.get(CorrelationIDPolicyBuilder.CORRELATION_ID);
        if (ais == null) {
            return;
        }
        for (AssertionInfo ai : ais) {
            if (ai.getAssertion() instanceof CorrelationIDAssertion) {
                CorrelationIDAssertion cAssertion = (CorrelationIDAssertion) ai.getAssertion();
                MethodType mType = cAssertion.getMethodType();
                // String value = cAssetrion.getValue();
                String correlationId = null;
                // get ID from Http header
                correlationId = CorrelationIdProtocolHeaderCodec.readCorrelationId(message);
                // get ID from SOAP header
                if (null == correlationId) {
                    correlationId = CorrelationIdSoapCodec.readCorrelationId(message);
                }
                // get from message
                if (null == correlationId) {
                    // Get ID from Message
                    correlationId = (String) message.get(CorrelationIDFeature.MESSAGE_CORRELATION_ID);
                }
                if ((message.getContent(javax.xml.stream.XMLStreamWriter.class) != null) && (message.getContent(javax.xml.stream.XMLStreamWriter.class) instanceof SAAJStreamWriter)) {
                    NodeList nodeList = ((SAAJStreamWriter) message.getContent(javax.xml.stream.XMLStreamWriter.class)).getDocument().getElementsByTagNameNS("http://www.talend.com/esb/sam/correlationId/v1", "correlationId");
                    if (nodeList.getLength() > 0) {
                        correlationId = nodeList.item(0).getTextContent();
                    }
                }
                // get from message exchange
                if (null == correlationId) {
                    // Get ID from Message exchange
                    Exchange ex = message.getExchange();
                    if (null != ex) {
                        Message reqMsg = null;
                        if (MessageUtils.isOutbound(message)) {
                            reqMsg = ex.getInMessage();
                        } else {
                            reqMsg = ex.getOutMessage();
                        }
                        if (null != reqMsg) {
                            correlationId = (String) reqMsg.get(CorrelationIDFeature.MESSAGE_CORRELATION_ID);
                        }
                    }
                }
                // If correlationId is null we should add it to headers
                if (null == correlationId) {
                    if (MethodType.XPATH.equals(mType)) {
                        XPathProcessor proc = new XPathProcessor(cAssertion, message);
                        correlationId = proc.getCorrelationID();
                    } else if (MethodType.CALLBACK.equals(mType)) {
                        CorrelationIDCallbackHandler handler = (CorrelationIDCallbackHandler) message.get(CorrelationIDFeature.CORRELATION_ID_CALLBACK_HANDLER);
                        if (null == handler) {
                            handler = (CorrelationIDCallbackHandler) message.getContextualProperty(CorrelationIDFeature.CORRELATION_ID_CALLBACK_HANDLER);
                        }
                        if (handler != null)
                            correlationId = handler.getCorrelationId();
                    }
                    // request
                    if (null == correlationId) {
                        correlationId = ContextUtils.generateUUID();
                    }
                }
                message.put(CorrelationIDFeature.MESSAGE_CORRELATION_ID, correlationId);
                // MessageUtils.isOutbound(message)) {// RESP_OUT
                if (isRestMessage(message)) {
                    // Add correlationId to http header
                    if (null == CorrelationIdProtocolHeaderCodec.readCorrelationId(message)) {
                        CorrelationIdProtocolHeaderCodec.writeCorrelationId(message, correlationId);
                    }
                } else {
                    // Add correlationId to soap header
                    if (null == CorrelationIdSoapCodec.readCorrelationId(message)) {
                        CorrelationIdSoapCodec.writeCorrelationId(message, correlationId);
                    }
                }
                // }
                ai.setAsserted(true);
            }
        }
    }
}
Also used : MethodType(org.talend.esb.policy.correlation.impl.CorrelationIDAssertion.MethodType) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) Message(org.apache.cxf.message.Message) NodeList(org.w3c.dom.NodeList) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap) SAAJStreamWriter(org.apache.cxf.binding.soap.saaj.SAAJStreamWriter) Exchange(org.apache.cxf.message.Exchange) CorrelationIDCallbackHandler(org.talend.esb.policy.correlation.CorrelationIDCallbackHandler)

Aggregations

AssertionInfo (org.apache.cxf.ws.policy.AssertionInfo)99 AssertionInfoMap (org.apache.cxf.ws.policy.AssertionInfoMap)45 QName (javax.xml.namespace.QName)21 SupportingTokens (org.apache.wss4j.policy.model.SupportingTokens)14 ArrayList (java.util.ArrayList)12 AbstractToken (org.apache.wss4j.policy.model.AbstractToken)12 SamlToken (org.apache.wss4j.policy.model.SamlToken)12 IssuedToken (org.apache.wss4j.policy.model.IssuedToken)10 UsernameToken (org.apache.wss4j.policy.model.UsernameToken)10 KerberosToken (org.apache.wss4j.policy.model.KerberosToken)9 SecurityContextToken (org.apache.wss4j.policy.model.SecurityContextToken)9 X509Token (org.apache.wss4j.policy.model.X509Token)9 Element (org.w3c.dom.Element)9 PolicyException (org.apache.cxf.ws.policy.PolicyException)8 KeyValueToken (org.apache.wss4j.policy.model.KeyValueToken)8 Header (org.apache.wss4j.policy.model.Header)7 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)6 Message (org.apache.cxf.message.Message)6 WSSecurityEngineResult (org.apache.wss4j.dom.engine.WSSecurityEngineResult)6 TLSSessionInfo (org.apache.cxf.security.transport.TLSSessionInfo)5