001 /**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.ksb.config.wss4j;
017
018 import org.apache.ws.security.WSPasswordCallback;
019 import org.kuali.rice.core.api.config.ConfigurationException;
020 import org.kuali.rice.core.api.config.property.Config;
021 import org.kuali.rice.core.api.config.property.ConfigContext;
022
023 import javax.security.auth.callback.Callback;
024 import javax.security.auth.callback.CallbackHandler;
025 import javax.security.auth.callback.UnsupportedCallbackException;
026 import java.io.IOException;
027
028
029 /**
030 * Workflow CryptoPasswordCallbackHandler which retrieves the keystore password
031 * from the workflow Config.
032 *
033 * @author Kuali Rice Team (rice.collab@kuali.org)
034 */
035 public class CryptoPasswordCallbackHandler implements CallbackHandler {
036
037 /**
038 * The actual CallBackHandler implementation.
039 */
040 public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
041 for (int i = 0; i < callbacks.length; i++) {
042 if (callbacks[i] instanceof WSPasswordCallback) {
043 WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
044 String password = ConfigContext.getCurrentContextConfig().getKeystorePassword();
045 if (password == null) {
046 throw new ConfigurationException("Could not locate the webservice password. Should be configured as the '" + Config.KEYSTORE_PASSWORD + "' property.");
047 }
048 pc.setPassword(password);
049 } else {
050 throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
051 }
052 }
053 }
054 }