1 /**
2 * Copyright 2005-2013 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.messaging.servicehandlers;
17
18 import java.io.IOException;
19
20 import javax.security.auth.callback.Callback;
21 import javax.security.auth.callback.CallbackHandler;
22 import javax.security.auth.callback.UnsupportedCallbackException;
23
24 import org.apache.ws.security.WSPasswordCallback;
25
26 /**
27 * CallbackHandler that sets the password if the callback is an instance of WSPasswordCallback
28 *
29 * @author Kuali Rice Team (rice.collab@kuali.org)
30 */
31
32 public class BasicAuthenticationPasswordHandler implements CallbackHandler {
33
34 private String password;
35
36 /**
37 * Initialize the BasicAuthenticationPasswordHandler with the password
38 *
39 * @param password the password to use
40 */
41 public BasicAuthenticationPasswordHandler(String password) {
42 this.password = password;
43 }
44
45 /**
46 * @param callbacks an array of Callback objects
47 * @see javax.security.auth.callback.CallbackHandler#handle(javax.security.auth.callback.Callback[]
48 */
49 public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
50 if (callbacks[0] != null && callbacks[0] instanceof WSPasswordCallback) {
51 WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
52 pc.setPassword(password);
53 }
54 }
55 }