KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > security > auth > realm > file > FileRealmUser


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
25 package com.sun.enterprise.security.auth.realm.file;
26
27 import java.util.*;
28
29 import com.sun.enterprise.deployment.PrincipalImpl;
30 import com.sun.enterprise.security.auth.realm.NoSuchRealmException;
31 import com.sun.enterprise.security.auth.realm.Realm;
32 import com.sun.enterprise.security.auth.realm.User;
33
34
35 /**
36  * Represents a FileRealm user.
37  *
38  *
39  */

40 public class FileRealmUser extends PrincipalImpl implements User
41 {
42     private static final String JavaDoc GROUP_KEY = "Groups"; // not needed
43
private String JavaDoc[] groups;
44     private String JavaDoc realm;
45     private Hashtable attributes;
46
47     private byte[] salt;
48     private byte[] hash;
49     
50     /**
51      * Constructor.
52      *
53      */

54     public FileRealmUser(String JavaDoc name)
55     {
56         super(name);
57         attributes = new Hashtable(1); // not really needed
58
}
59
60
61     /**
62      * Constructor.
63      *
64      * @param name User name.
65      * @param groups Group memerships.
66      * @param realm Realm.
67      * @param salt SSHA salt.
68      * @param hash SSHA password hash.
69      *
70      */

71     public FileRealmUser(String JavaDoc name, String JavaDoc[] groups, String JavaDoc realm,
72                          byte[] salt, byte[] hash)
73     {
74         super(name);
75         this.groups = groups;
76         this.realm = realm;
77         this.hash = hash;
78         this.salt = salt;
79         
80         attributes = new Hashtable(1); // not really needed
81
attributes.put(GROUP_KEY, groups);
82     }
83
84
85     /**
86      * Returns salt value.
87      *
88      */

89     public byte[] getSalt()
90     {
91         return salt;
92     }
93
94
95     /**
96      * Set salt value.
97      *
98      */

99     public void setSalt(byte[] salt)
100     {
101         this.salt = salt;
102     }
103
104
105     /**
106      * Get hash value.
107      *
108      */

109     public byte[] getHash()
110     {
111         return hash;
112     }
113
114
115     /**
116      * Set hash value.
117      *
118      */

119     public void setHash(byte[] hash)
120     {
121         this.hash = hash;
122     }
123
124     
125     /**
126      * Returns the realm with which this user is associated
127      *
128      * @return Realm name.
129      * @exception NoSuchRealmException if the realm associated this user
130      * no longer exist
131      *
132      */

133     public Realm getRealm() throws NoSuchRealmException
134     {
135     return Realm.getInstance(realm);
136     }
137
138
139     /**
140      * Return the names of the groups this user belongs to.
141      *
142      * @return String[] List of group memberships.
143      *
144      */

145     public String JavaDoc[] getGroups()
146     {
147     return groups;
148     }
149
150
151     /**
152      * Set group membership.
153      *
154      */

155     public void setGroups(Vector grp)
156     {
157         String JavaDoc[] g = new String JavaDoc[grp.size()];
158         grp.toArray(g);
159         this.groups = g;
160         attributes.put(GROUP_KEY, groups);
161     }
162
163     
164     /**
165      * Set group membership.
166      *
167      */

168     public void setGroups(String JavaDoc[] grp)
169     {
170         this.groups = grp;
171     }
172
173     
174     /**
175      * Return the requested attribute for the user.
176      * <P>Not really needed.
177      *
178      * @param key string identifies the attribute.
179      */

180     public Object JavaDoc getAttribute (String JavaDoc key)
181     {
182         return attributes.get(key);
183     }
184
185     
186     /**
187      * Return the names of the supported attributes for this user.
188      * <P>Not really needed.
189      */

190     public Enumeration getAttributeNames () {
191     return attributes.keys();
192     }
193
194
195     
196 }
197
Popular Tags