KickJava   Java API By Example, From Geeks To Geeks.

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


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
28 import java.util.logging.Logger JavaDoc;
29 import java.util.logging.Level JavaDoc;
30 import com.sun.logging.LogDomains;
31
32 import javax.security.auth.*;
33 import javax.security.auth.callback.*;
34 import javax.security.auth.login.*;
35 import javax.security.auth.spi.*;
36
37 import com.sun.enterprise.security.auth.realm.solaris.SolarisRealm;
38
39 // limit RI imports
40
import com.sun.enterprise.security.auth.Privilege;
41 import com.sun.enterprise.security.auth.PrivilegeImpl;
42
43 import com.sun.enterprise.security.auth.realm.Realm;
44 import com.sun.enterprise.security.auth.login.PasswordCredential;
45 import javax.security.auth.login.LoginException JavaDoc;
46
47 /**
48  * Solaris realm login module.
49  *
50  * <P>Processing is delegated to the SolarisRealm class which accesses
51  * the native methods.
52  *
53  * @see com.sun.enterprise.security.auth.login.PasswordLoginModule
54  * @see com.sun.enterprise.security.auth.realm.solaris.SolarisRealm
55  *
56  */

57 public class SolarisLoginModule extends PasswordLoginModule
58 {
59
60     /**
61      * Perform solaris authentication. Delegates to SolarisRealm.
62      *
63      * @throws LoginException If login fails (JAAS login() behavior).
64      *
65      */

66     protected void authenticate()
67         throws LoginException JavaDoc
68     {
69         if (!(_currentRealm instanceof SolarisRealm)) {
70             String JavaDoc msg = sm.getString("solarislm.badrealm");
71             throw new LoginException JavaDoc(msg);
72         }
73         
74         SolarisRealm solarisRealm = (SolarisRealm)_currentRealm;
75
76         // A solaris user must have a name not null so check here.
77
if ( (_username == null) || (_username.length() == 0) ) {
78             String JavaDoc msg = sm.getString("solarislm.nulluser");
79             throw new LoginException JavaDoc(msg);
80         }
81         
82         String JavaDoc[] grpList = solarisRealm.authenticate(_username, _password);
83
84         if (grpList == null) { // JAAS behavior
85
String JavaDoc msg = sm.getString("solarislm.loginfail", _username);
86             throw new LoginException JavaDoc(msg);
87         }
88
89         _logger.finest("Solaris login succeeded for: " + _username);
90
91         //make a copy of groupList to pass to LoginModule. This copy is the one
92
// that will be made null there. DO NOT PASS the grpList as is - as
93
// it will get overwritten. Resulting in logins passing only once.
94
String JavaDoc[] groupListToForward = new String JavaDoc[grpList.length];
95         for (int i = 0; i< grpList.length; i++){
96             groupListToForward[i] = grpList[i];
97         }
98
99         commitAuthentication(_username, _password,
100                              _currentRealm, groupListToForward);
101         solarisRealm.setGroupNames(_username, groupListToForward);
102     }
103
104 }
105
Popular Tags