KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > security > interceptors > InfoGlueOSWorkflowInterceptor


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.security.interceptors;
25
26 import java.util.HashMap JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import org.apache.log4j.Logger;
30 import org.exolab.castor.jdo.Database;
31 import org.infoglue.cms.controllers.kernel.impl.simple.AccessRightController;
32 import org.infoglue.cms.controllers.kernel.impl.simple.ContentControllerProxy;
33 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionControllerProxy;
34 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeVersionController;
35 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeVersionControllerProxy;
36 import org.infoglue.cms.entities.content.ContentVO;
37 import org.infoglue.cms.entities.content.ContentVersionVO;
38 import org.infoglue.cms.entities.management.InterceptionPointVO;
39 import org.infoglue.cms.entities.structure.SiteNodeVersion;
40 import org.infoglue.cms.entities.structure.SiteNodeVersionVO;
41 import org.infoglue.cms.exception.AccessConstraintException;
42 import org.infoglue.cms.exception.ConstraintException;
43 import org.infoglue.cms.exception.SystemException;
44 import org.infoglue.cms.security.InfoGluePrincipal;
45 import org.infoglue.cms.util.AccessConstraintExceptionBuffer;
46
47 import com.opensymphony.workflow.Workflow;
48 import com.opensymphony.workflow.basic.BasicWorkflow;
49 import com.opensymphony.workflow.loader.WorkflowDescriptor;
50
51 /**
52  * This interceptor is used to handle integration of the external workflow engine OSWorkflow.
53  *
54  * @author Mattias Bogeblad
55  */

56
57 public class InfoGlueOSWorkflowInterceptor implements InfoGlueInterceptor
58 {
59     private final static Logger logger = Logger.getLogger(InfoGlueOSWorkflowInterceptor.class.getName());
60
61     /**
62      * This method will be called when a interceptionPoint is reached.
63      *
64      * @param interceptionPoint
65      * @param extradata
66      * @throws ConstraintException
67      * @throws SystemException
68      */

69
70     public void intercept(InfoGluePrincipal infoGluePrincipal, InterceptionPointVO interceptionPointVO, Map JavaDoc extradata) throws ConstraintException, SystemException, Exception JavaDoc
71     {
72         logger.info("interceptionPointVO:" + interceptionPointVO.getName());
73         
74         AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer();
75         
76         try
77         {
78             Workflow workflowInit = new BasicWorkflow(infoGluePrincipal.getName());
79             
80             long id = workflowInit.initialize("MattiasWF", 1, new HashMap JavaDoc());
81             logger.info("Workflow initialized....");
82             logger.info("id:" + id);
83             logger.info("name:" + workflowInit.getWorkflowName(id));
84             
85             
86             Workflow workflow = workflowInit; //new BasicWorkflow(infoGluePrincipal.getName());
87

88             int[] actions = workflow.getAvailableActions(id, null);
89             logger.info("actions:" + actions.length);
90             WorkflowDescriptor wd = workflow.getWorkflowDescriptor(workflow.getWorkflowName(id));
91
92             for (int i = 0; i < actions.length; i++)
93             {
94                 int availableActionId = actions[i];
95                 String JavaDoc name = wd.getAction(availableActionId).getName();
96                 logger.info("Action:" + availableActionId + ":" + name);
97                 
98                 //workflow.doAction(id, availableActionId, Collections.EMPTY_MAP);
99
}
100  
101             Map JavaDoc map = new HashMap JavaDoc();
102             map.put("userName", "Mattias");
103             workflow.doAction(id, 1, map);
104
105             actions = workflow.getAvailableActions(id, null);
106             logger.info("actions:" + actions.length);
107             wd = workflow.getWorkflowDescriptor(workflow.getWorkflowName(id));
108
109             for (int i = 0; i < actions.length; i++)
110             {
111                 int availableActionId = actions[i];
112                 String JavaDoc name = wd.getAction(availableActionId).getName();
113                 logger.info("Action:" + availableActionId + ":" + name);
114                 
115                 //workflow.doAction(id, availableActionId, Collections.EMPTY_MAP);
116
}
117
118             //workflow.doAction(id, 2, Collections.EMPTY_MAP);
119
//workflow.doAction(id, 3, Collections.EMPTY_MAP);
120
//workflow.doAction(id, 1, Collections.EMPTY_MAP);
121
//workflow.doAction(id, 2, Collections.EMPTY_MAP);
122

123             /*
124             WorkflowQuery queryLeft = new WorkflowQuery(WorkflowQuery.OWNER, WorkflowQuery.CURRENT, WorkflowQuery.EQUALS, infoGluePrincipal.getName());
125             WorkflowQuery queryRight = new WorkflowQuery(WorkflowQuery.STATUS, WorkflowQuery.CURRENT, WorkflowQuery.EQUALS, "Underway");
126             WorkflowQuery query = new WorkflowQuery(queryLeft, WorkflowQuery.AND, queryRight);
127             List workflows = workflow.query(query);
128             for (Iterator iterator = workflows.iterator(); iterator.hasNext();) {
129                 Long wfId = (Long) iterator.next();
130                 logger.info(wfId);
131                 }
132             */

133         }
134         catch(Throwable JavaDoc t)
135         {
136             t.printStackTrace();
137         }
138                 
139         if(interceptionPointVO.getName().equalsIgnoreCase("Content.Read"))
140         {
141             Integer JavaDoc contentId = (Integer JavaDoc)extradata.get("contentId");
142             ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId);
143
144         }
145         else if(interceptionPointVO.getName().equalsIgnoreCase("Content.Write"))
146         {
147             Integer JavaDoc contentId = (Integer JavaDoc)extradata.get("contentId");
148             ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId);
149
150         }
151         else if(interceptionPointVO.getName().equalsIgnoreCase("Content.Create"))
152         {
153             Integer JavaDoc contentId = (Integer JavaDoc)extradata.get("contentId");
154             ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId);
155
156         }
157         else if(interceptionPointVO.getName().equalsIgnoreCase("Content.Delete"))
158         {
159             Integer JavaDoc contentId = (Integer JavaDoc)extradata.get("contentId");
160             ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId);
161
162         }
163         else if(interceptionPointVO.getName().equalsIgnoreCase("Content.Move"))
164         {
165             Integer JavaDoc contentId = (Integer JavaDoc)extradata.get("contentId");
166             ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId);
167
168         }
169         else if(interceptionPointVO.getName().equalsIgnoreCase("Content.CreateVersion"))
170         {
171             Integer JavaDoc contentId = (Integer JavaDoc)extradata.get("contentId");
172             ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId);
173
174         }
175         else if(interceptionPointVO.getName().equalsIgnoreCase("Content.SubmitToPublish"))
176         {
177             Integer JavaDoc contentId = (Integer JavaDoc)extradata.get("contentId");
178             ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId);
179
180         }
181         else if(interceptionPointVO.getName().equalsIgnoreCase("Content.ChangeAccessRights"))
182         {
183             Integer JavaDoc contentId = (Integer JavaDoc)extradata.get("contentId");
184             ContentVO contentVO = ContentControllerProxy.getController().getContentVOWithId(contentId);
185
186         }
187         else if(interceptionPointVO.getName().equalsIgnoreCase("ContentVersion.Read"))
188         {
189             Integer JavaDoc contentVersionId = (Integer JavaDoc)extradata.get("contentVersionId");
190             ContentVersionVO contentVersionVO = ContentVersionControllerProxy.getController().getContentVersionVOWithId(contentVersionId);
191
192         }
193         else if(interceptionPointVO.getName().equalsIgnoreCase("ContentVersion.Write"))
194         {
195             Integer JavaDoc contentVersionId = (Integer JavaDoc)extradata.get("contentVersionId");
196             ContentVersionVO contentVersionVO = ContentVersionControllerProxy.getController().getContentVersionVOWithId(contentVersionId);
197
198         }
199         else if(interceptionPointVO.getName().equalsIgnoreCase("ContentVersion.Delete"))
200         {
201             Integer JavaDoc contentVersionId = (Integer JavaDoc)extradata.get("contentVersionId");
202             ContentVersionVO contentVersionVO = ContentVersionControllerProxy.getController().getContentVersionVOWithId(contentVersionId);
203
204         }
205         else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.Read"))
206         {
207             Integer JavaDoc siteNodeVersionId = (Integer JavaDoc)extradata.get("siteNodeVersionId");
208             SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(siteNodeVersionId);
209
210         }
211         else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.Write"))
212         {
213             Integer JavaDoc siteNodeVersionId = (Integer JavaDoc)extradata.get("siteNodeVersionId");
214             SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(siteNodeVersionId);
215
216         }
217         else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.CreateSiteNode"))
218         {
219             Integer JavaDoc parentSiteNodeId = (Integer JavaDoc)extradata.get("siteNodeId");
220             SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getLatestSiteNodeVersionVO(parentSiteNodeId);
221
222         }
223         else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.DeleteSiteNode"))
224         {
225             Integer JavaDoc siteNodeId = (Integer JavaDoc)extradata.get("siteNodeId");
226             SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getLatestSiteNodeVersionVO(siteNodeId);
227
228         }
229         else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.MoveSiteNode"))
230         {
231             Integer JavaDoc siteNodeId = (Integer JavaDoc)extradata.get("siteNodeId");
232             SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getLatestSiteNodeVersionVO(siteNodeId);
233
234         }
235         else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.SubmitToPublish"))
236         {
237             Integer JavaDoc siteNodeVersionId = (Integer JavaDoc)extradata.get("siteNodeVersionId");
238             SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(siteNodeVersionId);
239
240         }
241         else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.ChangeAccessRights"))
242         {
243             Integer JavaDoc siteNodeVersionId = (Integer JavaDoc)extradata.get("siteNodeVersionId");
244             SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(siteNodeVersionId);
245
246         }
247         
248         ceb.throwIfNotEmpty();
249     }
250     
251     
252     /**
253      * This method will be called when a interceptionPoint is reached and it handle it within a transaction.
254      *
255      * @param interceptionPoint
256      * @param extradata
257      * @throws ConstraintException
258      * @throws SystemException
259      */

260
261     public void intercept(InfoGluePrincipal infoGluePrincipal, InterceptionPointVO interceptionPointVO, Map JavaDoc extradata, Database db) throws ConstraintException, SystemException, Exception JavaDoc
262     {
263         logger.info("interceptionPointVO:" + interceptionPointVO.getName());
264         
265         AccessConstraintExceptionBuffer ceb = new AccessConstraintExceptionBuffer();
266         
267         /*
268         if(interceptionPointVO.getName().equalsIgnoreCase("Content.Read"))
269         {
270             Integer contentId = (Integer)extradata.get("contentId");
271             if(ContentControllerProxy.getController().getIsContentProtected(contentId) && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "Content.Read", contentId.toString()))
272                 ceb.add(new AccessConstraintException("Content.contentId", "1000"));
273         }
274         else if(interceptionPointVO.getName().equalsIgnoreCase("Content.Write"))
275         {
276             Integer contentId = (Integer)extradata.get("contentId");
277             if(ContentControllerProxy.getController().getIsContentProtected(contentId) && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "Content.Write", contentId.toString()))
278                 ceb.add(new AccessConstraintException("Content.contentId", "1001"));
279         }
280         else if(interceptionPointVO.getName().equalsIgnoreCase("Content.Create"))
281         {
282             Integer contentId = (Integer)extradata.get("contentId");
283             if(ContentControllerProxy.getController().getIsContentProtected(contentId) && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "Content.Create", contentId.toString()))
284                 ceb.add(new AccessConstraintException("Content.contentId", "1002"));
285         }
286         else if(interceptionPointVO.getName().equalsIgnoreCase("Content.Delete"))
287         {
288             Integer contentId = (Integer)extradata.get("contentId");
289             if(ContentControllerProxy.getController().getIsContentProtected(contentId) && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "Content.Delete", contentId.toString()))
290                 ceb.add(new AccessConstraintException("Content.contentId", "1003"));
291         }
292         else if(interceptionPointVO.getName().equalsIgnoreCase("Content.Move"))
293         {
294             Integer contentId = (Integer)extradata.get("contentId");
295             if(ContentControllerProxy.getController().getIsContentProtected(contentId) && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "Content.Move", contentId.toString()))
296                 ceb.add(new AccessConstraintException("Content.contentId", "1004"));
297         }
298         else if(interceptionPointVO.getName().equalsIgnoreCase("Content.SubmitToPublish"))
299         {
300             Integer contentId = (Integer)extradata.get("contentId");
301             if(ContentControllerProxy.getController().getIsContentProtected(contentId) && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "Content.SubmitToPublish", contentId.toString()))
302                 ceb.add(new AccessConstraintException("Content.contentId", "1005"));
303         }
304         else if(interceptionPointVO.getName().equalsIgnoreCase("Content.ChangeAccessRights"))
305         {
306             Integer contentId = (Integer)extradata.get("contentId");
307             if(ContentControllerProxy.getController().getIsContentProtected(contentId) && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "Content.ChangeAccessRights", contentId.toString()))
308                 ceb.add(new AccessConstraintException("Content.contentId", "1006"));
309         }
310         else if(interceptionPointVO.getName().equalsIgnoreCase("ContentVersion.Read"))
311         {
312             Integer contentVersionId = (Integer)extradata.get("contentVersionId");
313             ContentVersionVO contentVersionVO = ContentVersionControllerProxy.getController().getContentVersionVOWithId(contentVersionId);
314             if(!contentVersionVO.getVersionModifier().equalsIgnoreCase(infoGluePrincipal.getName()))
315             {
316                 if(ContentVersionControllerProxy.getController().getIsContentProtected(contentVersionVO.getContentId()) && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "ContentVersion.Read", contentVersionId.toString()))
317                     ceb.add(new AccessConstraintException("ContentVersion.contentVersionId", "1000"));
318             }
319         }
320         else if(interceptionPointVO.getName().equalsIgnoreCase("ContentVersion.Write"))
321         {
322             Integer contentVersionId = (Integer)extradata.get("contentVersionId");
323             ContentVersionVO contentVersionVO = ContentVersionControllerProxy.getController().getContentVersionVOWithId(contentVersionId);
324             if(!contentVersionVO.getVersionModifier().equalsIgnoreCase(infoGluePrincipal.getName()))
325             {
326                 if(ContentVersionControllerProxy.getController().getIsContentProtected(contentVersionVO.getContentId()) && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "ContentVersion.Write", contentVersionId.toString()))
327                     ceb.add(new AccessConstraintException("ContentVersion.contentVersionId", "1001"));
328             }
329         }
330         else if(interceptionPointVO.getName().equalsIgnoreCase("ContentVersion.Delete"))
331         {
332             Integer contentVersionId = (Integer)extradata.get("contentVersionId");
333             ContentVersionVO contentVersionVO = ContentVersionControllerProxy.getController().getContentVersionVOWithId(contentVersionId);
334             if(!contentVersionVO.getVersionModifier().equalsIgnoreCase(infoGluePrincipal.getName()))
335             {
336                 if(ContentVersionControllerProxy.getController().getIsContentProtected(contentVersionVO.getContentId()) && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "ContentVersion.Delete", contentVersionId.toString()))
337                     ceb.add(new AccessConstraintException("ContentVersion.contentVersionId", "1003"));
338             }
339         }
340         else if(interceptionPointVO.getName().equalsIgnoreCase("Content.CreateVersion"))
341         {
342             Integer contentId = (Integer)extradata.get("contentId");
343             if(ContentVersionControllerProxy.getController().getIsContentProtected(contentId) && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "Content.CreateVersion", contentId.toString()))
344                 ceb.add(new AccessConstraintException("Content.contentId", "1002"));
345         }
346         else if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.Read"))
347         {
348             Integer siteNodeVersionId = (Integer)extradata.get("siteNodeVersionId");
349             SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(siteNodeVersionId);
350             if(!siteNodeVersionVO.getVersionModifier().equalsIgnoreCase(infoGluePrincipal.getName()))
351             {
352                 if(SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy().getIsSiteNodeVersionProtected(siteNodeVersionId) && !AccessRightController.getController().getIsPrincipalAuthorized(infoGluePrincipal, "SiteNodeVersion.Read", siteNodeVersionId.toString()))
353                     ceb.add(new AccessConstraintException("SiteNodeVersion.siteNodeVersionId", "1000"));
354             }
355         }
356         else*/
if(interceptionPointVO.getName().equalsIgnoreCase("SiteNodeVersion.Write"))
357         {
358             logger.info("******************************************************");
359             logger.info("SiteNodeVersion.ChangeAccessRights");
360             Integer JavaDoc siteNodeVersionId = (Integer JavaDoc)extradata.get("siteNodeVersionId");
361             SiteNodeVersion siteNodeVersion = SiteNodeVersionController.getController().getSiteNodeVersionWithId(siteNodeVersionId, db);
362             logger.info("VersionModifier:" + siteNodeVersion.getVersionModifier());
363             logger.info("infoGluePrincipal:" + infoGluePrincipal.getName());
364             if(!siteNodeVersion.getVersionModifier().equalsIgnoreCase(infoGluePrincipal.getName()))
365             {
366                 Integer JavaDoc protectedSiteNodeVersionId = SiteNodeVersionControllerProxy.getSiteNodeVersionControllerProxy().getProtectedSiteNodeVersionId(siteNodeVersionId, db);
367                 if(protectedSiteNodeVersionId != null && !AccessRightController.getController().getIsPrincipalAuthorized(db, infoGluePrincipal, "SiteNodeVersion.Write", siteNodeVersionId.toString()))
368                     ceb.add(new AccessConstraintException("SiteNodeVersion.siteNodeVersionId", "1001"));
369             }
370         }
371
372         ceb.throwIfNotEmpty();
373     }
374 }
375
Popular Tags