KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > security > auth > login > ServerLoginCallbackHandler


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.security.auth.login;
25
26 import java.util.*;
27 import java.io.*;
28 import javax.security.auth.*;
29 import javax.security.auth.callback.*;
30 import javax.security.auth.login.*;
31 import java.util.logging.*;
32 import com.sun.logging.*;
33
34
35 /**
36  * This is the default callback handler provided by the application
37  * client container. The container tries to use the application specified
38  * callback handler (if provided). If there is no callback handler or if
39  * the handler cannot be instantiated then this default handler is used.
40  */

41 public class ServerLoginCallbackHandler implements CallbackHandler
42 {
43     String JavaDoc username = null;
44     String JavaDoc password = null;
45
46     public ServerLoginCallbackHandler(String JavaDoc username, String JavaDoc password) {
47     this.username = username;
48     this.password = password;
49     }
50     
51     public ServerLoginCallbackHandler(){
52     username = null;
53     password = null;
54     }
55     
56     public void setUsername(String JavaDoc user){
57     username = user;
58     }
59     
60     public void setPassword(String JavaDoc pass){
61     password = pass;
62     }
63
64     
65     /**
66      * This is the callback method called when authentication data is
67      * required. It either pops up a dialog box to request authentication
68      * data or use text input.
69      * @param the callback object instances supported by the login module.
70      */

71     public void handle(Callback[] callbacks) throws IOException,
72                     UnsupportedCallbackException
73     {
74     for (int i = 0; i < callbacks.length; i++) {
75             if (callbacks[i] instanceof NameCallback){
76         NameCallback nme = (NameCallback)callbacks[i];
77         nme.setName(username);
78         } else if (callbacks[i] instanceof PasswordCallback){
79         PasswordCallback pswd = (PasswordCallback)callbacks[i];
80         pswd.setPassword(password.toCharArray());
81         }
82     }
83     }
84 }
85
86
Popular Tags