01: package org.emforge.test;
02:
03: import java.io.IOException;
04:
05: import javax.security.auth.callback.Callback;
06: import javax.security.auth.callback.CallbackHandler;
07: import javax.security.auth.callback.UnsupportedCallbackException;
08:
09: import org.apache.commons.logging.Log;
10: import org.apache.commons.logging.LogFactory;
11: import org.apache.ws.security.WSPasswordCallback;
12:
13: public class PasswordCallbackHandler implements CallbackHandler {
14: private final Log log = LogFactory.getLog(getClass());
15:
16: private String password;
17:
18: public void setPassword(String i_password) {
19: password = i_password;
20: }
21:
22: public void handle(Callback[] i_callbacks) throws IOException,
23: UnsupportedCallbackException {
24: for (int i = 0; i < i_callbacks.length; i++) {
25: WSPasswordCallback pc = (WSPasswordCallback) i_callbacks[0];
26:
27: int usage = pc.getUsage();
28: log.debug("identifier: " + pc.getIdentifer());
29: log.debug("usage: " + pc.getUsage());
30:
31: if (usage == WSPasswordCallback.USERNAME_TOKEN) {
32: // username token pwd...
33: pc.setPassword(password);
34: } else if (usage == WSPasswordCallback.SIGNATURE) {
35: // set the password for client's keystore.keyPassword
36: pc.setPassword("EmForge");
37: }
38: }
39: }
40: }
|