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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations