1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.config.wss4j;
17
18 import org.apache.ws.security.WSPasswordCallback;
19 import org.kuali.rice.core.api.config.ConfigurationException;
20 import org.kuali.rice.core.api.config.property.Config;
21 import org.kuali.rice.core.api.config.property.ConfigContext;
22
23 import javax.security.auth.callback.Callback;
24 import javax.security.auth.callback.CallbackHandler;
25 import javax.security.auth.callback.UnsupportedCallbackException;
26 import java.io.IOException;
27
28
29
30
31
32
33
34
35 public class CryptoPasswordCallbackHandler implements CallbackHandler {
36
37
38
39
40 public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
41 for (int i = 0; i < callbacks.length; i++) {
42 if (callbacks[i] instanceof WSPasswordCallback) {
43 WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
44 String password = ConfigContext.getCurrentContextConfig().getKeystorePassword();
45 if (password == null) {
46 throw new ConfigurationException("Could not locate the webservice password. Should be configured as the '" + Config.KEYSTORE_PASSWORD + "' property.");
47 }
48 pc.setPassword(password);
49 } else {
50 throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
51 }
52 }
53 }
54 }