KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > security > Security


1 /*
2  * $Id: Security.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.security;
26
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29
30 import javax.servlet.http.HttpSession JavaDoc;
31
32 import org.ofbiz.base.util.cache.UtilCache;
33 import org.ofbiz.entity.GenericDelegator;
34 import org.ofbiz.entity.GenericValue;
35
36 /**
37  * Security handler: This class is an abstract implementation for all commononly used security aspects.
38  *
39  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
40  * @author <a HREF="mailto:hermanns@aixcept.de">Rainer Hermanns</a>
41  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
42  * @version $Rev: 5462 $
43  * @since 2.0
44  */

45 public abstract class Security {
46
47     /**
48      * UtilCache to cache a Collection of UserLoginSecurityGroup entities for each UserLogin, by userLoginId.
49      */

50     public static UtilCache userLoginSecurityGroupByUserLoginId = new UtilCache("security.UserLoginSecurityGroupByUserLoginId");
51
52     /**
53      * UtilCache to cache whether or not a certain SecurityGroupPermission row exists or not.
54      * For each SecurityGroupPermissionPK there is a Boolean in the cache specifying whether or not it exists.
55      * In this way the cache speeds things up whether or not the user has a permission.
56      */

57     public static UtilCache securityGroupPermissionCache = new UtilCache("security.SecurityGroupPermissionCache");
58
59     GenericDelegator delegator = null;
60
61     public GenericDelegator getDelegator() {
62         return delegator;
63     }
64
65     public void setDelegator(GenericDelegator delegator) {
66         this.delegator = delegator;
67     }
68
69     /**
70      * Uses userLoginSecurityGroupByUserLoginId cache to speed up the finding of the userLogin's security group list.
71      *
72      * @param userLoginId The userLoginId to find security groups by
73      * @return An iterator made from the Collection either cached or retrieved from the database through the
74      * UserLoginSecurityGroup Delegator.
75      */

76     public abstract Iterator JavaDoc findUserLoginSecurityGroupByUserLoginId(String JavaDoc userLoginId);
77
78     /**
79      * Finds whether or not a SecurityGroupPermission row exists given a groupId and permission.
80      * Uses the securityGroupPermissionCache to speed this up.
81      * The groupId,permission pair is cached instead of the userLoginId,permission pair to keep the cache small and to
82      * make it more changeable.
83      *
84      * @param groupId The ID of the group
85      * @param permission The name of the permission
86      * @return boolean specifying whether or not a SecurityGroupPermission row exists
87      */

88     public abstract boolean securityGroupPermissionExists(String JavaDoc groupId, String JavaDoc permission);
89
90     /**
91      * Checks to see if the currently logged in userLogin has the passed permission.
92      *
93      * @param permission Name of the permission to check.
94      * @param session The current HTTP session, contains the logged in userLogin as an attribute.
95      * @return Returns true if the currently logged in userLogin has the specified permission, otherwise returns false.
96      */

97     public abstract boolean hasPermission(String JavaDoc permission, HttpSession JavaDoc session);
98
99     /**
100      * Checks to see if the userLogin has the passed permission.
101      *
102      * @param permission Name of the permission to check.
103      * @param userLogin The userLogin object for user to check against.
104      * @return Returns true if the currently logged in userLogin has the specified permission, otherwise returns false.
105      */

106     public abstract boolean hasPermission(String JavaDoc permission, GenericValue userLogin);
107
108     /**
109      * Like hasPermission above, except it has functionality specific to Entity permissions. Checks the entity for the
110      * specified action, as well as for "_ADMIN" to allow for simplified general administration permission.
111      *
112      * @param entity The name of the Entity corresponding to the desired permission.
113      * @param action The action on the Entity corresponding to the desired permission.
114      * @param session The current HTTP session, contains the logged in userLogin as an attribute.
115      * @return Returns true if the currently logged in userLogin has the specified permission, otherwise returns false.
116      */

117     public abstract boolean hasEntityPermission(String JavaDoc entity, String JavaDoc action, HttpSession JavaDoc session);
118
119     /**
120      * Like hasPermission above, except it has functionality specific to Entity permissions. Checks the entity for the
121      * specified action, as well as for "_ADMIN" to allow for simplified general administration permission.
122      *
123      * @param entity The name of the Entity corresponding to the desired permission.
124      * @param action The action on the Entity corresponding to the desired permission.
125      * @param userLogin The userLogin object for user to check against.
126      * @return Returns true if the currently logged in userLogin has the specified permission, otherwise returns false.
127      */

128     public abstract boolean hasEntityPermission(String JavaDoc entity, String JavaDoc action, GenericValue userLogin);
129     
130     /**
131      * Like hasEntityPermission above, this checks the specified action, as well as for "_ADMIN" to allow for simplified
132      * general administration permission, but also checks action_ROLE and validates the user is a member for the
133      * application.
134      *
135      * @param application The name of the application corresponding to the desired permission.
136      * @param action The action on the application corresponding to the desired permission.
137      * @param primaryKey The primary key for the role check.
138      * @param role The roleTypeId which the user must validate with.
139      * @param session The current HTTP session, contains the logged in userLogin as an attribute.
140      * @return Returns true if the currently logged in userLogin has the specified permission, otherwise returns false.
141      */

142     public abstract boolean hasRolePermission(String JavaDoc application, String JavaDoc action, String JavaDoc primaryKey, String JavaDoc role, HttpSession JavaDoc session);
143
144     /**
145      * Like hasEntityPermission above, this checks the specified action, as well as for "_ADMIN" to allow for simplified
146      * general administration permission, but also checks action_ROLE and validates the user is a member for the
147      * application.
148      *
149      * @param application The name of the application corresponding to the desired permission.
150      * @param action The action on the application corresponding to the desired permission.
151      * @param primaryKey The primary key for the role check.
152      * @param role The roleTypeId which the user must validate with.
153      * @param userLogin The userLogin object for user to check against.
154      * @return Returns true if the currently logged in userLogin has the specified permission, otherwise returns false.
155      */

156     public abstract boolean hasRolePermission(String JavaDoc application, String JavaDoc action, String JavaDoc primaryKey, String JavaDoc role, GenericValue userLogin);
157         
158     /**
159      * Like hasEntityPermission above, this checks the specified action, as well as for "_ADMIN" to allow for simplified
160      * general administration permission, but also checks action_ROLE and validates the user is a member for the
161      * application.
162      *
163      * @param application The name of the application corresponding to the desired permission.
164      * @param action The action on the application corresponding to the desired permission.
165      * @param primaryKey The primary key for the role check.
166      * @param roles List of roleTypeId of which the user must validate with (ORed).
167      * @param userLogin The userLogin object for user to check against.
168      * @return Returns true if the currently logged in userLogin has the specified permission, otherwise returns false.
169      */

170     public abstract boolean hasRolePermission(String JavaDoc application, String JavaDoc action, String JavaDoc primaryKey, List JavaDoc roles, GenericValue userLogin);
171     
172     /**
173      * Like hasEntityPermission above, this checks the specified action, as well as for "_ADMIN" to allow for simplified
174      * general administration permission, but also checks action_ROLE and validates the user is a member for the
175      * application.
176      *
177      * @param application The name of the application corresponding to the desired permission.
178      * @param action The action on the application corresponding to the desired permission.
179      * @param primaryKey The primary key for the role check.
180      * @param roles List of roleTypeId of which the user must validate with (ORed).
181      * @param session The current HTTP session, contains the logged in userLogin as an attribute.
182      * @return Returns true if the currently logged in userLogin has the specified permission, otherwise returns false.
183      */

184     public abstract boolean hasRolePermission(String JavaDoc application, String JavaDoc action, String JavaDoc primaryKey, List JavaDoc roles, HttpSession JavaDoc session);
185     
186 }
187
Popular Tags