01: /**
02: * Copyright 2004-2005 jManage.org
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: */package org.jmanage.core.auth;
16:
17: import javax.security.auth.callback.*;
18: import java.io.IOException;
19:
20: /**
21: * Date : Jun 27, 2004 1:34:02 PM
22: * @author Shashank
23: */
24: public class LoginCallbackHandler implements CallbackHandler {
25: private String username;
26: private String password;
27:
28: public LoginCallbackHandler(String username, String password) {
29: this .username = username;
30: this .password = password;
31: }
32:
33: public String getUsername() {
34: return username;
35: }
36:
37: public String getPassword() {
38: return password;
39: }
40:
41: /**
42: *
43: * @param callbacks
44: * @throws IOException
45: * @throws UnsupportedCallbackException
46: */
47: public void handle(Callback[] callbacks) throws IOException,
48: UnsupportedCallbackException {
49:
50: for (int i = 0; i < callbacks.length; i++) {
51: if (callbacks[i] instanceof NameCallback) {
52: NameCallback nc = (NameCallback) callbacks[i];
53: nc.setName(username);
54: } else if (callbacks[i] instanceof PasswordCallback) {
55: PasswordCallback pc = (PasswordCallback) callbacks[i];
56: pc.setPassword(password.toCharArray());
57: } else {
58: throw (new UnsupportedCallbackException(callbacks[i],
59: "Callback handler not supported"));
60: }
61: }
62: }
63: }
|