View Javadoc

1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
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  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   * Workflow CryptoPasswordCallbackHandler which retrieves the keystore password
31   * from the workflow Config.
32   * 
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   */
35  public class CryptoPasswordCallbackHandler implements CallbackHandler {
36  
37      /**
38       * The actual CallBackHandler implementation.
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  }