Search in sources :

Example 1 with KeystorePasswordCallback

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

the class StaxServer method doPublish.

private void doPublish(String url, Object obj) {
    Endpoint ep = Endpoint.create(obj);
    ep.getProperties().put(SecurityConstants.ENABLE_STREAMING_SECURITY, "true");
    ep.getProperties().put(SecurityConstants.CALLBACK_HANDLER + ".sct", new KeystorePasswordCallback());
    ep.getProperties().put(SecurityConstants.ENCRYPT_PROPERTIES + ".sct", "bob.properties");
    if (url.contains("X10_I")) {
        ep.getProperties().put(SecurityConstants.SIGNATURE_PROPERTIES + ".sct", "bob.properties");
        ep.getProperties().put(SecurityConstants.ENCRYPT_PROPERTIES + ".sct", "alice.properties");
    } else if (url.contains("MutualCert")) {
        ep.getProperties().put(SecurityConstants.ENCRYPT_PROPERTIES + ".sct", "bob.properties");
        ep.getProperties().put(SecurityConstants.SIGNATURE_PROPERTIES + ".sct", "alice.properties");
        ep.getProperties().put(SecurityConstants.CALLBACK_HANDLER, new KeystorePasswordCallback());
    } else if (url.contains("UserNameOverTransport")) {
        ep.getProperties().put(SecurityConstants.CALLBACK_HANDLER + ".sct", new UTPasswordCallback());
    }
    ep.publish(url);
}
Also used : Endpoint(javax.xml.ws.Endpoint) UTPasswordCallback(org.apache.cxf.systest.ws.common.UTPasswordCallback) KeystorePasswordCallback(org.apache.cxf.systest.ws.common.KeystorePasswordCallback)

Example 2 with KeystorePasswordCallback

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

the class AbstractServerRestricted 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, "restricted/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 3 with KeystorePasswordCallback

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

the class SecurityPolicyTest method testFault.

@Test
public void testFault() 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);
    QName portQName = new QName(NAMESPACE, "DoubleItFaultPortSignThenEncrypt");
    DoubleItPortType 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
    try {
        pt.doubleIt(5);
        fail("SOAPFaultException expected!");
    } catch (SOAPFaultException e) {
        assertEquals("Foo", e.getFault().getFaultString());
    } finally {
        ((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) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) URL(java.net.URL) KeystorePasswordCallback(org.apache.cxf.systest.ws.common.KeystorePasswordCallback) Test(org.junit.Test)

Example 4 with KeystorePasswordCallback

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

the class SecurityPolicyTest method testCXF4119.

@Test
public void testCXF4119() 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, "DoubleItPortCXF4119");
    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, "revocation.properties");
    ((BindingProvider) pt).getRequestContext().put(SecurityConstants.ENABLE_REVOCATION, "true");
    DoubleIt di = new DoubleIt();
    di.setNumberToDouble(5);
    try {
        pt.doubleIt(di, 1);
        fail("Failure expected on a revoked certificate");
    } catch (Exception ex) {
    // expected
    }
    ((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) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) IOException(java.io.IOException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.junit.Test)

Example 5 with KeystorePasswordCallback

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

the class SecurityPolicyTest method testDispatchClient.

@Test
public void testDispatchClient() 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);
    QName portQName = new QName(NAMESPACE, "DoubleItPortEncryptThenSign");
    Dispatch<Source> disp = service.createDispatch(portQName, Source.class, Mode.PAYLOAD);
    disp.getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, new KeystorePasswordCallback());
    disp.getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES, "alice.properties");
    disp.getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES, "bob.properties");
    updateAddressPort(disp, PORT);
    String req = "<ns2:DoubleIt xmlns:ns2=\"http://www.example.org/schema/DoubleIt\">" + "<numberToDouble>25</numberToDouble></ns2:DoubleIt>";
    Source source = new StreamSource(new StringReader(req));
    source = disp.invoke(source);
    Node nd = StaxUtils.read(source);
    if (nd instanceof Document) {
        nd = ((Document) nd).getDocumentElement();
    }
    Map<String, String> ns = new HashMap<>();
    ns.put("ns2", "http://www.example.org/schema/DoubleIt");
    XPathUtils xp = new XPathUtils(ns);
    Object o = xp.getValue("//ns2:DoubleItResponse/doubledNumber", nd, XPathConstants.STRING);
    assertEquals(StaxUtils.toString(nd), "50", o);
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) Node(org.w3c.dom.Node) Service(javax.xml.ws.Service) Document(org.w3c.dom.Document) URL(java.net.URL) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) XPathUtils(org.apache.cxf.helpers.XPathUtils) StringReader(java.io.StringReader) KeystorePasswordCallback(org.apache.cxf.systest.ws.common.KeystorePasswordCallback) 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