Search in sources :

Example 31 with STSClient

use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.

the class STSTokenRetrieverTest method initStsClientAsymmeticBinding.

private STSClient initStsClientAsymmeticBinding(Bus bus) {
    bus.getInInterceptors().add(new LoggingOutInterceptor());
    bus.getOutInterceptors().add(new LoggingInInterceptor());
    bus.getOutFaultInterceptors().add(new LoggingInInterceptor());
    STSClient stsClient = new STSClient(bus);
    stsClient.setWsdlLocation("http://localhost:" + STSPORT2 + STS_X509_WSDL_LOCATION_RELATIVE);
    stsClient.setServiceName(STS_SERVICE_NAME);
    stsClient.setEndpointName(STS_X509_ENDPOINT_NAME);
    stsClient.setTokenType(TOKEN_TYPE_SAML_2_0);
    stsClient.setKeyType(KEY_TYPE_X509);
    stsClient.setAllowRenewingAfterExpiry(true);
    stsClient.setEnableLifetime(true);
    Map<String, Object> props = new HashMap<>();
    props.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.sts.common.CommonCallbackHandler");
    props.put(SecurityConstants.ENCRYPT_USERNAME, "mystskey");
    props.put(SecurityConstants.ENCRYPT_PROPERTIES, "clientKeystore.properties");
    props.put(SecurityConstants.SIGNATURE_PROPERTIES, "clientKeystore.properties");
    props.put(SecurityConstants.STS_TOKEN_USERNAME, "mystskey");
    props.put(SecurityConstants.STS_TOKEN_PROPERTIES, "clientKeystore.properties");
    props.put(SecurityConstants.STS_TOKEN_USE_CERT_FOR_KEYINFO, "true");
    stsClient.setProperties(props);
    return stsClient;
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) HashMap(java.util.HashMap) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor)

Example 32 with STSClient

use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.

the class SymmetricBindingTest method testUsernameTokenSAML1Dispatch.

@org.junit.Test
public void testUsernameTokenSAML1Dispatch() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SymmetricBindingTest.class.getResource("cxf-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = SymmetricBindingTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSymmetricSAML1Port");
    Dispatch<DOMSource> dispatch = service.createDispatch(portQName, DOMSource.class, Service.Mode.PAYLOAD, new AddressingFeature());
    updateAddressPort(dispatch, test.getPort());
    // Setup STSClient
    STSClient stsClient = createDispatchSTSClient(bus);
    String wsdlLocation = "http://localhost:" + test.getStsPort() + "/SecurityTokenService/UT?wsdl";
    stsClient.setWsdlLocation(wsdlLocation);
    // Creating a DOMSource Object for the request
    DOMSource request = createDOMRequest();
    // Make a successful request
    Client client = ((DispatchImpl<DOMSource>) dispatch).getClient();
    client.getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);
    if (test.isStreaming()) {
        client.getRequestContext().put(SecurityConstants.ENABLE_STREAMING_SECURITY, "true");
        client.getResponseContext().put(SecurityConstants.ENABLE_STREAMING_SECURITY, "true");
    }
    DOMSource response = dispatch.invoke(request);
    assertNotNull(response);
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) DOMSource(javax.xml.transform.dom.DOMSource) STSClient(org.apache.cxf.ws.security.trust.STSClient) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) AddressingFeature(javax.xml.ws.soap.AddressingFeature) QName(javax.xml.namespace.QName) DispatchImpl(org.apache.cxf.jaxws.DispatchImpl) Service(javax.xml.ws.Service) STSClient(org.apache.cxf.ws.security.trust.STSClient) Client(org.apache.cxf.endpoint.Client) URL(java.net.URL)

Example 33 with STSClient

use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.

the class TemplateTest method testBearerToSAML2PublicKey.

@org.junit.Test
public void testBearerToSAML2PublicKey() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = TemplateTest.class.getResource("cxf-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = TemplateTest.class.getResource("DoubleItNoTemplate2.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML2PublicKeyPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    // Setup STSClient
    STSClient stsClient = createSTSClient(bus);
    stsClient.setKeyType("http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer");
    stsClient.setTokenType("http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0");
    String wsdlLocation = "https://localhost:" + test.getStsPort() + "/SecurityTokenService/Transport?wsdl";
    stsClient.setWsdlLocation(wsdlLocation);
    ((BindingProvider) port).getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }
    try {
        doubleIt(port, 25);
        fail("Failure expected on sending a SAML 2.0 Bearer token");
    } catch (Exception ex) {
    // expected
    }
    ((java.io.Closeable) port).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) URL(java.net.URL)

Example 34 with STSClient

use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.

the class TemplateTest method testSAML1PublicKey.

@org.junit.Test
public void testSAML1PublicKey() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = TemplateTest.class.getResource("cxf-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = TemplateTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML1PublicKeyPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    // Setup STSClient
    STSClient stsClient = createSTSClient(bus);
    String wsdlLocation = "https://localhost:" + test.getStsPort() + "/SecurityTokenService/Transport?wsdl";
    stsClient.setWsdlLocation(wsdlLocation);
    ((BindingProvider) port).getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }
    doubleIt(port, 25);
    ((java.io.Closeable) port).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) URL(java.net.URL)

Example 35 with STSClient

use of org.apache.cxf.ws.security.trust.STSClient in project cxf by apache.

the class TemplateTest method testSendBearerToSAML1PublicKey.

@org.junit.Test
public void testSendBearerToSAML1PublicKey() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = TemplateTest.class.getResource("cxf-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = TemplateTest.class.getResource("DoubleItNoTemplate2.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportSAML1PublicKeyPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    // Setup STSClient
    STSClient stsClient = createSTSClient(bus);
    stsClient.setKeyType("http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer");
    stsClient.setTokenType("http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1");
    String wsdlLocation = "https://localhost:" + test.getStsPort() + "/SecurityTokenService/Transport?wsdl";
    stsClient.setWsdlLocation(wsdlLocation);
    ((BindingProvider) port).getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);
    ((BindingProvider) port).getRequestContext().put(SecurityConstants.SIGNATURE_USERNAME, "myclientkey");
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }
    try {
        doubleIt(port, 25);
        fail("Failure expected on sending a SAML 1.1 Bearer token");
    } catch (Exception ex) {
    // expected
    }
    ((java.io.Closeable) port).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) URL(java.net.URL)

Aggregations

STSClient (org.apache.cxf.ws.security.trust.STSClient)89 Bus (org.apache.cxf.Bus)35 HashMap (java.util.HashMap)33 URL (java.net.URL)31 QName (javax.xml.namespace.QName)29 Service (javax.xml.ws.Service)27 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)24 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)21 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)14 BindingProvider (javax.xml.ws.BindingProvider)11 Test (org.junit.Test)11 Client (org.apache.cxf.endpoint.Client)9 WebService (javax.jws.WebService)5 BusException (org.apache.cxf.BusException)5 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)5 EndpointException (org.apache.cxf.endpoint.EndpointException)5 MessageImpl (org.apache.cxf.message.MessageImpl)5 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)5 ClientCallbackHandler (org.jboss.as.test.integration.ws.wsse.trust.shared.ClientCallbackHandler)5 DOMSource (javax.xml.transform.dom.DOMSource)4