01: package hero.client.test;
02:
03: /*
04: *
05: * NodeTests.java -
06: * Copyright (C) 2002 Ecoo Team
07: * valdes@loria.fr
08: *
09: *
10: * This program is free software; you can redistribute it and/or
11: * modify it under the terms of the GNU Lesser General Public License
12: * as published by the Free Software Foundation; either version 2
13: * of the License, or (at your option) any later version.
14: *
15: * This program is distributed in the hope that it will be useful,
16: * but WITHOUT ANY WARRANTY; without even the implied warranty of
17: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: * GNU Lesser General Public License for more details.
19: *
20: * You should have received a copy of the GNU Lesser General Public License
21: * along with this program; if not, write to the Free Software
22: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23: */
24:
25: import javax.security.auth.callback.Callback;
26: import javax.security.auth.callback.CallbackHandler;
27: import javax.security.auth.callback.NameCallback;
28: import javax.security.auth.callback.PasswordCallback;
29: import javax.security.auth.callback.UnsupportedCallbackException;
30:
31: public class SimpleCallbackHandler implements CallbackHandler {
32: private String username;
33: private char[] password;
34:
35: public SimpleCallbackHandler(String username, char[] password) {
36: this .username = username;
37: this .password = password;
38: }
39:
40: public void handle(Callback[] callbacks)
41: throws java.io.IOException, UnsupportedCallbackException {
42: for (int i = 0; i < callbacks.length; i++) {
43: if (callbacks[i] instanceof NameCallback) {
44: NameCallback nc = (NameCallback) callbacks[i];
45: nc.setName(username);
46: } else if (callbacks[i] instanceof PasswordCallback) {
47: PasswordCallback pc = (PasswordCallback) callbacks[i];
48: pc.setPassword(password);
49: }
50: /* else
51: {
52: throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
53: }*/
54: }
55: }
56: }
|