Search in sources :

Example 6 with KeystorePasswordCallback

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

the class SecurityPolicyTest method testCXF3041.

@Test
public void testCXF3041() 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, "DoubleItPortCXF3041");
    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
    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 7 with KeystorePasswordCallback

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

the class SecurityPolicyTest method testCXF3452.

@Test
public void testCXF3452() 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);
    DoubleItPortTypeHeader pt;
    QName portQName = new QName(NAMESPACE, "DoubleItPortCXF3452");
    pt = service.getPort(portQName, DoubleItPortTypeHeader.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");
    DoubleIt di = new DoubleIt();
    di.setNumberToDouble(5);
    assertEquals(10, pt.doubleIt(di, 1).getDoubledNumber());
    ((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) DoubleItPortTypeHeader(org.example.contract.doubleit.DoubleItPortTypeHeader) Service(javax.xml.ws.Service) URL(java.net.URL) KeystorePasswordCallback(org.apache.cxf.systest.ws.common.KeystorePasswordCallback) DoubleIt(org.example.schema.doubleit.DoubleIt) Test(org.junit.Test)

Example 8 with KeystorePasswordCallback

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

the class ActionTest method testSignatureDispatchPayload.

@org.junit.Test
public void testSignatureDispatchPayload() 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.PAYLOAD);
    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 = "<ns2:DoubleIt xmlns:ns2=\"http://www.example.org/schema/DoubleIt\">" + "<numberToDouble>25</numberToDouble></ns2:DoubleIt>";
    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 9 with KeystorePasswordCallback

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

the class ActionTest method testSignatureProgrammaticMultipleActors.

@org.junit.Test
public void testSignatureProgrammaticMultipleActors() 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, "DoubleItSignatureConfigPort2");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, PORT);
    Client client = ClientProxy.getClient(port);
    // Add a UsernameToken for the "dave" actor
    Map<String, Object> props = new HashMap<>();
    props.put(ConfigurationConstants.ACTION, "UsernameToken");
    props.put(ConfigurationConstants.ACTOR, "dave");
    props.put(ConfigurationConstants.USER, "alice");
    props.put(ConfigurationConstants.PW_CALLBACK_REF, new KeystorePasswordCallback());
    WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(props);
    client.getOutInterceptors().add(outInterceptor);
    // Add a Signature for the "bob" actor - this is what the service is expecting
    Map<String, Object> props2 = new HashMap<>();
    props2.put(ConfigurationConstants.ACTION, "Signature");
    props2.put(ConfigurationConstants.ACTOR, "bob");
    props2.put(ConfigurationConstants.SIGNATURE_USER, "alice");
    props2.put(ConfigurationConstants.PW_CALLBACK_REF, new KeystorePasswordCallback());
    props2.put(ConfigurationConstants.SIG_KEY_ID, "DirectReference");
    props2.put(ConfigurationConstants.SIG_PROP_FILE, "alice.properties");
    outInterceptor = new WSS4JOutInterceptor(props2);
    outInterceptor.setId("WSS4JOutInterceptor2");
    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 10 with KeystorePasswordCallback

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

the class ActionTest method testSignatureProgrammaticStAX.

@org.junit.Test
public void testSignatureProgrammaticStAX() 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
    WSSSecurityProperties properties = new WSSSecurityProperties();
    properties.setActions(Collections.singletonList(WSSConstants.SIGNATURE));
    properties.setSignatureUser("alice");
    properties.setCallbackHandler(new KeystorePasswordCallback());
    properties.setSignatureKeyIdentifier(WSSecurityTokenConstants.KEYIDENTIFIER_SECURITY_TOKEN_DIRECT_REFERENCE);
    Properties sigProperties = CryptoFactory.getProperties("alice.properties", this.getClass().getClassLoader());
    properties.setSignatureCryptoProperties(sigProperties);
    WSS4JStaxOutInterceptor outInterceptor = new WSS4JStaxOutInterceptor(properties);
    Client client = ClientProxy.getClient(port);
    client.getOutInterceptors().add(outInterceptor);
    assertEquals(50, port.doubleIt(25));
    ((java.io.Closeable) port).close();
    bus.shutdown(true);
}
Also used : WSS4JStaxOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor) Bus(org.apache.cxf.Bus) WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) Properties(java.util.Properties) WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) URL(java.net.URL) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) Client(org.apache.cxf.endpoint.Client) KeystorePasswordCallback(org.apache.cxf.systest.ws.common.KeystorePasswordCallback)

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