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