KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > security > LoginContext


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 package com.sun.enterprise.security;
24
25 import java.security.AccessController JavaDoc;
26 import java.security.PrivilegedAction JavaDoc;
27
28 import com.sun.enterprise.security.auth.login.ClientPasswordLoginModule;
29 import com.sun.enterprise.security.auth.LoginContextDriver;
30 import com.sun.enterprise.appclient.AppContainer;
31 import com.sun.enterprise.util.LocalStringManagerImpl;
32 import java.util.logging.*;
33 import com.sun.logging.*;
34
35 /**
36  * This class is kept for CTS. Ideally we should move away from it.
37  * The login can be done via the following call:
38  * <pre>
39  * // Initialize the ORB.
40  * try {
41  * LoginContext lc = new LoginContext();
42  * lc.login("john", "john123");
43  * } catch (LoginException le) {
44  * le.printStackTrace();
45  * }
46  *
47  *
48  * </PRE>
49  *
50  * Ideally the login should be done with the system property -Dj2eelogin.name and -Dj2eelogin.password
51  *
52  * @author Harpreet Singh (hsingh@eng.sun.com)
53  */

54
55 public final class LoginContext {
56     private static Logger _logger=null;
57     static{
58        _logger = LogDomains.getLogger(LogDomains.SECURITY_LOGGER);
59    }
60
61     private boolean guiAuth = false;
62
63     // declaring this different from the Appcontainer as
64
// this will be called from standalone clients.
65
public javax.security.auth.callback.CallbackHandler JavaDoc handler = null;
66     
67     /**
68      * Creates the LoginContext with the defauly callback handler
69      */

70     public LoginContext () {
71     handler = new com.sun.enterprise.security.auth.login.LoginCallbackHandler(guiAuth);
72     }
73     
74     /**
75      * Login method to login username and password
76      */

77     public void login(String JavaDoc user, String JavaDoc pass) throws LoginException{
78     final String JavaDoc username = user;
79     final String JavaDoc password = pass;
80     AccessController.doPrivileged(new PrivilegedAction JavaDoc() {
81         public java.lang.Object JavaDoc run() {
82         
83         System.setProperty(ClientPasswordLoginModule.LOGIN_NAME,
84                    username);
85         System.setProperty(ClientPasswordLoginModule.LOGIN_PASSWORD,
86                    password);
87
88             return null;
89         }
90         });
91     // Since this is a private api and the user is not supposed to use
92
// this. We use the default the LoginCallbackHandler.
93
LoginContextDriver.doClientLogin(AppContainer.USERNAME_PASSWORD,
94                      handler);
95     }
96     
97     /** This method has been provided to satisfy the CTS Porting Package
98      * requirement for logging in a certificate
99      */

100     public void login(String JavaDoc username, byte[] authData)
101     throws LoginException{
102     
103         // do nothing
104
}
105
106 }
107
108
109
110
Popular Tags