KickJava   Java API By Example, From Geeks To Geeks.

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


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.exolab.castor.jdo.Database;
32 import org.infoglue.cms.entities.kernel.BaseEntityVO;
33 import org.infoglue.cms.entities.management.RoleVO;
34 import org.infoglue.cms.exception.ConstraintException;
35 import org.infoglue.cms.exception.SystemException;
36 import org.infoglue.cms.security.AuthorizationModule;
37 import org.infoglue.cms.security.InfoGlueAuthenticationFilter;
38 import org.infoglue.cms.security.InfoGlueRole;
39 import org.infoglue.cms.util.sorters.ReflectionComparator;
40
41 /**
42  * @author Mattias Bogeblad
43  *
44  * This class acts as the proxy for getting the right roles.
45  */

46
47 public class RoleControllerProxy extends BaseController
48 {
49     private AuthorizationModule authorizationModule = null;
50     private Database transactionObject = null;
51
52     public RoleControllerProxy(Database transactionObject)
53     {
54         this.transactionObject = transactionObject;
55     }
56
57     public static RoleControllerProxy getController()
58     {
59         return new RoleControllerProxy(null);
60     }
61     
62     public static RoleControllerProxy getController(Database transactionObject)
63     {
64         return new RoleControllerProxy(transactionObject);
65     }
66
67     /**
68      * This method instantiates the AuthorizationModule.
69      */

70     
71     private AuthorizationModule getAuthorizationModule()
72     {
73         //if(authorizationModule == null)
74
//{
75
try
76             {
77                 authorizationModule = (AuthorizationModule)Class.forName(InfoGlueAuthenticationFilter.authorizerClass).newInstance();
78                 authorizationModule.setExtraProperties(InfoGlueAuthenticationFilter.extraProperties);
79                 authorizationModule.setTransactionObject(this.transactionObject);
80             }
81             catch(Exception JavaDoc e)
82             {
83                 e.printStackTrace();
84             }
85         //}
86

87         return authorizationModule;
88     }
89
90     /**
91      * This method return whether the module in question supports updates to the values.
92      */

93     
94     public boolean getSupportUpdate() throws ConstraintException, SystemException, Exception JavaDoc
95     {
96         return getAuthorizationModule().getSupportUpdate();
97     }
98
99     /**
100      * This method return whether the module in question supports deletes of users.
101      */

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

111     
112     public boolean getSupportCreate() throws ConstraintException, SystemException, Exception JavaDoc
113     {
114         return getAuthorizationModule().getSupportCreate();
115     }
116
117     /**
118      * This method returns a specific content-object
119      */

120     
121     public List JavaDoc getAllRoles() throws ConstraintException, SystemException, Exception JavaDoc
122     {
123         List JavaDoc roles = new ArrayList JavaDoc();
124         
125         roles = getAuthorizationModule().getRoles();
126         Collections.sort(roles, new ReflectionComparator("name"));
127         
128         return roles;
129     }
130
131     /**
132      * This method returns a certain role
133      */

134     
135     public InfoGlueRole getRole(String JavaDoc roleName) throws ConstraintException, SystemException, Exception JavaDoc
136     {
137         InfoGlueRole infoGlueRole = null;
138         
139         infoGlueRole = getAuthorizationModule().getAuthorizedInfoGlueRole(roleName);
140         
141         return infoGlueRole;
142     }
143
144     /**
145      * This method returns a list of InfoGlue Principals which are part of this role
146      */

147     
148     public List JavaDoc getInfoGluePrincipals(String JavaDoc roleName) throws ConstraintException, SystemException, Exception JavaDoc
149     {
150         List JavaDoc infoGluePrincipals = new ArrayList JavaDoc();
151         
152         infoGluePrincipals = getAuthorizationModule().getUsers(roleName);
153         Collections.sort(infoGluePrincipals, new ReflectionComparator("name"));
154         
155         return infoGluePrincipals;
156     }
157     
158     
159     /**
160      * This method creates a new role
161      */

162     
163     public InfoGlueRole createRole(RoleVO roleVO) throws ConstraintException, SystemException, Exception JavaDoc
164     {
165         InfoGlueRole infoGlueRole = null;
166         
167         getAuthorizationModule().createInfoGlueRole(roleVO);
168         
169         return getRole(roleVO.getRoleName());
170     }
171
172     /**
173      * This method updates an existing role
174      */

175     
176     public void updateRole(RoleVO roleVO, String JavaDoc[] userNames) throws ConstraintException, SystemException, Exception JavaDoc
177     {
178         getAuthorizationModule().updateInfoGlueRole(roleVO, userNames);
179     }
180
181     /**
182      * This method deletes an existing user
183      */

184     
185     public void deleteRole(String JavaDoc roleName) throws ConstraintException, SystemException, Exception JavaDoc
186     {
187         getAuthorizationModule().deleteInfoGlueRole(roleName);
188         AccessRightController.getController().delete(roleName);
189     }
190     
191     public BaseEntityVO getNewVO()
192     {
193         return null;
194     }
195  
196 }
197
Popular Tags