KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > db > CmsDefaultUsers


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/db/CmsDefaultUsers.java,v $
3  * Date : $Date: 2006/03/27 14:52:27 $
4  * Version: $Revision: 1.32 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.db;
33
34 import org.opencms.main.CmsLog;
35 import org.opencms.main.CmsRuntimeException;
36 import org.opencms.util.CmsStringUtil;
37
38 /**
39  * Provides access to the names of the OpenCms default users and groups.<p>
40  *
41  * @author Alexander Kandzior
42  * @author Armen Markarian
43  *
44  * @version $Revision: 1.32 $
45  *
46  * @since 6.0.0
47  */

48 public class CmsDefaultUsers {
49
50     /** Default name for the "Administrators" group. */
51     protected static final String JavaDoc DEFAULT_GROUP_ADMINISTRATORS = "Administrators";
52
53     /** Default name for the "Guests" group. */
54     protected static final String JavaDoc DEFAULT_GROUP_GUESTS = "Guests";
55
56     /** Default name for the "Projectmanagers" group. */
57     protected static final String JavaDoc DEFAULT_GROUP_PROJECTMANAGERS = "Projectmanagers";
58
59     /** Default name for the "Users" group. */
60     protected static final String JavaDoc DEFAULT_GROUP_USERS = "Users";
61
62     /** Default name for the "Admin" user. */
63     protected static final String JavaDoc DEFAULT_USER_ADMIN = "Admin";
64
65     /** Default name for the "Deleted Resource" user. */
66     public static final String JavaDoc DEFAULT_USER_DELETED_RESOURCE = "Admin";
67
68     /** Default name for the "Export" user. */
69     protected static final String JavaDoc DEFAULT_USER_EXPORT = "Export";
70
71     /** Default name for the "Guest" user. */
72     protected static final String JavaDoc DEFAULT_USER_GUEST = "Guest";
73
74     /** Administrators group name. */
75     private String JavaDoc m_groupAdministrators;
76
77     /** Guests group name. */
78     private String JavaDoc m_groupGuests;
79
80     /** Project Managers group name. */
81     private String JavaDoc m_groupProjectmanagers;
82
83     /** System Users group name. */
84     private String JavaDoc m_groupUsers;
85
86     /** Administrator user name. */
87     private String JavaDoc m_userAdmin;
88
89     /** Export user name. */
90     private String JavaDoc m_userExport;
91
92     /** Guest user name. */
93     private String JavaDoc m_userGuest;
94
95     /** Deleted resource user name. */
96     private String JavaDoc m_userDeletedResource;
97
98     /**
99      * Constructor that initializes all names with default values.<p>
100      *
101      * See the constants of this class for the defaule values that are uses.<p>
102      */

103     public CmsDefaultUsers() {
104
105         m_userAdmin = DEFAULT_USER_ADMIN;
106         m_userGuest = DEFAULT_USER_GUEST;
107         m_userExport = DEFAULT_USER_EXPORT;
108         m_userDeletedResource = DEFAULT_USER_DELETED_RESOURCE;
109         m_groupAdministrators = DEFAULT_GROUP_ADMINISTRATORS;
110         m_groupProjectmanagers = DEFAULT_GROUP_PROJECTMANAGERS;
111         m_groupUsers = DEFAULT_GROUP_USERS;
112         m_groupGuests = DEFAULT_GROUP_GUESTS;
113     }
114
115     /**
116      * Public constructor. <p>
117      *
118      * @param userAdmin the name of the default admin user
119      * @param userGuest the name of the guest user
120      * @param userExport the name of the export user
121      * @param userDeletedResource the name of the deleted resource user, can be <code>null</code>
122      * @param groupAdministrators the name of the administrators group
123      * @param groupProjectmanagers the name of the project managers group
124      * @param groupUsers the name of the users group
125      * @param groupGuests the name of the guests group
126      */

127     public CmsDefaultUsers(
128         String JavaDoc userAdmin,
129         String JavaDoc userGuest,
130         String JavaDoc userExport,
131         String JavaDoc userDeletedResource,
132         String JavaDoc groupAdministrators,
133         String JavaDoc groupProjectmanagers,
134         String JavaDoc groupUsers,
135         String JavaDoc groupGuests) {
136
137         // check if all required user and group names are not null or empty
138
if (CmsLog.INIT.isInfoEnabled()) {
139             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_CHECKING_DEFAULT_USER_NAMES_0));
140         }
141         if (CmsStringUtil.isEmptyOrWhitespaceOnly(userAdmin)
142             || CmsStringUtil.isEmptyOrWhitespaceOnly(userGuest)
143             || CmsStringUtil.isEmptyOrWhitespaceOnly(userExport)
144             || CmsStringUtil.isEmptyOrWhitespaceOnly(groupAdministrators)
145             || CmsStringUtil.isEmptyOrWhitespaceOnly(groupProjectmanagers)
146             || CmsStringUtil.isEmptyOrWhitespaceOnly(groupUsers)
147             || CmsStringUtil.isEmptyOrWhitespaceOnly(groupGuests)) {
148             throw new CmsRuntimeException(Messages.get().container(Messages.ERR_USER_GROUP_NAMES_EMPTY_0));
149         }
150         // set members
151
m_userAdmin = userAdmin.trim();
152         m_userGuest = userGuest.trim();
153         m_userExport = userExport.trim();
154         if (CmsStringUtil.isEmptyOrWhitespaceOnly(userDeletedResource)) {
155             m_userDeletedResource = userAdmin;
156         } else {
157             m_userDeletedResource = userDeletedResource.trim();
158         }
159         m_groupAdministrators = groupAdministrators.trim();
160         m_groupProjectmanagers = groupProjectmanagers.trim();
161         m_groupUsers = groupUsers.trim();
162         m_groupGuests = groupGuests.trim();
163
164         if (CmsLog.INIT.isInfoEnabled()) {
165             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_ADMIN_USER_1, getUserAdmin()));
166             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_GUEST_USER_1, getUserGuest()));
167             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_EXPORT_USER_1, getUserExport()));
168             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DELETED_RESOURCE_USER_1, getUserDeletedResource()));
169             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_ADMIN_GROUP_1, getGroupAdministrators()));
170             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_PROJECT_MANAGERS_GROUP_1, getGroupProjectmanagers()));
171             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_USERS_GROUP_1, getGroupUsers()));
172             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_GUESTS_GROUP_1, getGroupGuests()));
173             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DEFAULT_USER_NAMES_INITIALIZED_0));
174         }
175     }
176
177     /**
178      * Returns the name of the administrators group.<p>
179      *
180      * @return the name of the administrators group
181      */

182     public String JavaDoc getGroupAdministrators() {
183
184         return m_groupAdministrators;
185     }
186
187     /**
188      * Returns the name of the guests group.<p>
189      *
190      * @return the name of the guests group
191      */

192     public String JavaDoc getGroupGuests() {
193
194         return m_groupGuests;
195     }
196
197     /**
198      * Returns the name of the project managers group.<p>
199      *
200      * @return the name of the project managers group
201      */

202     public String JavaDoc getGroupProjectmanagers() {
203
204         return m_groupProjectmanagers;
205     }
206
207     /**
208      * Returns the name of the users group.<p>
209      *
210      * @return the name of the users group
211      */

212     public String JavaDoc getGroupUsers() {
213
214         return m_groupUsers;
215     }
216
217     /**
218      * Returns the name of the default administrator user.<p>
219      *
220      * @return the name of the default administrator user
221      */

222     public String JavaDoc getUserAdmin() {
223
224         return m_userAdmin;
225     }
226
227     /**
228      * Returns the name of the user used to generate the static export.<p>
229      *
230      * @return the name of the user used to generate the static export
231      */

232     public String JavaDoc getUserExport() {
233
234         return m_userExport;
235     }
236
237     /**
238      * Returns the name of the default guest user.<p>
239      *
240      * @return the name of the default guest user
241      */

242     public String JavaDoc getUserGuest() {
243
244         return m_userGuest;
245     }
246
247     /**
248      * Returns the name of the default deleted resource user.<p>
249      *
250      * @return the name of the default deleted resource user
251      */

252     public String JavaDoc getUserDeletedResource() {
253
254         return m_userDeletedResource;
255     }
256
257     /**
258      * Checks if a given group name is the name of one of the OpenCms default groups.<p>
259      *
260      * @param groupName the group name to check
261      * @return <code>true</code> if group name is one of OpenCms default groups, <code>false</code> if it is not
262      * or if <code>groupName</code> is <code>null</code> or an empty string (no trim)
263      *
264      * @see #getGroupAdministrators()
265      * @see #getGroupProjectmanagers()
266      * @see #getGroupUsers()
267      * @see #getGroupGuests()
268      */

269     public boolean isDefaultGroup(String JavaDoc groupName) {
270
271         if (CmsStringUtil.isEmptyOrWhitespaceOnly(groupName)) {
272             return false;
273         }
274
275         return m_groupAdministrators.equals(groupName)
276             || m_groupProjectmanagers.equals(groupName)
277             || m_groupUsers.equals(groupName)
278             || m_groupGuests.equals(groupName);
279     }
280
281     /**
282      * Checks if a given user name is the name of one of the OpenCms default users.<p>
283      *
284      * @param userName the group name to check
285      *
286      * @return <code>true</code> if user name is one of OpenCms default users, <code>false</code> if it is not
287      * or if <code>userName</code> is <code>null</code> or an empty string (no trim)
288      *
289      * @see #getUserAdmin()
290      * @see #getUserExport()
291      * @see #getUserGuest()
292      * @see #getUserDeletedResource()
293      */

294     public boolean isDefaultUser(String JavaDoc userName) {
295
296         if (CmsStringUtil.isEmptyOrWhitespaceOnly(userName)) {
297             return false;
298         }
299
300         return m_userAdmin.equals(userName)
301             || m_userGuest.equals(userName)
302             || m_userExport.equals(userName)
303             || m_userDeletedResource.equals(userName);
304     }
305 }
Popular Tags