use of org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor in project midpoint by Evolveum.
the class Action method createModelPort.
protected ModelPortType createModelPort() {
ModelService modelService = new ModelService();
ModelPortType port = modelService.getModelPort();
BindingProvider bp = (BindingProvider) port;
Client client = ClientProxy.getClient(port);
Endpoint endpoint = client.getEndpoint();
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = http.getClient();
if (httpClientPolicy == null) {
httpClientPolicy = new HTTPClientPolicy();
http.setClient(httpClientPolicy);
}
httpClientPolicy.setConnectionTimeout(10000);
Map<String, Object> requestContext = bp.getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, params.getUrl().toString());
requestContext.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
requestContext.put(WSHandlerConstants.USER, params.getUsername());
requestContext.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
ClientPasswordHandler handler = new ClientPasswordHandler();
handler.setPassword(params.getInsertedPassword());
requestContext.put(WSHandlerConstants.PW_CALLBACK_REF, handler);
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(requestContext);
endpoint.getOutInterceptors().add(wssOut);
if (params.isVerbose()) {
endpoint.getOutInterceptors().add(new LoggingOutInterceptor());
endpoint.getInInterceptors().add(new LoggingInInterceptor());
}
return port;
}
use of org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor in project midpoint by Evolveum.
the class AbstractTestForExchangeConnector method createModelPort.
public ModelPortType createModelPort(String[] args) {
String endpointUrl = DEFAULT_ENDPOINT_URL;
if (args.length > 0) {
endpointUrl = args[0];
}
System.out.println("Endpoint URL: " + endpointUrl);
// uncomment this if you want to use Fiddler or any other proxy
// ProxySelector.setDefault(new MyProxySelector("127.0.0.1", 8888));
ModelService modelService = new ModelService();
ModelPortType modelPort = modelService.getModelPort();
BindingProvider bp = (BindingProvider) modelPort;
Map<String, Object> requestContext = bp.getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);
org.apache.cxf.endpoint.Client client = ClientProxy.getClient(modelPort);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setReceiveTimeout(300000L);
http.setClient(httpClientPolicy);
org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
Map<String, Object> outProps = new HashMap<String, Object>();
outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
outProps.put(WSHandlerConstants.USER, ADM_USERNAME);
outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordHandler.class.getName());
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
cxfEndpoint.getOutInterceptors().add(wssOut);
return modelPort;
}
use of org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor in project camel by apache.
the class GreeterClientTest method sendMessageWithUsernameToken.
protected String sendMessageWithUsernameToken(String username, String password, String message) throws Exception {
final javax.xml.ws.Service svc = javax.xml.ws.Service.create(WSDL_LOC, SERVICE_QNAME);
final Greeter greeter = svc.getPort(PORT_QNAME, Greeter.class);
Client client = ClientProxy.getClient(greeter);
Map<String, Object> props = new HashMap<String, Object>();
props.put("action", "UsernameToken");
props.put("user", username);
// Set the the password type to be plain text,
// so we can keep using the password to authenticate with spring security
props.put("passwordType", "PasswordText");
WSS4JOutInterceptor wss4jOut = new WSS4JOutInterceptor(props);
client.getOutInterceptors().add(wss4jOut);
((BindingProvider) greeter).getRequestContext().put("password", password);
return greeter.greetMe(message);
}
use of org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor in project midpoint by Evolveum.
the class Main method createModelPort.
public static ModelPortType createModelPort(String[] args) {
String endpointUrl = DEFAULT_ENDPOINT_URL;
if (args.length > 0) {
endpointUrl = args[0];
}
System.out.println("Endpoint URL: " + endpointUrl);
// uncomment this if you want to use Fiddler or any other proxy
//ProxySelector.setDefault(new MyProxySelector("127.0.0.1", 8888));
ModelService modelService = new ModelService();
ModelPortType modelPort = modelService.getModelPort();
BindingProvider bp = (BindingProvider) modelPort;
Map<String, Object> requestContext = bp.getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);
org.apache.cxf.endpoint.Client client = ClientProxy.getClient(modelPort);
org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
Map<String, Object> outProps = new HashMap<String, Object>();
outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
outProps.put(WSHandlerConstants.USER, ADM_USERNAME);
outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordHandler.class.getName());
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
cxfEndpoint.getOutInterceptors().add(wssOut);
// enable the following to get client-side logging of outgoing requests and incoming responses
cxfEndpoint.getOutInterceptors().add(new LoggingOutInterceptor());
cxfEndpoint.getInInterceptors().add(new LoggingInInterceptor());
return modelPort;
}
use of org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor in project fabric8 by jboss-fuse.
the class CustomSecurityInterceptor method handleMessage.
/**
* This is the actual implementation for our interceptor - we define the necessary properties for doing the authentication
* and then iterate over the rest of the interceptor chain to find the WSS4J interceptor and configure it properly.
*/
public void handleMessage(Message message) throws Fault {
/*
* Define the configuration properties
*/
Map<String, Object> outProps = new HashMap<String, Object>();
outProps.put("action", "UsernameToken");
outProps.put("passwordType", "PasswordText");
/*
* The username ('admin') is provided as a literal, the corresponding password will be determined by the client
* password callback object.
*/
outProps.put("user", "admin");
outProps.put("passwordCallbackClass", ClientPasswordCallback.class.getName());
/*
* Find the WSS4J interceptor in the interceptor chain and set the configuration properties
*/
for (Interceptor interceptor : message.getInterceptorChain()) {
// set properties for WSS4JOutInterceptor
if (interceptor.getClass().getName().equals("org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor")) {
((WSS4JOutInterceptor) interceptor).setProperties(outProps);
}
}
}
Aggregations