01: /**
02: *
03: * Bonita
04: * Copyright (C) 1999 Bull S.A.
05: * Bull 68 route de versailles 78434 Louveciennes Cedex France
06: * Further information: bonita@objectweb.org
07: *
08: * This library is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU Lesser General Public
10: * License as published by the Free Software Foundation; either
11: * version 2.1 of the License, or any later version.
12: *
13: * This library is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16: * Lesser General Public License for more details.
17: *
18: * You should have received a copy of the GNU Lesser General Public
19: * License along with this library; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21: * USA
22: *
23: *
24: --------------------------------------------------------------------------
25: * $Id: SimpleCallbackHandler.java,v 1.1 2004/07/30 14:57:58 mvaldes Exp $
26: *
27: --------------------------------------------------------------------------
28: */package hero.client.importLdap;
29:
30: /*
31: *
32: * NodeTests.java -
33: * Copyright (C) 2002 Ecoo Team
34: * valdes@loria.fr
35: *
36: *
37: * This program is free software; you can redistribute it and/or
38: * modify it under the terms of the GNU Lesser General Public License
39: * as published by the Free Software Foundation; either version 2
40: * of the License, or (at your option) any later version.
41: *
42: * This program is distributed in the hope that it will be useful,
43: * but WITHOUT ANY WARRANTY; without even the implied warranty of
44: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45: * GNU Lesser General Public License for more details.
46: *
47: * You should have received a copy of the GNU Lesser General Public License
48: * along with this program; if not, write to the Free Software
49: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
50: */
51:
52: import javax.security.auth.callback.Callback;
53: import javax.security.auth.callback.CallbackHandler;
54: import javax.security.auth.callback.NameCallback;
55: import javax.security.auth.callback.PasswordCallback;
56: import javax.security.auth.callback.UnsupportedCallbackException;
57:
58: public class SimpleCallbackHandler implements CallbackHandler {
59: private String username;
60: private char[] password;
61:
62: public SimpleCallbackHandler(String username, char[] password) {
63: this .username = username;
64: this .password = password;
65: }
66:
67: public void handle(Callback[] callbacks)
68: throws java.io.IOException, UnsupportedCallbackException {
69: for (int i = 0; i < callbacks.length; i++) {
70: if (callbacks[i] instanceof NameCallback) {
71: NameCallback nc = (NameCallback) callbacks[i];
72: nc.setName(username);
73: } else if (callbacks[i] instanceof PasswordCallback) {
74: PasswordCallback pc = (PasswordCallback) callbacks[i];
75: pc.setPassword(password);
76: }
77: /* else
78: {
79: throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
80: }*/
81: }
82: }
83: }
|