001/** 002 * Copyright 2005-2017 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 */ 016package org.kuali.rice.ksb.messaging.servicehandlers; 017 018import org.apache.wss4j.common.ext.WSPasswordCallback; 019 020import java.io.IOException; 021 022import javax.security.auth.callback.Callback; 023import javax.security.auth.callback.CallbackHandler; 024import javax.security.auth.callback.UnsupportedCallbackException; 025 026 027/** 028 * CallbackHandler that sets the password if the callback is an instance of WSPasswordCallback 029 * 030 * @author Kuali Rice Team (rice.collab@kuali.org) 031 */ 032 033public class BasicAuthenticationPasswordHandler implements CallbackHandler { 034 035 private String password; 036 037 /** 038 * Initialize the BasicAuthenticationPasswordHandler with the password 039 * 040 * @param password the password to use 041 */ 042 public BasicAuthenticationPasswordHandler(String password) { 043 this.password = password; 044 } 045 046 /** 047 * @param callbacks an array of Callback objects 048 * @see javax.security.auth.callback.CallbackHandler#handle(javax.security.auth.callback.Callback[] 049 */ 050 public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { 051 if (callbacks[0] != null && callbacks[0] instanceof WSPasswordCallback) { 052 WSPasswordCallback pc = (WSPasswordCallback) callbacks[0]; 053 pc.setPassword(password); 054 } 055 } 056}