Reputation: 115
I would like to know if we can set WS-Security properties like ws-security.signature.properties
in WSS4J interceptors.
I'm configuring WSS4J properties this way but WSHandler need ws-security.signature.properties
and ws-security.encryption.properties
but it can't find it.
Map<String, Object> outProps = new HashMap<String, Object>()
outProps.put(WSHandlerConstants.ACTION,
WSHandlerConstants.TIMESTAMP + " "
+ WSHandlerConstants.SIGNATURE + " "
+ WSHandlerConstants.ENCRYPT);
outProps.put(WSHandlerConstants.USER, "clientKey");
outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS,
ClientKeystorePasswordCallback.class.getName());
outProps.put(WSHandlerConstants.SIG_PROP_FILE,
"clientWSsec-PC165.properties");
outProps.put(WSHandlerConstants.ENC_PROP_FILE,
"clientWSsec-PC165-Srv.properties");
outProps.put(WSHandlerConstants.SIGNATURE_USER, "clientKey");
outProps.put(WSHandlerConstants.ENCRYPTION_USER, "serverKey");
How can I add thoses properties in WSS4J interceptors ?
Thank you!
Upvotes: 0
Views: 2364
Reputation: 3495
How can I add thoses properties in WSS4J interceptors ?
if you are using cxf with spring, try this:
ClientKeystorePasswordCallback:
/**
* @see <a href="https://github.com/gmazza/blog-samples/blob/master/cxf_x509_profile/client/src/main/java/client/ClientKeystorePasswordCallback.java">ClientKeystorePasswordCallback</a>
*/
public class ClientKeystorePasswordCallback implements CallbackHandler {
private Map<String, String> passwords =
new HashMap<String, String>();
public ClientKeystorePasswordCallback() {
passwords.put("myclientkey", "ckpass");
}
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
WSPasswordCallback pc = (WSPasswordCallback)callbacks[i];
String pass = passwords.get(pc.getIdentifier());
if (pass != null) {
pc.setPassword(pass);
return;
}
}
}
}
spring configuration:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<bean id="clientKeystorePasswordCallback" class="client.ClientKeystorePasswordCallback"/>
<bean id="wss4JInInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
<constructor-arg>
<map>
<entry key="#{T(org.apache.ws.security.handler.WSHandlerConstants).ACTION}"
value="#{T(org.apache.ws.security.handler.WSHandlerConstants).TIMESTAMP} #{T(org.apache.ws.security.handler.WSHandlerConstants).SIGNATURE} #{T(org.apache.ws.security.handler.WSHandlerConstants).ENCRYPT}"/>
<entry key="#{T(org.apache.ws.security.handler.WSHandlerConstants).USER}"
value="clientKey"/>
<entry key="#{T(org.apache.ws.security.handler.WSHandlerConstants).PASSWORD_TYPE}"
value="#{T(org.apache.ws.security.WSConstants).PW_TEXT}"/>
<entry key="#{T(org.apache.ws.security.handler.WSHandlerConstants).PW_CALLBACK_REF}"
value-ref="clientKeystorePasswordCallback"/>
<entry key="#{T(org.apache.ws.security.handler.WSHandlerConstants).SIG_PROP_FILE}"
value="clientWSsec-PC165.properties"/>
<entry key="#{T(org.apache.ws.security.handler.WSHandlerConstants).ENC_PROP_FILE}"
value="clientWSsec-PC165-Srv.properties"/>
<entry key="#{T(org.apache.ws.security.handler.WSHandlerConstants).SIGNATURE_USER}"
value="clientKey"/>
<entry key="#{T(org.apache.ws.security.handler.WSHandlerConstants).ENCRYPTION_USER}"
value="serverKey"/>
</map>
</constructor-arg>
</bean>
<jaxws:endpoint id="myServiceEndpoint" implementor="#myServiceImpl" address="/myServicePath">
<jaxws:inInterceptors>
<ref bean="wss4JInInterceptor"/>
</jaxws:inInterceptors>
</jaxws:endpoint>
<bean id="myServiceImpl" class="server.MyServiceImpl"/>
</beans>
Upvotes: 1