KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > util > workflow > OwnerStepFilter


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 package org.infoglue.cms.util.workflow;
24
25 import java.util.Iterator JavaDoc;
26
27 import org.infoglue.cms.applications.common.Session;
28 import org.infoglue.cms.entities.mydesktop.WorkflowStepVO;
29 import org.infoglue.cms.security.InfoGluePrincipal;
30
31 /**
32  * Filters steps according to owner. If a step has no owner, it is assumed that anyone can view it.
33  * An administrator can view all steps regardless of owner.
34  * @author <a HREF="mailto:jedprentice@gmail.com">Jed Prentice</a>
35  * @version $Revision: 1.10 $ $Date: 2006/03/06 17:28:55 $
36  */

37 public class OwnerStepFilter implements StepFilter
38 {
39     private final InfoGluePrincipal userPrincipal;
40
41     /**
42      * Constructs an OwnerStepFilter from the user associated with the current session/action context
43      */

44     public OwnerStepFilter()
45     {
46         this(new Session().getInfoGluePrincipal());
47     }
48
49     /**
50      * Constructs an owner step filter with the given user principal
51      * @param userPrincipal an InfoGluePrincipal representing a user
52      */

53     public OwnerStepFilter(InfoGluePrincipal userPrincipal)
54     {
55         this.userPrincipal = userPrincipal;
56     }
57
58     /**
59      * Indicates whether the step is allowed
60      * @param step a workflow step.
61      * @return true if the step is owned by the current user, the current user is an administrator, or if the owner
62      * of the step is null; otherwise returns false.
63      */

64     public boolean isAllowed(WorkflowStepVO step)
65     {
66         if(!step.hasOwner() || isUserAdministrator())
67         {
68             return true;
69         }
70         for(final Iterator JavaDoc owners = OwnerFactory.createAll(userPrincipal).iterator(); owners.hasNext(); )
71         {
72             final Owner owner = (Owner) owners.next();
73             if(step.isOwner(owner.getIdentifier()))
74             {
75                 return true;
76             }
77         }
78         return false;
79     }
80
81     protected boolean isUserAdministrator()
82     {
83         return userPrincipal.getIsAdministrator();
84     }
85
86     protected InfoGluePrincipal getUserPrincipal()
87     {
88         return userPrincipal;
89     }
90 }
91
Popular Tags