KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > ac > impl > AbstractUser


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 package org.apache.lenya.ac.impl;
19
20 import org.apache.lenya.ac.AccessControlException;
21 import org.apache.lenya.ac.Password;
22 import org.apache.lenya.ac.User;
23 import org.apache.log4j.Category;
24
25 /**
26  * Abstract user implementation.
27  * @version $Id: AbstractUser.java 43241 2004-08-16 16:36:57Z andreas $
28  */

29 public abstract class AbstractUser extends AbstractGroupable implements User {
30
31     private static Category log = Category.getInstance(AbstractUser.class);
32     private String JavaDoc email;
33     private String JavaDoc encryptedPassword;
34     
35     /**
36      * Creates a new User.
37      */

38     public AbstractUser() {
39     }
40
41     /**
42          * Create a User instance
43          *
44          * @param id the user id
45          * @param fullName the full name of the user
46          * @param email the users email address
47          * @param password the users password
48          */

49     public AbstractUser(String JavaDoc id, String JavaDoc fullName, String JavaDoc email, String JavaDoc password) {
50         setId(id);
51         setName(fullName);
52         this.email = email;
53         setPassword(password);
54     }
55
56     /**
57      * Get the email address
58      *
59      * @return a <code>String</code>
60      */

61     public String JavaDoc getEmail() {
62         return email;
63     }
64
65     /**
66      * Get the full name
67      *
68      * @return a <code>String</code>
69      * @deprecated has been superceded by getName()
70      */

71     public String JavaDoc getFullName() {
72         return getName();
73     }
74
75     /**
76      * Set the email address
77      *
78      * @param email the new email address
79      */

80     public void setEmail(String JavaDoc email) {
81         this.email = email;
82     }
83
84     /**
85      * Set the full name
86      *
87      * @param name the new full name
88      * @deprecated has been superceded by setName(String)
89      */

90     public void setFullName(String JavaDoc name) {
91         setName(name);
92     }
93
94     /**
95     * Sets the password.
96      * @param plainTextPassword The plain text passwrod.
97      */

98     public void setPassword(String JavaDoc plainTextPassword) {
99         encryptedPassword = Password.encrypt(plainTextPassword);
100     }
101
102     /**
103      * This method can be used for subclasses to set the password without it
104      * being encrypted again. Some subclass might have knowledge of the encrypted
105      * password and needs to be able to set it.
106      *
107      * @param encryptedPassword the encrypted password
108      */

109     protected void setEncryptedPassword(String JavaDoc encryptedPassword) {
110         this.encryptedPassword = encryptedPassword;
111     }
112
113     /**
114      * Get the encrypted password
115      *
116      * @return the encrypted password
117      */

118     protected String JavaDoc getEncryptedPassword() {
119         return encryptedPassword;
120     }
121
122     /**
123      * Save the user
124      *
125      * @throws AccessControlException if the save failed
126      */

127     public abstract void save() throws AccessControlException;
128
129     /**
130      * Delete a user
131      *
132      * @throws AccessControlException if the delete failed
133      */

134     public void delete() throws AccessControlException {
135         removeFromAllGroups();
136     }
137
138     /**
139      * Authenticate a user. This is done by encrypting
140      * the given password and comparing this to the
141      * encryptedPassword.
142      *
143      * @param password to authenticate with
144      * @return true if the given password matches the password for this user
145      */

146     public boolean authenticate(String JavaDoc password) {
147         log.debug("Password: " + password);
148         log.debug("pw encypted: " + Password.encrypt(password));
149         log.debug("orig encrypted pw: " + this.encryptedPassword);
150
151         return this.encryptedPassword.equals(Password.encrypt(password));
152     }
153     
154 }
155
Popular Tags