Client client = ClientProxy.getClient(greeter);
Map<String, Object> props = new HashMap<String, Object>();
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) {