Search in sources :

Example 16 with Bus

use of org.apache.cxf.Bus in project wildfly by wildfly.

the class WSTrustTestCase method testUsingEPR.

/**
     * WS-Trust test with the STS information coming from EPR specified in service endpoint contract policy
     *
     * @throws Exception
     */
@Test
@RunAsClient
@OperateOnDeployment(SERVER_DEP)
@WrapThreadContextClassLoader
public void testUsingEPR() throws Exception {
    Bus bus = BusFactory.newInstance().createBus();
    try {
        BusFactory.setThreadDefaultBus(bus);
        final QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wssecuritypolicy", "SecurityService");
        final URL wsdlURL = new URL(serviceURL + "SecurityService?wsdl");
        Service service = Service.create(wsdlURL, serviceName);
        ServiceIface proxy = (ServiceIface) service.getPort(ServiceIface.class);
        WSTrustTestUtils.setupWsse(proxy, bus);
        try {
            assertEquals("WS-Trust Hello World!", proxy.sayHello());
        } catch (Exception e) {
            throw e;
        }
    } finally {
        bus.shutdown(true);
    }
}
Also used : Bus(org.apache.cxf.Bus) ActAsServiceIface(org.jboss.as.test.integration.ws.wsse.trust.actas.ActAsServiceIface) ServiceIface(org.jboss.as.test.integration.ws.wsse.trust.service.ServiceIface) OnBehalfOfServiceIface(org.jboss.as.test.integration.ws.wsse.trust.onbehalfof.OnBehalfOfServiceIface) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) IOException(java.io.IOException) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) WrapThreadContextClassLoader(org.jboss.as.test.integration.ws.WrapThreadContextClassLoader)

Example 17 with Bus

use of org.apache.cxf.Bus in project wildfly by wildfly.

the class WSTrustTestCase method testNoClientCallback.

/**
     * No CallbackHandler is provided in STSCLient.  Username and password provided instead.
     *
     * @throws Exception
     */
@Test
@RunAsClient
@OperateOnDeployment(SERVER_DEP)
@WrapThreadContextClassLoader
public void testNoClientCallback() throws Exception {
    Bus bus = BusFactory.newInstance().createBus();
    try {
        BusFactory.setThreadDefaultBus(bus);
        final QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wssecuritypolicy", "SecurityService");
        final URL wsdlURL = new URL(serviceURL + "SecurityService?wsdl");
        Service service = Service.create(wsdlURL, serviceName);
        ServiceIface proxy = (ServiceIface) service.getPort(ServiceIface.class);
        final QName stsServiceName = new QName("http://docs.oasis-open.org/ws-sx/ws-trust/200512/", "SecurityTokenService");
        final QName stsPortName = new QName("http://docs.oasis-open.org/ws-sx/ws-trust/200512/", "UT_Port");
        URL stsURL = new URL(serviceURL.getProtocol(), serviceURL.getHost(), serviceURL.getPort(), "/jaxws-samples-wsse-policy-trust-sts/SecurityTokenService?wsdl");
        WSTrustTestUtils.setupWsseAndSTSClientNoCallbackHandler(proxy, bus, stsURL.toString(), stsServiceName, stsPortName);
        assertEquals("WS-Trust Hello World!", proxy.sayHello());
    } finally {
        bus.shutdown(true);
    }
}
Also used : Bus(org.apache.cxf.Bus) ActAsServiceIface(org.jboss.as.test.integration.ws.wsse.trust.actas.ActAsServiceIface) ServiceIface(org.jboss.as.test.integration.ws.wsse.trust.service.ServiceIface) OnBehalfOfServiceIface(org.jboss.as.test.integration.ws.wsse.trust.onbehalfof.OnBehalfOfServiceIface) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) WrapThreadContextClassLoader(org.jboss.as.test.integration.ws.WrapThreadContextClassLoader)

Example 18 with Bus

use of org.apache.cxf.Bus in project wildfly by wildfly.

the class WSTrustTestCase method testActAs.

/**
     * Request a security token that allows it to act as if it were somebody else.
     *
     * @throws Exception
     */
@Test
@RunAsClient
@OperateOnDeployment(ACT_AS_SERVER_DEP)
@WrapThreadContextClassLoader
public void testActAs() throws Exception {
    Bus bus = BusFactory.newInstance().createBus();
    try {
        BusFactory.setThreadDefaultBus(bus);
        final QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/actaswssecuritypolicy", "ActAsService");
        final URL wsdlURL = new URL(serviceURL + "ActAsService?wsdl");
        Service service = Service.create(wsdlURL, serviceName);
        ActAsServiceIface proxy = (ActAsServiceIface) service.getPort(ActAsServiceIface.class);
        WSTrustTestUtils.setupWsseAndSTSClientActAs((BindingProvider) proxy, bus);
        assertEquals("ActAs WS-Trust Hello World!", proxy.sayHello(serviceURL.getHost(), String.valueOf(serviceURL.getPort())));
    } finally {
        bus.shutdown(true);
    }
}
Also used : Bus(org.apache.cxf.Bus) ActAsServiceIface(org.jboss.as.test.integration.ws.wsse.trust.actas.ActAsServiceIface) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) WrapThreadContextClassLoader(org.jboss.as.test.integration.ws.WrapThreadContextClassLoader)

Example 19 with Bus

use of org.apache.cxf.Bus in project tomee by apache.

the class SaajInterceptor method registerInterceptors.

public static synchronized void registerInterceptors() {
    if (!interceptorsRegistered) {
        final Bus bus = CxfUtil.getBus();
        final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(CxfUtil.initBusLoader());
        try {
            SaajUniverse universe = new SaajUniverse();
            bus.getOutInterceptors().add(new SaajOutInterceptor(universe));
            bus.getInInterceptors().add(new SaajInInterceptor(universe));
            bus.getInInterceptors().add(new SaajInFaultInterceptor(universe));
        } finally {
            if (oldLoader != null) {
                CxfUtil.clearBusLoader(oldLoader);
            }
        }
        interceptorsRegistered = true;
    }
}
Also used : Bus(org.apache.cxf.Bus) SaajUniverse(org.apache.openejb.server.webservices.saaj.SaajUniverse)

Example 20 with Bus

use of org.apache.cxf.Bus in project ddf by codice.

the class StsIssueTest method testBearerPkiTokenSaml2.

/**
     * Test the User PKI Token
     */
public void testBearerPkiTokenSaml2(StsPortTypes portType) throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = StsIssueTest.class.getResource("/cxf-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    SpringBusFactory.setDefaultBus(bus);
    SpringBusFactory.setThreadDefaultBus(bus);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.newDocument();
    // Build the Claims object
    W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
    writer.writeStartElement(WST, CLAIMS, STSUtils.WST_NS_05_12);
    writer.writeNamespace(WST, STSUtils.WST_NS_05_12);
    writer.writeNamespace(IC, IDENTITY_URI);
    writer.writeAttribute(DIALECT, IDENTITY_URI);
    // Add the Role claim
    writer.writeStartElement(IC, CLAIM_TYPE, IDENTITY_URI);
    writer.writeAttribute("URI", "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role");
    writer.writeEndElement();
    Element claims = writer.getDocument().getDocumentElement();
    // Alerternatively we can use a certificate to request a SAML
    X509Security oboToken = new X509Security(doc);
    Crypto crypto = CryptoFactory.getInstance("clientKeystore.properties");
    CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ALIAS);
    cryptoType.setAlias("client");
    X509Certificate[] certs = crypto.getX509Certificates(cryptoType);
    if (null != certs) {
        oboToken.setX509Certificate(certs[0]);
        // Get a token
        SecurityToken token = requestSecurityToken(SAML2_TOKEN_TYPE, BEARER_KEYTYPE, oboToken.getElement(), bus, StsAddresses.valueOf(portType.toString()).toString(), WsdlLocations.valueOf(portType.toString()).toString(), EndPoints.valueOf(portType.toString()).toString(), claims);
        if (token != null) {
            validateSecurityToken(token);
        }
    }
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Element(org.w3c.dom.Element) CryptoType(org.apache.wss4j.common.crypto.CryptoType) Document(org.w3c.dom.Document) URL(java.net.URL) X509Certificate(java.security.cert.X509Certificate) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) Crypto(org.apache.wss4j.common.crypto.Crypto) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) X509Security(org.apache.wss4j.common.token.X509Security)

Aggregations

Bus (org.apache.cxf.Bus)57 Test (org.junit.Test)31 URL (java.net.URL)19 QName (javax.xml.namespace.QName)15 Service (javax.xml.ws.Service)12 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)11 Exchange (org.apache.cxf.message.Exchange)9 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)9 Message (org.apache.cxf.message.Message)9 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)9 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)9 WrapThreadContextClassLoader (org.jboss.as.test.integration.ws.WrapThreadContextClassLoader)9 ServiceIface (org.jboss.as.test.integration.ws.wsse.trust.service.ServiceIface)7 IOException (java.io.IOException)6 ActAsServiceIface (org.jboss.as.test.integration.ws.wsse.trust.actas.ActAsServiceIface)6 OnBehalfOfServiceIface (org.jboss.as.test.integration.ws.wsse.trust.onbehalfof.OnBehalfOfServiceIface)6 CamelContext (org.apache.camel.CamelContext)4 Message (org.apache.camel.Message)4 Greeter (org.apache.camel.hello_world_soap_http.Greeter)4 GreeterService (org.apache.camel.hello_world_soap_http.GreeterService)4