KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.logging.Level JavaDoc;
28 import javax.security.auth.*;
29 import javax.security.auth.callback.*;
30 import javax.security.auth.login.*;
31 import javax.security.auth.spi.*;
32 import com.sun.enterprise.security.auth.realm.file.FileRealm;
33 import javax.security.auth.login.LoginException JavaDoc;
34
35 /**
36  * File realm login module.
37  *
38  * <P>Provides a file-based implementation of a password login module.
39  * Processing is delegated to the FileRealm class.
40  *
41  * @see com.sun.enterprise.security.auth.login.PasswordLoginModule
42  * @see com.sun.enterprise.security.auth.realm.file.FileRealm
43  *
44  */

45 public class FileLoginModule extends PasswordLoginModule
46 {
47
48     /**
49      * Perform file authentication. Delegates to FileRealm.
50      *
51      * @throws LoginException If login fails (JAAS login() behavior).
52      *
53      */

54     protected void authenticate()
55         throws LoginException JavaDoc
56     {
57         if (!(_currentRealm instanceof FileRealm)) {
58             String JavaDoc msg = sm.getString("filelm.badrealm");
59             throw new LoginException JavaDoc(msg);
60         }
61         FileRealm fileRealm = (FileRealm)_currentRealm;
62
63         String JavaDoc[] grpList = fileRealm.authenticate(_username, _password);
64
65         if (grpList == null) { // JAAS behavior
66
String JavaDoc msg = sm.getString("filelm.faillogin", _username);
67             throw new LoginException JavaDoc(msg);
68         }
69
70         if (_logger.isLoggable(Level.FINE)) {
71             _logger.log(Level.FINE, "File login succeeded for: " + _username);
72         }
73         //make a copy of groupList to pass to LoginModule. This copy is the one
74
// that will be made null there. DO NOT PASS the grpList as is - as
75
// it will get overwritten. Resulting in logins passing only once.
76
String JavaDoc[] groupListToForward = new String JavaDoc[grpList.length];
77         for (int i = 0; i< grpList.length; i++){
78             groupListToForward[i] = grpList[i];
79         }
80         commitAuthentication(_username, _password,
81                              _currentRealm, groupListToForward);
82     }
83 }
84
Popular Tags