KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > outdated > User


1 /*
2  * eAdmin/OWX
3  * Copyright (C) 1996-2003 OWX-Project Team <owx-team@gmx.net>
4  */

5
6 package com.raptus.owxv3.outdated;
7
8 import java.util.Locale JavaDoc;
9
10 import com.raptus.owxv3.*;
11
12
13 /**
14  * Represents a user.
15  *
16  * <hr>
17  * <table width="100%" border="0">
18  * <tr>
19  * <td width="24%"><b>Filename</b></td><td width="76%">User.java</td>
20  * </tr>
21  * <tr>
22  * <td width="24%"><b>Author</b></td><td width="76%">Guy Z�rcher (gzuercher@raptus.com)</td>
23  * </tr>
24  * <tr>
25  * <td width="24%"><b>Date</b></td><td width="76%">15th of April 2001</td>
26  * </tr>
27  * </table>
28  * <hr>
29  * <table width="100%" border="0">
30  * <tr>
31  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
32  * </tr>
33  * </table>
34  * <hr>
35  */

36 public class User extends Object JavaDoc
37 {
38     /**
39      *
40      */

41     public static final int MIN_PASSWORD_LENGTH = 5;
42
43     /**
44      * Users ID
45      */

46     protected String JavaDoc identification;
47
48     /**
49      * Users name (full or not)
50      */

51     protected String JavaDoc displayname;
52
53     /**
54      * Users email address
55      */

56     protected String JavaDoc email;
57
58     /**
59      * Users typed password. Mustn't be the same as <realPassWD>
60      */

61     protected String JavaDoc password;
62
63     /**
64      * Users preferred locale.
65      */

66     protected Locale JavaDoc locale = null;
67
68     /**
69      *
70      */

71     protected String JavaDoc[] vmoduleAccess;
72
73     /**
74      * initialize a configured user
75      *
76      * @param username known/configured user to create
77      * @param password its password
78      */

79     public boolean initialize(String JavaDoc username, String JavaDoc checkpassword)
80     {
81         XMLConfigManager cm = XMLConfigManager.getInstance();
82         Configuration cfg = cm.getConfiguration();
83
84         String JavaDoc pfx = Constants.USER_PREFIX + username;
85         //displayname = cfg.getStringByKey(pfx + Constants.USER_PROPERTY_DISPLAYNAME);
86
//password = cfg.getStringByKey(pfx + Constants.USER_PROPERTY_PASSWORD);
87
//email = cfg.getStringByKey(pfx + Constants.USER_PROPERTY_EMAIL);
88
displayname=cm.getPropertyByTree("virtualhost/users/user?name="+username,"displayname");
89         password=cm.getPropertyByTree("virtualhost/users/user?name="+username,"password");
90         email=cm.getPropertyByTree("virtualhost/users/user?name="+username,"email");
91         //String l = cfg.getStringByKey(pfx + Constants.USER_PROPERTY_LOCALE);
92
String JavaDoc l=cm.getPropertyByTree("virtualhost/users/user?name="+username,"locale");
93
94         if(l != null)
95         {
96             PairOfObjects po = LocaleManager.stripLocaleString(l);
97             if(po != null)
98                 locale = new Locale JavaDoc((String JavaDoc) po.getObjectOne(), (String JavaDoc) po.getObjectTwo());
99         }
100
101         if(displayname != null && password != null && email != null && locale != null)
102         {
103             if(checkPassword(checkpassword))
104             {
105                 //LoggingManager.log("Password check succesful.");
106

107                 //String vmAccessChk = cfg.getStringByKey(pfx + Constants.USER_PROPERTY_ALLOWED_VMODULES);
108
String JavaDoc vmAccessChk = cm.getPropertyByTree("virtualhost/users/user?name="+username,"allowed_vmodules");
109                 if(vmAccessChk != null && vmAccessChk.compareTo("*") == 0) // all vmodules ?
110
vmoduleAccess = cm.getStringArrayByTree("virtualhost/vmodules","items");
111                 else
112                     vmoduleAccess = cm.getStringArrayByTree("virtualhost/users/user?name="+username,"allowed_vmodules");
113
114                 identification = username;
115                 return true;
116             }
117            
118         }
119         else
120             LoggingManager.log("Missing required fields for user configuration (required: " +
121                                "displayname, password, email, locale", this);
122
123         LoggingManager.log("User " + username + " cannot be initialized!", this);
124         return false;
125     }
126
127
128     public String JavaDoc getIdentification() { return identification; }
129     public void setIdentification(String JavaDoc id) { this.identification = id.toLowerCase(); }
130
131     public Locale JavaDoc getLocale() { return locale; }
132     public void setLocale(Locale JavaDoc l) { this.locale = l; }
133
134     public String JavaDoc getDisplayname() { return displayname; }
135     public void setDisplayname(String JavaDoc val) { this.displayname = val; }
136
137     public String JavaDoc getEmail() { return email; }
138     public void setEmail(String JavaDoc val) { this.email = val.toLowerCase(); }
139
140     public String JavaDoc[] getAllowedVModules() { return vmoduleAccess; }
141
142     public boolean checkPassword(String JavaDoc pw) { return password.compareTo(pw) == 0; }
143
144     /**
145      *
146      */

147     public boolean checkAccess(String JavaDoc vmodule)
148     {
149         for(int i = 0; i < vmoduleAccess.length; i ++)
150         {
151             if(vmoduleAccess[i].compareToIgnoreCase(vmodule) == 0)
152                 return true;
153         }
154
155         return false;
156     }
157
158     /**
159      *
160      */

161     public boolean isValid()
162     {
163         return identification != null && identification.length() > 0 &&
164                password != null && password.length() > MIN_PASSWORD_LENGTH;
165     }
166
167 }
168
169 /* end class User */
170
Popular Tags