use of org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor in project cxf by apache.
the class CryptoCoverageCheckerTest method testEncryptedUsernameToken.
@org.junit.Test
public void testEncryptedUsernameToken() throws Exception {
if (!unrestrictedPoliciesInstalled) {
return;
}
SpringBusFactory bf = new SpringBusFactory();
URL busFile = CryptoCoverageCheckerTest.class.getResource("client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = CryptoCoverageCheckerTest.class.getResource("DoubleItCoverageChecker.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItEncryptedUsernameTokenPort");
DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(port, test.getPort());
Map<String, Object> outProps = new HashMap<>();
outProps.put("action", "UsernameToken Encrypt");
outProps.put("encryptionPropFile", "bob.properties");
outProps.put("user", "alice");
outProps.put("encryptionUser", "bob");
outProps.put("passwordCallbackClass", "org.apache.cxf.systest.ws.common.KeystorePasswordCallback");
outProps.put("encryptionParts", "{}{http://schemas.xmlsoap.org/soap/envelope/}Body;" + "{Element}{" + WSS4JConstants.WSSE_NS + "}UsernameToken;");
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(port);
}
if (test.isStreaming()) {
WSS4JStaxOutInterceptor staxOutInterceptor = new WSS4JStaxOutInterceptor(outProps);
bus.getOutInterceptors().add(staxOutInterceptor);
} else {
WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(outProps);
bus.getOutInterceptors().add(outInterceptor);
}
assertEquals(50, port.doubleIt(25));
((java.io.Closeable) port).close();
bus.shutdown(true);
}
use of org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor 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);
}
use of org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor in project cxf by apache.
the class WSSecurityClientTest method testUsernameTokenStreaming.
@Test
public void testUsernameTokenStreaming() throws Exception {
final javax.xml.ws.Service svc = javax.xml.ws.Service.create(WSDL_LOC, GREETER_SERVICE_QNAME);
final Greeter greeter = svc.getPort(USERNAME_TOKEN_PORT_QNAME, Greeter.class);
updateAddressPort(greeter, test.getPort());
Client client = ClientProxy.getClient(greeter);
Map<String, Object> props = new HashMap<>();
props.put("action", "UsernameToken");
props.put("user", "alice");
props.put("passwordType", "PasswordText");
WSS4JStaxOutInterceptor wss4jOut = new WSS4JStaxOutInterceptor(props);
client.getOutInterceptors().add(wss4jOut);
((BindingProvider) greeter).getRequestContext().put("password", "password");
try {
greeter.greetMe("CXF");
fail("should fail because of password text instead of digest");
} catch (Exception ex) {
// expected
}
client.getOutInterceptors().remove(wss4jOut);
props.put("passwordType", "PasswordDigest");
wss4jOut = new WSS4JStaxOutInterceptor(props);
client.getOutInterceptors().add(wss4jOut);
String s = greeter.greetMe("CXF");
assertEquals("Hello CXF", s);
client.getOutInterceptors().remove(wss4jOut);
try {
((BindingProvider) greeter).getRequestContext().put("password", "foo");
wss4jOut = new WSS4JStaxOutInterceptor(props);
client.getOutInterceptors().add(wss4jOut);
greeter.greetMe("CXF");
fail("should fail");
} catch (Exception ex) {
// expected
}
client.getOutInterceptors().remove(wss4jOut);
try {
props.put("passwordType", "PasswordText");
wss4jOut = new WSS4JStaxOutInterceptor(props);
client.getOutInterceptors().add(wss4jOut);
((BindingProvider) greeter).getRequestContext().put("password", "password");
greeter.greetMe("CXF");
fail("should fail");
} catch (Exception ex) {
// expected
}
client.getOutInterceptors().remove(wss4jOut);
((java.io.Closeable) greeter).close();
}
use of org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor in project cxf by apache.
the class CryptoCoverageCheckerTest method testSignedBodyTimestampSoap12.
@org.junit.Test
public void testSignedBodyTimestampSoap12() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = CryptoCoverageCheckerTest.class.getResource("client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = CryptoCoverageCheckerTest.class.getResource("DoubleItCoverageChecker.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItBodyTimestampSoap12Port");
DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(port, test.getPort());
Map<String, Object> outProps = new HashMap<>();
outProps.put("action", "Timestamp Signature");
outProps.put("signaturePropFile", "alice.properties");
outProps.put("user", "alice");
outProps.put("passwordCallbackClass", "org.apache.cxf.systest.ws.common.KeystorePasswordCallback");
outProps.put("signatureParts", "{}{http://www.w3.org/2003/05/soap-envelope}Body;" + "{}{http://docs.oasis-open.org/wss/2004/01/oasis-" + "200401-wss-wssecurity-utility-1.0.xsd}Timestamp;");
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(port);
}
if (test.isStreaming()) {
WSS4JStaxOutInterceptor staxOutInterceptor = new WSS4JStaxOutInterceptor(outProps);
bus.getOutInterceptors().add(staxOutInterceptor);
} else {
WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(outProps);
bus.getOutInterceptors().add(outInterceptor);
}
assertEquals(50, port.doubleIt(25));
((java.io.Closeable) port).close();
bus.shutdown(true);
}
use of org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor in project cxf by apache.
the class StaxClient method main.
public static void main(String[] args) throws Exception {
try {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = StaxClient.class.getResource("/wssec.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
WSSSecurityProperties properties = new WSSSecurityProperties();
properties.addAction(WSSConstants.USERNAMETOKEN);
properties.addAction(WSSConstants.TIMESTAMP);
properties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST);
properties.setTokenUser("abcd");
properties.setCallbackHandler(new UTPasswordCallback());
WSSSecurityProperties inProperties = new WSSSecurityProperties();
inProperties.addAction(WSSConstants.USERNAMETOKEN);
inProperties.addAction(WSSConstants.TIMESTAMP);
inProperties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_TEXT);
inProperties.setCallbackHandler(new UTPasswordCallback());
GreeterService service = new GreeterService();
Greeter port = service.getGreeterPort();
org.apache.cxf.endpoint.Client client = ClientProxy.getClient(port);
client.getInInterceptors().add(new WSS4JStaxInInterceptor(inProperties));
client.getOutInterceptors().add(new WSS4JStaxOutInterceptor(properties));
String[] names = new String[] { "Anne", "Bill", "Chris", "Scott" };
// make a sequence of 4 invocations
for (int i = 0; i < 4; i++) {
System.out.println("Invoking greetMe...");
String response = port.greetMe(names[i]);
System.out.println("response: " + response + "\n");
}
if (port instanceof Closeable) {
((Closeable) port).close();
}
bus.shutdown(true);
} catch (UndeclaredThrowableException ex) {
ex.getUndeclaredThrowable().printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
System.exit(0);
}
}
Aggregations