KickJava   Java API By Example, From Geeks To Geeks.

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


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.GroupVO;
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.InfoGlueGroup;
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 groups.
45  */

46
47 public class GroupControllerProxy extends BaseController
48 {
49     private AuthorizationModule authorizationModule = null;
50     private Database transactionObject = null;
51
52     public GroupControllerProxy(Database transactionObject)
53     {
54         this.transactionObject = transactionObject;
55     }
56
57     public static GroupControllerProxy getController()
58     {
59         return new GroupControllerProxy(null);
60     }
61
62     public static GroupControllerProxy getController(Database transactionObject)
63     {
64         return new GroupControllerProxy(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 getAllGroups() throws ConstraintException, SystemException, Exception JavaDoc
122     {
123         List JavaDoc groups = new ArrayList JavaDoc();
124         
125         groups = getAuthorizationModule().getGroups();
126         Collections.sort(groups, new ReflectionComparator("name"));
127
128         return groups;
129     }
130
131     /**
132      * This method returns a certain group
133      */

134     
135     public InfoGlueGroup getGroup(String JavaDoc groupName) throws ConstraintException, SystemException, Exception JavaDoc
136     {
137         InfoGlueGroup infoGlueGroup = null;
138         
139         infoGlueGroup = getAuthorizationModule().getAuthorizedInfoGlueGroup(groupName);
140         
141         return infoGlueGroup;
142     }
143
144     /**
145      * This method returns a list of InfoGlue Principals which are part of this group
146      */

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

162     
163     public InfoGlueGroup createGroup(GroupVO groupVO) throws ConstraintException, SystemException, Exception JavaDoc
164     {
165         InfoGlueGroup infoGlueGroup = null;
166         
167         getAuthorizationModule().createInfoGlueGroup(groupVO);
168         
169         return getGroup(groupVO.getGroupName());
170     }
171
172     /**
173      * This method updates an existing group
174      */

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

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