Search in sources :

Example 96 with Bus

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

the class SAMLRenewUnitTest method testRenewSAML2TokenFail.

@org.junit.Test
public void testRenewSAML2TokenFail() 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, false);
    assertNotNull(token);
    // Sleep to expire the token
    Thread.sleep(2100);
    // Renew the token - this will fail as we didn't send a Renewing @OK attribute
    try {
        renewSecurityToken(bus, wsdlLocation, token, false);
        fail("Failure expected on a different AppliesTo address");
    } catch (Exception ex) {
    // expected
    }
    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)

Example 97 with Bus

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

the class SAMLRenewUnitTest method testRenewSAML2TokenDifferentAppliesTo.

@org.junit.Test
public void testRenewSAML2TokenDifferentAppliesTo() 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
    token.setIssuerAddress("http://www.apache.org");
    try {
        renewSecurityToken(bus, wsdlLocation, token, true);
        fail("Failure expected on a different AppliesTo address");
    } catch (Exception ex) {
    // expected
    }
    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)

Example 98 with Bus

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

the class AsymmetricEncryptionTest method testEncryptedToken.

@org.junit.Test
public void testEncryptedToken() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SecurityContextTokenUnitTest.class.getResource("cxf-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    SecurityToken token = requestSecurityToken(bus, test.getStsPort());
    assertTrue(token != null);
    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)

Example 99 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.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 100 with Bus

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

the class JaxwsBasicAuthTest method testBadBasicAuth.

@org.junit.Test
public void testBadBasicAuth() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = JaxwsBasicAuthTest.class.getResource("cxf-bad-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = JaxwsBasicAuthTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }
    try {
        doubleIt(port, 30);
        fail("Expected failure on a bad password");
    } catch (javax.xml.ws.soap.SOAPFaultException fault) {
        String message = fault.getMessage();
        assertTrue(message.contains("STS Authentication failed") || message.contains("Validation of security token failed"));
    }
    ((java.io.Closeable) port).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)

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