01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: // Created on Feb 27, 2006
17: package org.kuali.rice.config.wss4j;
18:
19: import java.io.IOException;
20:
21: import javax.security.auth.callback.Callback;
22: import javax.security.auth.callback.CallbackHandler;
23: import javax.security.auth.callback.UnsupportedCallbackException;
24:
25: import org.apache.ws.security.WSPasswordCallback;
26: import org.kuali.rice.config.Config;
27: import org.kuali.rice.config.ConfigurationException;
28: import org.kuali.rice.core.Core;
29:
30: /**
31: * Workflow CryptoPasswordCallbackHandler which retrieves the keystore password
32: * from the workflow Config.
33: *
34: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
35: */
36: public class CryptoPasswordCallbackHandler implements CallbackHandler {
37:
38: /**
39: * The actual CallBackHandler implementation.
40: */
41: public void handle(Callback[] callbacks) throws IOException,
42: UnsupportedCallbackException {
43: for (int i = 0; i < callbacks.length; i++) {
44: if (callbacks[i] instanceof WSPasswordCallback) {
45: WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
46: String password = Core.getCurrentContextConfig()
47: .getKeystorePassword();
48: if (password == null) {
49: throw new ConfigurationException(
50: "Could not locate the webservice password. Should be configured as the '"
51: + Config.KEYSTORE_PASSWORD
52: + "' property.");
53: }
54: pc.setPassword(password);
55: } else {
56: throw new UnsupportedCallbackException(callbacks[i],
57: "Unrecognized Callback");
58: }
59: }
60: }
61: }
|