KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > controllers > kernel > impl > simple > UserControllerProxy


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24
25 package org.infoglue.cms.controllers.kernel.impl.simple;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.Collections JavaDoc;
29 import java.util.List JavaDoc;
30
31 import org.apache.log4j.Logger;
32 import org.exolab.castor.jdo.Database;
33 import org.infoglue.cms.entities.kernel.BaseEntityVO;
34 import org.infoglue.cms.entities.management.SystemUserVO;
35 import org.infoglue.cms.exception.ConstraintException;
36 import org.infoglue.cms.exception.SystemException;
37 import org.infoglue.cms.security.AuthorizationModule;
38 import org.infoglue.cms.security.InfoGlueAuthenticationFilter;
39 import org.infoglue.cms.security.InfoGluePrincipal;
40 import org.infoglue.cms.util.sorters.ReflectionComparator;
41 import org.infoglue.deliver.util.CacheController;
42
43
44 /**
45  * @author Mattias Bogeblad
46  *
47  * This class acts as the proxy for getting the right roles.
48  */

49
50 public class UserControllerProxy extends BaseController
51 {
52     private final static Logger logger = Logger.getLogger(UserControllerProxy.class.getName());
53
54     private AuthorizationModule authorizationModule = null;
55     private Database transactionObject = null;
56     
57     public UserControllerProxy(Database transactionObject)
58     {
59         this.transactionObject = transactionObject;
60     }
61     
62     public static UserControllerProxy getController()
63     {
64         return new UserControllerProxy(null);
65     }
66     
67     public static UserControllerProxy getController(Database transactionObject)
68     {
69         return new UserControllerProxy(transactionObject);
70     }
71     
72     /**
73      * This method instantiates the AuthorizationModule.
74      */

75     
76     private AuthorizationModule getAuthorizationModule() throws SystemException
77     {
78         //if(authorizationModule == null)
79
//{
80
try
81             {
82                 logger.info("InfoGlueAuthenticationFilter.authorizerClass:" + InfoGlueAuthenticationFilter.authorizerClass);
83                 authorizationModule = (AuthorizationModule)Class.forName(InfoGlueAuthenticationFilter.authorizerClass).newInstance();
84                 logger.info("authorizationModule:" + authorizationModule);
85                 authorizationModule.setExtraProperties(InfoGlueAuthenticationFilter.extraProperties);
86                 authorizationModule.setTransactionObject(this.transactionObject);
87                 logger.info("InfoGlueAuthenticationFilter.extraProperties:" + InfoGlueAuthenticationFilter.extraProperties);
88             }
89             catch(Exception JavaDoc e)
90             {
91                 //e.printStackTrace();
92
logger.error("There was an error initializing the authorizerClass:" + e.getMessage(), e);
93                 throw new SystemException("There was an error initializing the authorizerClass:" + e.getMessage(), e);
94             }
95         //}
96

97         return authorizationModule;
98     }
99     
100     /**
101      * This method return whether the module in question supports updates to the values.
102      */

103     
104     public boolean getSupportUpdate() throws ConstraintException, SystemException, Exception JavaDoc
105     {
106         return getAuthorizationModule().getSupportUpdate();
107     }
108
109     /**
110      * This method return whether the module in question supports deletes of users.
111      */

112     
113     public boolean getSupportDelete() throws ConstraintException, SystemException, Exception JavaDoc
114     {
115         return getAuthorizationModule().getSupportDelete();
116     }
117
118     /**
119      * This method return whether the module in question supports creation of new users.
120      */

121     
122     public boolean getSupportCreate() throws ConstraintException, SystemException, Exception JavaDoc
123     {
124         return getAuthorizationModule().getSupportCreate();
125     }
126
127     /**
128      * This method returns a complete list of available users
129      */

130     
131     public List JavaDoc getAllUsers() throws ConstraintException, SystemException, Exception JavaDoc
132     {
133         List JavaDoc users = new ArrayList JavaDoc();
134         
135         users = getAuthorizationModule().getUsers();
136         
137         Collections.sort(users, new ReflectionComparator("name"));
138
139         return users;
140     }
141
142     /**
143      * This method returns a list of all sought for users
144      */

145     
146     public List JavaDoc getFilteredUsers(String JavaDoc firstName, String JavaDoc lastName, String JavaDoc userName, String JavaDoc email, String JavaDoc[] roleNames) throws Exception JavaDoc
147     {
148         List JavaDoc users = new ArrayList JavaDoc();
149         
150         users = getAuthorizationModule().getFilteredUsers(firstName, lastName, userName, email, roleNames);
151         
152         return users;
153     }
154     
155     /**
156      * This method returns a certain user
157      */

158     
159     public InfoGluePrincipal getUser(String JavaDoc userName) throws ConstraintException, SystemException, Exception JavaDoc
160     {
161         //InfoGluePrincipal infoGluePrincipal = null;
162

163         InfoGluePrincipal infoGluePrincipal = (InfoGluePrincipal)CacheController.getCachedObjectFromAdvancedCache("principalCache", userName, 300);
164         if(infoGluePrincipal == null)
165         {
166             infoGluePrincipal = getAuthorizationModule().getAuthorizedInfoGluePrincipal(userName);
167            
168             if(infoGluePrincipal != null)
169                 CacheController.cacheObjectInAdvancedCache("principalCache", userName, infoGluePrincipal, new String JavaDoc[]{}, false);
170                 //CacheController.cacheObject("principalCache", userName, infoGluePrincipal);
171
}
172         
173         //infoGluePrincipal = getAuthorizationModule().getAuthorizedInfoGluePrincipal(userName);
174

175         return infoGluePrincipal;
176     }
177     
178     
179     /**
180      * This method creates a new user
181      */

182     
183     public InfoGluePrincipal createUser(SystemUserVO systemUserVO) throws ConstraintException, SystemException, Exception JavaDoc
184     {
185         InfoGluePrincipal infoGluePrincipal = null;
186         
187         getAuthorizationModule().createInfoGluePrincipal(systemUserVO);
188         
189         return getUser(systemUserVO.getUserName());
190     }
191
192     /**
193      * This method updates an existing user
194      */

195     
196     public void updateUser(SystemUserVO systemUserVO, String JavaDoc[] roleNames, String JavaDoc[] groupNames) throws ConstraintException, SystemException, Exception JavaDoc
197     {
198         getAuthorizationModule().updateInfoGluePrincipal(systemUserVO, roleNames, groupNames);
199     }
200
201     /**
202      * This method makes a new password and sends it to the user
203      */

204     
205     public void updateUserPassword(String JavaDoc userName) throws ConstraintException, SystemException, Exception JavaDoc
206     {
207         getAuthorizationModule().updateInfoGluePrincipalPassword(userName);
208     }
209
210     /**
211      * This method makes a new password and sends it to the user
212      */

213     
214     public void updateUserPassword(String JavaDoc userName, String JavaDoc oldPassword, String JavaDoc newPassword) throws ConstraintException, SystemException, Exception JavaDoc
215     {
216         getAuthorizationModule().updateInfoGluePrincipalPassword(userName, oldPassword, newPassword);
217     }
218
219     /**
220      * This method deletes an existing user
221      */

222     
223     public void deleteUser(String JavaDoc userName) throws ConstraintException, SystemException, Exception JavaDoc
224     {
225         getAuthorizationModule().deleteInfoGluePrincipal(userName);
226     }
227     
228     public BaseEntityVO getNewVO()
229     {
230         return null;
231     }
232  
233 }
234
Popular Tags