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