KickJava   Java API By Example, From Geeks To Geeks.

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


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
32 import com.sun.enterprise.util.LocalStringManagerImpl;
33 import com.sun.enterprise.security.TextLoginDialog;
34 import com.sun.enterprise.security.GUILoginDialog;
35
36 /**
37  * This is the default callback handler provided by the application
38  * client container. The container tries to use the application specified
39  * callback handler (if provided). If there is no callback handler or if
40  * the handler cannot be instantiated then this default handler is used.
41  */

42 public class LoginCallbackHandler implements CallbackHandler
43 {
44     private boolean isGUI;
45     private static LocalStringManagerImpl localStrings =
46     new LocalStringManagerImpl(LoginCallbackHandler.class);
47
48     public LoginCallbackHandler() {
49         this(true);
50     }
51
52     public LoginCallbackHandler(boolean gui) {
53         isGUI = gui;
54     }
55
56     /**
57      * This is the callback method called when authentication data is
58      * required. It either pops up a dialog box to request authentication
59      * data or use text input.
60      * @param the callback object instances supported by the login module.
61      */

62     public void handle(Callback[] callbacks) throws IOException,
63                     UnsupportedCallbackException
64     {
65         if(isGUI) {
66             String JavaDoc user = localStrings.getLocalString("login.user", "user");
67         GUILoginDialog gd = new GUILoginDialog(user, callbacks);
68     } else {
69         TextLoginDialog td = new TextLoginDialog(callbacks);
70         }
71     }
72 }
73
74
Popular Tags