Search in sources :

Example 91 with Bus

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

the class DifferentRealmTest method testUnknownRealm.

/**
 * In this test, a token is issued by the first STS in realm "C". The second STS is not
 * configured to trust realm "C" (via a cert constraint) and so authentication does not succeed.
 */
@org.junit.Test
public void testUnknownRealm() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = DifferentRealmTest.class.getResource("cxf-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = DifferentRealmTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItRealmCPort");
    DoubleItPortType transportPort = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(transportPort, PORT);
    // Transport port
    try {
        doubleIt(transportPort, 25);
    } catch (Exception ex) {
    // expected
    }
    ((java.io.Closeable) transportPort).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) URL(java.net.URL)

Example 92 with Bus

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

the class DifferentRealmTest method testRealmTransform.

/**
 * In this test, a token is issued by the first STS in realm "A". The second STS is configured
 * to trust realm "A" (via a cert constraint) and so authentication succeeds. The service
 * endpoint also sends a tokenType (SAML2) to the second STS, and so the IdentityMapper is
 * invoked to transform the authenticated principal into a principal in the current realm.
 */
@org.junit.Test
public void testRealmTransform() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = DifferentRealmTest.class.getResource("cxf-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = DifferentRealmTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItRealmTransformPort");
    DoubleItPortType transportPort = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(transportPort, PORT);
    // Transport port
    doubleIt(transportPort, 25);
    ((java.io.Closeable) transportPort).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) URL(java.net.URL)

Example 93 with Bus

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

the class STSServer method run.

protected void run() {
    URL busFile = STSServer.class.getResource("cxf-sts-saml1.xml");
    Bus busLocal = new SpringBusFactory().createBus(busFile);
    BusFactory.setDefaultBus(busLocal);
    setBus(busLocal);
    try {
        new STSServer();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) URL(java.net.URL)

Example 94 with Bus

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

the class SAMLRenewTest method testRenewExpiredTokens.

@org.junit.Test
public void testRenewExpiredTokens() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SAMLRenewTest.class.getResource("cxf-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = SAMLRenewTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName saml1PortQName = new QName(NAMESPACE, "DoubleItTransportSaml1Port");
    DoubleItPortType saml1Port = service.getPort(saml1PortQName, DoubleItPortType.class);
    updateAddressPort(saml1Port, PORT);
    QName saml1BearerPortQName = new QName(NAMESPACE, "DoubleItTransportSaml1BearerPort");
    DoubleItPortType saml1BearerPort = service.getPort(saml1BearerPortQName, DoubleItPortType.class);
    updateAddressPort(saml1BearerPort, PORT);
    QName saml2PortQName = new QName(NAMESPACE, "DoubleItTransportSaml2Port");
    DoubleItPortType saml2Port = service.getPort(saml2PortQName, DoubleItPortType.class);
    updateAddressPort(saml2Port, PORT);
    QName saml2NoRenewPortQName = new QName(NAMESPACE, "DoubleItTransportSaml2NoRenewPort");
    DoubleItPortType saml2NoRenewPort = service.getPort(saml2NoRenewPortQName, DoubleItPortType.class);
    updateAddressPort(saml2NoRenewPort, PORT);
    QName saml2IntermediaryPortQName = new QName(NAMESPACE, "DoubleItTransportSaml2IntermediaryPort");
    DoubleItPortType saml2IntermediaryPort = service.getPort(saml2IntermediaryPortQName, DoubleItPortType.class);
    updateAddressPort(saml2IntermediaryPort, PORT);
    ((BindingProvider) saml2IntermediaryPort).getRequestContext().put(SecurityConstants.USERNAME, "alice");
    // Make initial successful invocation(s)
    doubleIt(saml1Port, 25);
    doubleIt(saml1BearerPort, 30);
    doubleIt(saml2Port, 35);
    doubleIt(saml2NoRenewPort, 35);
    doubleIt(saml2IntermediaryPort, 40);
    // Now sleep to expire the token(s)
    Thread.sleep(8 * 1000);
    // The IssuedTokenInterceptorProvider should renew the token
    BindingProvider p = (BindingProvider) saml1Port;
    STSClient stsClient = (STSClient) p.getRequestContext().get(SecurityConstants.STS_CLIENT);
    stsClient.setTtl(300);
    doubleIt(saml1Port, 25);
    try {
        // The IssuedTokenInterceptorProvider should renew the token - but it should fail on
        // lack of Proof-of-Possession
        doubleIt(saml1BearerPort, 30);
        fail("Expected failure on no Proof-of-Possession");
    } catch (Exception ex) {
    // expected
    }
    // The IssuedTokenInterceptorProvider should renew the token
    p = (BindingProvider) saml2Port;
    stsClient = (STSClient) p.getRequestContext().get(SecurityConstants.STS_CLIENT);
    stsClient.setTtl(300);
    doubleIt(saml2Port, 35);
    // Renew should fail here, but it should fall back to issue
    doubleIt(saml2NoRenewPort, 35);
    doubleIt(saml2IntermediaryPort, 40);
    ((java.io.Closeable) saml1Port).close();
    ((java.io.Closeable) saml1BearerPort).close();
    ((java.io.Closeable) saml2Port).close();
    ((java.io.Closeable) saml2IntermediaryPort).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) STSClient(org.apache.cxf.ws.security.trust.STSClient) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL)

Example 95 with Bus

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

the class SAMLRenewUnitTest method testRenewSAML2Token.

@org.junit.Test
public void testRenewSAML2Token() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SAMLRenewUnitTest.class.getResource("cxf-client-unit.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    String wsdlLocation = "https://localhost:" + test.getStsPort() + "/SecurityTokenService/Transport?wsdl";
    // Request the token
    SecurityToken token = requestSecurityToken(bus, wsdlLocation, WSS4JConstants.WSS_SAML2_TOKEN_TYPE, 2, true);
    assertNotNull(token);
    // Sleep to expire the token
    Thread.sleep(2100);
    // Renew the token
    SecurityToken renewedToken = renewSecurityToken(bus, wsdlLocation, token, false);
    assertFalse(token.equals(renewedToken));
    // Try to validate old token -> fail.
    try {
        validateSecurityToken(bus, wsdlLocation, token);
        fail("Failure expected on trying to renew the old token");
    } catch (Exception ex) {
    // expected
    }
    // Validate the renewed token
    validateSecurityToken(bus, wsdlLocation, renewedToken);
    bus.shutdown(true);
}
Also used : SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) URL(java.net.URL)

Aggregations

Bus (org.apache.cxf.Bus)1144 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)800 URL (java.net.URL)748 QName (javax.xml.namespace.QName)436 Service (javax.xml.ws.Service)400 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)354 Test (org.junit.Test)219 HashMap (java.util.HashMap)63 Message (org.apache.cxf.message.Message)60 WebClient (org.apache.cxf.jaxrs.client.WebClient)50 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)48 Client (org.apache.cxf.endpoint.Client)43 Greeter (org.apache.hello_world.Greeter)42 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)41 SOAPService (org.apache.hello_world.services.SOAPService)41 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)40 Endpoint (org.apache.cxf.endpoint.Endpoint)38 ExtensionManagerBus (org.apache.cxf.bus.extension.ExtensionManagerBus)36 STSClient (org.apache.cxf.ws.security.trust.STSClient)36 Document (org.w3c.dom.Document)36