My websrervice works using authentication, but the problem is that it’s static, it’s written in the XML file, and even in the class that implements CallbackHandler.
I want to execute my webservice but by using a login and a password that user will enter in a console
This is the client part where I wrote the user :
<bean id="wss4jOutInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
<property name="properties">
<map>
<entry key="action" value="UsernameToken Timestamp" />
**<entry key="user" value="pT64f349"/>**
<entry key="passwordType" value="PasswordDigest" />
<entry>
<key>
<value>passwordCallbackRef</value>
</key>
<ref bean="passwordCallback" />
</entry>
</map>
</property>
</bean>
And this is where I put my password :
public class ClientPasswordCallback implements CallbackHandler{
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
WSPasswordCallback callback = (WSPasswordCallback) callbacks[0];
if(callback.getIdentifier().equals("pT64f349")){
**callback.setPassword("pass");**
}
}
}
Thnx a lot
You could maybe adapt your
ClientPasswordCallbackto read the user inputs from aThreadLocal(see Javadoc and example 1 or example 2).You’ll have first to fill the inputs into the
ThreadLocaland then you can read them in theClientPasswordCallback.