Search in sources :

Example 11 with KeystorePasswordCallback

use of org.apache.cxf.systest.ws.common.KeystorePasswordCallback in project cxf by apache.

the class AbstractServer method doPublish.

private void doPublish(String url, Object obj) {
    Endpoint ep = Endpoint.create(obj);
    ep.getProperties().put(SecurityConstants.CALLBACK_HANDLER, new KeystorePasswordCallback());
    ep.getProperties().put(SecurityConstants.ENCRYPT_PROPERTIES, "bob.properties");
    if (streaming) {
        ep.getProperties().put(SecurityConstants.ENABLE_STREAMING_SECURITY, "true");
    }
    ep.publish(url);
}
Also used : Endpoint(javax.xml.ws.Endpoint) KeystorePasswordCallback(org.apache.cxf.systest.ws.common.KeystorePasswordCallback)

Example 12 with KeystorePasswordCallback

use of org.apache.cxf.systest.ws.common.KeystorePasswordCallback in project cxf by apache.

the class ActionTest method testSignatureDispatchMessage.

@org.junit.Test
public void testSignatureDispatchMessage() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = ActionTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = ActionTest.class.getResource("DoubleItAction.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSignatureConfigPort");
    Dispatch<StreamSource> dispatch = service.createDispatch(portQName, StreamSource.class, Service.Mode.MESSAGE);
    updateAddressPort(dispatch, PORT);
    // Programmatic interceptor
    Map<String, Object> props = new HashMap<>();
    props.put(ConfigurationConstants.ACTION, "Signature");
    props.put(ConfigurationConstants.SIGNATURE_USER, "alice");
    props.put(ConfigurationConstants.PW_CALLBACK_REF, new KeystorePasswordCallback());
    props.put(ConfigurationConstants.SIG_KEY_ID, "DirectReference");
    props.put(ConfigurationConstants.SIG_PROP_FILE, "alice.properties");
    WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(props);
    Client client = ((DispatchImpl<StreamSource>) dispatch).getClient();
    client.getOutInterceptors().add(outInterceptor);
    String payload = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soap:Header></soap:Header><soap:Body>" + "<ns2:DoubleIt xmlns:ns2=\"http://www.example.org/schema/DoubleIt\">" + "<numberToDouble>25</numberToDouble></ns2:DoubleIt>" + "</soap:Body></soap:Envelope>";
    StreamSource request = new StreamSource(new StringReader(payload));
    StreamSource response = dispatch.invoke(request);
    assertNotNull(response);
    Document doc = StaxUtils.read(response.getInputStream());
    assertEquals("50", doc.getElementsByTagNameNS(null, "doubledNumber").item(0).getTextContent());
    ((java.io.Closeable) dispatch).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) DispatchImpl(org.apache.cxf.jaxws.DispatchImpl) StreamSource(javax.xml.transform.stream.StreamSource) Service(javax.xml.ws.Service) Document(org.w3c.dom.Document) URL(java.net.URL) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) StringReader(java.io.StringReader) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Client(org.apache.cxf.endpoint.Client) KeystorePasswordCallback(org.apache.cxf.systest.ws.common.KeystorePasswordCallback)

Example 13 with KeystorePasswordCallback

use of org.apache.cxf.systest.ws.common.KeystorePasswordCallback in project cxf by apache.

the class ActionTest method testSignatureProgrammatic.

@org.junit.Test
public void testSignatureProgrammatic() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = ActionTest.class.getResource("client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = ActionTest.class.getResource("DoubleItAction.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItSignatureConfigPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, PORT);
    // Programmatic interceptor
    Map<String, Object> props = new HashMap<>();
    props.put(ConfigurationConstants.ACTION, "Signature");
    props.put(ConfigurationConstants.SIGNATURE_USER, "alice");
    props.put(ConfigurationConstants.PW_CALLBACK_REF, new KeystorePasswordCallback());
    props.put(ConfigurationConstants.SIG_KEY_ID, "DirectReference");
    props.put(ConfigurationConstants.SIG_PROP_FILE, "alice.properties");
    WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(props);
    Client client = ClientProxy.getClient(port);
    client.getOutInterceptors().add(outInterceptor);
    assertEquals(50, port.doubleIt(25));
    ((java.io.Closeable) port).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Client(org.apache.cxf.endpoint.Client) KeystorePasswordCallback(org.apache.cxf.systest.ws.common.KeystorePasswordCallback)

Example 14 with KeystorePasswordCallback

use of org.apache.cxf.systest.ws.common.KeystorePasswordCallback in project cxf by apache.

the class SecurityPolicyTest method testCXF3042.

@Test
public void testCXF3042() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    Bus bus = bf.createBus();
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = SecurityPolicyTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    DoubleItPortType pt;
    QName portQName = new QName(NAMESPACE, "DoubleItPortCXF3042");
    pt = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(pt, PORT);
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, new KeystorePasswordCallback());
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES, "alice.properties");
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES, "alice.properties");
    // DOM
    assertEquals(10, pt.doubleIt(5));
    // Streaming
    SecurityTestUtil.enableStreaming(pt);
    assertEquals(10, pt.doubleIt(5));
    ((java.io.Closeable) pt).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) KeystorePasswordCallback(org.apache.cxf.systest.ws.common.KeystorePasswordCallback) Test(org.junit.Test)

Example 15 with KeystorePasswordCallback

use of org.apache.cxf.systest.ws.common.KeystorePasswordCallback in project cxf by apache.

the class SecurityPolicyTest method testPolicy.

@Test
public void testPolicy() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = SecurityPolicyTest.class.getResource("https_config_client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = SecurityPolicyTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    DoubleItPortType pt;
    QName portQName = new QName(NAMESPACE, "DoubleItPortXPath");
    pt = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(pt, PORT);
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, new KeystorePasswordCallback());
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES, "alice.properties");
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES, "bob.properties");
    assertEquals(10, pt.doubleIt(5));
    ((java.io.Closeable) pt).close();
    portQName = new QName(NAMESPACE, "DoubleItPortEncryptThenSign");
    pt = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(pt, PORT);
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, new KeystorePasswordCallback());
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES, "alice.properties");
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES, "bob.properties");
    // DOM
    pt.doubleIt(5);
    // TODO See WSS-464
    // SecurityTestUtil.enableStreaming(pt);
    // pt.doubleIt(5);
    ((java.io.Closeable) pt).close();
    portQName = new QName(NAMESPACE, "DoubleItPortSign");
    pt = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(pt, PORT);
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, new KeystorePasswordCallback());
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES, "alice.properties");
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES, "bob.properties");
    // DOM
    pt.doubleIt(5);
    // Streaming
    SecurityTestUtil.enableStreaming(pt);
    pt.doubleIt(5);
    ((java.io.Closeable) pt).close();
    portQName = new QName(NAMESPACE, "DoubleItPortSignThenEncrypt");
    pt = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(pt, PORT);
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, new KeystorePasswordCallback());
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES, "alice.properties");
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES, "bob.properties");
    // DOM
    pt.doubleIt(5);
    // Streaming
    SecurityTestUtil.enableStreaming(pt);
    pt.doubleIt(5);
    ((java.io.Closeable) pt).close();
    portQName = new QName(NAMESPACE, "DoubleItPortHttps");
    pt = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(pt, SSL_PORT);
    try {
        pt.doubleIt(25);
    } catch (Exception ex) {
        String msg = ex.getMessage();
        if (!msg.contains("sername")) {
            throw ex;
        }
    }
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.USERNAME, "bob");
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.SIGNATURE_USERNAME, "bob");
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.PASSWORD, "pwd");
    // DOM
    pt.doubleIt(25);
    // Streaming
    SecurityTestUtil.enableStreaming(pt);
    pt.doubleIt(25);
    ((java.io.Closeable) pt).close();
    try {
        portQName = new QName(NAMESPACE, "DoubleItPortHttp");
        pt = service.getPort(portQName, DoubleItPortType.class);
        updateAddressPort(pt, PORT);
        pt.doubleIt(25);
        fail("https policy should have triggered");
    } catch (Exception ex) {
        String msg = ex.getMessage();
        if (!msg.contains("HttpsToken")) {
            throw ex;
        }
    }
    ((java.io.Closeable) pt).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) KeystorePasswordCallback(org.apache.cxf.systest.ws.common.KeystorePasswordCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) IOException(java.io.IOException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.junit.Test)

Aggregations

KeystorePasswordCallback (org.apache.cxf.systest.ws.common.KeystorePasswordCallback)19 URL (java.net.URL)14 QName (javax.xml.namespace.QName)14 Service (javax.xml.ws.Service)14 Bus (org.apache.cxf.Bus)14 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)14 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)9 Test (org.junit.Test)9 HashMap (java.util.HashMap)5 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)5 Client (org.apache.cxf.endpoint.Client)5 IOException (java.io.IOException)4 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)4 Endpoint (javax.xml.ws.Endpoint)4 WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)4 StringReader (java.io.StringReader)3 StreamSource (javax.xml.transform.stream.StreamSource)3 Document (org.w3c.dom.Document)3 DispatchImpl (org.apache.cxf.jaxws.DispatchImpl)2 UTPasswordCallback (org.apache.cxf.systest.ws.common.UTPasswordCallback)2