KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > client > importLdap > SimpleCallbackHandler


1 /**
2  *
3  * Bonita
4  * Copyright (C) 1999 Bull S.A.
5  * Bull 68 route de versailles 78434 Louveciennes Cedex France
6  * Further information: bonita@objectweb.org
7  *
8  * This library is free software; you can redistribute it and/or
9  * 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  */

29
30 package hero.client.importLdap;
31
32 /*
33 *
34 * NodeTests.java -
35 * Copyright (C) 2002 Ecoo Team
36 * valdes@loria.fr
37 *
38 *
39 * This program is free software; you can redistribute it and/or
40 * modify it under the terms of the GNU Lesser General Public License
41 * as published by the Free Software Foundation; either version 2
42 * of the License, or (at your option) any later version.
43 *
44 * This program is distributed in the hope that it will be useful,
45 * but WITHOUT ANY WARRANTY; without even the implied warranty of
46 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47 * GNU Lesser General Public License for more details.
48 *
49 * You should have received a copy of the GNU Lesser General Public License
50 * along with this program; if not, write to the Free Software
51 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
52 */

53
54 import javax.security.auth.callback.Callback JavaDoc;
55 import javax.security.auth.callback.CallbackHandler JavaDoc;
56 import javax.security.auth.callback.NameCallback JavaDoc;
57 import javax.security.auth.callback.PasswordCallback JavaDoc;
58 import javax.security.auth.callback.UnsupportedCallbackException JavaDoc;
59
60
61 public class SimpleCallbackHandler implements CallbackHandler JavaDoc {
62     private String JavaDoc username;
63     private char[] password;
64     
65     public SimpleCallbackHandler(String JavaDoc username, char[] password)
66     {
67     this.username = username;
68     this.password = password;
69     }
70     
71     public void handle(Callback JavaDoc[] callbacks) throws
72     java.io.IOException JavaDoc, UnsupportedCallbackException JavaDoc
73     {
74     for (int i = 0; i < callbacks.length; i++)
75             {
76                 if (callbacks[i] instanceof NameCallback JavaDoc)
77             {
78             NameCallback JavaDoc nc = (NameCallback JavaDoc)callbacks[i];
79             nc.setName(username);
80             }
81                 else if (callbacks[i] instanceof PasswordCallback JavaDoc)
82             {
83             PasswordCallback JavaDoc pc = (PasswordCallback JavaDoc)callbacks[i];
84             pc.setPassword(password);
85             }
86               /* else
87             {
88             throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
89             }*/

90             }
91     }
92 }
93
Popular Tags