KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > contenttool > actions > ViewAccessRightsAction


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 package org.infoglue.cms.applications.contenttool.actions;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.apache.log4j.Logger;
31 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
32 import org.infoglue.cms.controllers.kernel.impl.simple.AccessRightController;
33 import org.infoglue.cms.controllers.kernel.impl.simple.ContentControllerProxy;
34 import org.infoglue.cms.controllers.kernel.impl.simple.GroupControllerProxy;
35 import org.infoglue.cms.controllers.kernel.impl.simple.InterceptionPointController;
36 import org.infoglue.cms.controllers.kernel.impl.simple.RoleControllerProxy;
37 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeVersionController;
38 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeVersionControllerProxy;
39 import org.infoglue.cms.entities.content.ContentVO;
40 import org.infoglue.cms.entities.management.AccessRightVO;
41 import org.infoglue.cms.entities.structure.SiteNodeVersionVO;
42 import org.infoglue.cms.exception.AccessConstraintException;
43 import org.infoglue.cms.exception.Bug;
44 import org.infoglue.cms.exception.SystemException;
45 import org.infoglue.cms.util.AccessConstraintExceptionBuffer;
46
47
48 /**
49  * This class shows which roles has access to the siteNode.
50  */

51
52 public class ViewAccessRightsAction extends InfoGlueAbstractAction
53 {
54     private final static Logger logger = Logger.getLogger(ViewAccessRightsAction.class.getName());
55
56     private static final long serialVersionUID = 1L;
57     
58     private Integer JavaDoc interceptionPointId = null;
59     private String JavaDoc interceptionPointName = null;
60     private String JavaDoc interceptionPointCategory = null;
61     private String JavaDoc extraParameters = "";
62     private String JavaDoc returnAddress;
63     private String JavaDoc colorScheme;
64
65     private List JavaDoc interceptionPointVOList = new ArrayList JavaDoc();
66     private List JavaDoc roleList = null;
67     private List JavaDoc groupList = null;
68     private Collection JavaDoc accessRightsUserRows = null;
69     
70     public String JavaDoc doExecute() throws Exception JavaDoc
71     {
72         AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer();
73         
74         if(interceptionPointCategory.equalsIgnoreCase("Content"))
75         {
76             if(extraParameters == null || extraParameters.equals(""))
77                 throw new SystemException("The content category must have a content id sent in so don't set 'Use extra data for access control' to no for those interception points.");
78                 
79             Integer JavaDoc contentId = new Integer JavaDoc(extraParameters);
80             ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId);
81             if(!contentVO.getCreatorName().equalsIgnoreCase(this.getInfoGluePrincipal().getName()))
82             {
83                 Integer JavaDoc protectedContentId = ContentControllerProxy.getController().getProtectedContentId(contentId);
84                 if(ContentControllerProxy.getController().getIsContentProtected(contentId) && !AccessRightController.getController().getIsPrincipalAuthorized(this.getInfoGluePrincipal(), "Content.ChangeAccessRights", contentId.toString()))
85                     ceb.add(new AccessConstraintException("Content.contentId", "1006"));
86             }
87         }
88         else if(interceptionPointCategory.equalsIgnoreCase("SiteNodeVersion"))
89         {
90             if(extraParameters == null || extraParameters.equals(""))
91                 throw new SystemException("The sitenode category must have a sitenode id sent in so don't set 'Use extra data for access control' to no for those interception points.");
92
93             Integer JavaDoc siteNodeVersionId = new Integer JavaDoc(extraParameters);
94             SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(siteNodeVersionId);
95             if(!siteNodeVersionVO.getVersionModifier().equalsIgnoreCase(this.getInfoGluePrincipal().getName()))
96             {
97                 Integer JavaDoc protectedSiteNodeVersionId = SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy().getProtectedSiteNodeVersionId(siteNodeVersionId);
98                 if(protectedSiteNodeVersionId != null && !AccessRightController.getController().getIsPrincipalAuthorized(this.getInfoGluePrincipal(), "SiteNodeVersion.ChangeAccessRights", siteNodeVersionId.toString()))
99                     ceb.add(new AccessConstraintException("SiteNodeVersion.siteNodeId", "1006"));
100             }
101         }
102         
103         ceb.throwIfNotEmpty();
104         
105         this.interceptionPointVOList = InterceptionPointController.getController().getInterceptionPointVOList(interceptionPointCategory);
106         //this.roleVOList = RoleController.getController().getRoleVOList();
107
this.roleList = RoleControllerProxy.getController().getAllRoles();
108         this.groupList = GroupControllerProxy.getController().getAllGroups();
109         //this.accessRightVOList = AccessRightController.getController().getAccessRightVOList(this.interceptionPointId, extraParameters);
110

111         //this.extranetRoleVOList = ExtranetRoleController.getController().getExtranetRoleVOList();
112
//this.extranetAccessVOList = ExtranetAccessController.getController().getExtranetAccessVOList(this.name, this.value);
113
this.accessRightsUserRows = AccessRightController.getController().getAccessRightsUserRows(interceptionPointCategory, extraParameters);
114         
115         return "success";
116     }
117     
118     public boolean getHasAccessRight(Integer JavaDoc interceptionPointId, String JavaDoc extraParameters, String JavaDoc roleName) throws SystemException, Bug
119     {
120         try
121         {
122             List JavaDoc accessRights = AccessRightController.getController().getAccessRightVOList(interceptionPointId, extraParameters, roleName);
123             boolean hasAccessRight = (accessRights.size() > 0) ? true : false;
124             return hasAccessRight;
125         }
126         catch(Exception JavaDoc e)
127         {
128             logger.warn(e);
129             throw new SystemException(e);
130         }
131     }
132     
133     public Integer JavaDoc getAccessRightId(Integer JavaDoc interceptionPointId, String JavaDoc extraParameters) throws SystemException, Bug
134     {
135         List JavaDoc accessRights = AccessRightController.getController().getAccessRightVOListOnly(interceptionPointId, extraParameters);
136         return accessRights.size() > 0 ? ((AccessRightVO)accessRights.get(0)).getAccessRightId() : null;
137     }
138     
139     public Collection JavaDoc getAccessRightGroups(Integer JavaDoc accessRightId) throws SystemException, Bug
140     {
141         Collection JavaDoc accessRightGroups = AccessRightController.getController().getAccessRightGroupVOList(accessRightId);
142         return accessRightGroups;
143     }
144         
145     public List JavaDoc getRoleList()
146     {
147         return this.roleList;
148     }
149     
150     public List JavaDoc getGroupList()
151     {
152         return this.groupList;
153     }
154
155     public String JavaDoc getReturnAddress()
156     {
157         return returnAddress;
158     }
159
160     public void setReturnAddress(String JavaDoc returnAddress)
161     {
162         this.returnAddress = returnAddress;
163     }
164
165     public String JavaDoc getColorScheme()
166     {
167         return this.colorScheme;
168     }
169
170     public void setColorScheme(String JavaDoc colorScheme)
171     {
172         this.colorScheme = colorScheme;
173     }
174
175     public Integer JavaDoc getInterceptionPointId()
176     {
177         return this.interceptionPointId;
178     }
179
180     public void setInterceptionPointId(Integer JavaDoc interceptionPointId)
181     {
182         this.interceptionPointId = interceptionPointId;
183     }
184
185     public String JavaDoc getExtraParameters()
186     {
187         return this.extraParameters;
188     }
189
190     public String JavaDoc getInterceptionPointName()
191     {
192         return this.interceptionPointName;
193     }
194
195     public void setExtraParameters(String JavaDoc extraParameters)
196     {
197         this.extraParameters = extraParameters;
198     }
199
200     public void setInterceptionPointName(String JavaDoc interceptionPointName)
201     {
202         this.interceptionPointName = interceptionPointName;
203     }
204
205     public String JavaDoc getInterceptionPointCategory()
206     {
207         return this.interceptionPointCategory;
208     }
209
210     public void setInterceptionPointCategory(String JavaDoc interceptionPointCategory)
211     {
212         this.interceptionPointCategory = interceptionPointCategory;
213     }
214
215     public List JavaDoc getInterceptionPointVOList()
216     {
217         return this.interceptionPointVOList;
218     }
219
220     public Collection JavaDoc getAccessRightsUserRows()
221     {
222         return accessRightsUserRows;
223     }
224 }
Popular Tags