1 /***
2 * The contents of this file are subject to the Mozilla Public License Version
3 * 1.1 (the "License"); you may not use this file except in compliance with the
4 * License.
5 *
6 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
7 * Software distributed under the License is distributed on an "AS IS" basis,
8 * WITHOUT WARRANTY OF ANY KIND, either express or implied.
9 * See the License for the specific language governing rights and limitations
10 * under the License.
11 *
12 * The Original Code is pow2ACL library. The Initial Owner of the Original Code
13 * is Power Of Two S.R.L. Portions created by Power Of Two S.R.L. are Copyright
14 * (C) Power Of Two S.R.L. All Rights Reserved. Contributor(s):
15 */
16 package com.pow2.acl.struts.action;
17
18 import javax.servlet.http.HttpServletRequest;
19 import javax.servlet.http.HttpServletResponse;
20 import javax.servlet.http.HttpSession;
21
22 import org.apache.log4j.Category;
23 import org.apache.struts.action.*;
24 import com.pow2.acl.dao.ACLDAO;
25 import com.pow2.user.User;
26 import com.pow2.user.UserManager;
27 import com.pow2.struts.action.DispatcherAction;
28
29 /***
30 * Abstract class that extends <code>com.pow2.struts.actions.DispatcherAction</code>.
31 * <br>
32 * Override the <code>validateSession</code> method, checking for
33 * a valid <code>com.pow2.user.User</code> object into the session scope.
34 * <br>
35 * Add the <code>validatePermission</code> hook method to check the user
36 * permissions for a given resource. This default implementation always returns
37 * true; subclass this class and make your own implementation.
38 *
39 * @author Luca Fossato
40 * @created 8 aprile 2002
41 */
42 public abstract class ACLDispatcherAction extends DispatcherAction
43 {
44 /*** ActionForward invalid user string */
45 private final static String FWD_ACL_NOPERMISSIONS = "noPermissions";
46
47 /*** Resource properties message key for user insufficient permissions */
48 private final static String KEY_FWD_ACL_NOPERMISSIONS = "acl.noPermissions";
49
50
51 /***
52 * Get the ActionForward object related to the "failure" forward, and store
53 * the new error identified by the errorKey string into the input
54 * ActionErrors object.
55 *
56 * @param request the HttpServletRequest object
57 * @param mapping the ActionMapping object
58 * @param errors the ActionErrors object
59 * @param errorKey a string key identifying a resource properties error
60 * string
61 * @return Description of the Return Value
62 */
63 protected ActionForward failureForward(HttpServletRequest request,
64 ActionMapping mapping,
65 ActionErrors errors,
66 String errorKey)
67 {
68 return super.failureForward(request, mapping, errors, errorKey);
69 }
70
71
72 /***
73 * Get the ActionForward object related to the "invalidSession" forward.
74 *
75 * @param request the HttpServletRequest object
76 * @param mapping the ActionMapping object
77 * @param errors the ActionErrors object
78 * @return Description of the Return Value
79 */
80 protected ActionForward invalidSessionForward(HttpServletRequest request,
81 ActionMapping mapping,
82 ActionErrors errors)
83 {
84 return super.invalidSessionForward(request, mapping, errors);
85 }
86
87
88 /***
89 * Get the ActionForward object related to the "insufficientPermissions"
90 * forward.
91 *
92 * @param request the HttpServletRequest object
93 * @param mapping the ActionMapping object
94 * @param errors the ActionErrors object
95 * @return Description of the Return Value
96 */
97 protected ActionForward noPermissionsForward(HttpServletRequest request,
98 ActionMapping mapping,
99 ActionErrors errors)
100 {
101 return super.getForward(request, mapping, errors, FWD_ACL_NOPERMISSIONS, KEY_FWD_ACL_NOPERMISSIONS);
102 }
103
104
105 /***
106 * Check if the current session have a valid reference to an User object.
107 *
108 * @param request the input HttpServletRequest object
109 * @return true if the current session is valid; false otherwise
110 */
111 protected boolean validateSession(HttpServletRequest request)
112 {
113 UserManager userManager = UserManager.instance();
114 return (userManager.getUser(request) != null);
115 }
116
117
118 /***
119 * Validate user permissions. <br>
120 * This is an hook method; this default implementation always returns true.
121 * <br>
122 * Subclass this class and make your own implementation.
123 *
124 * @param user the current User object
125 * @param acl the data access object for ACL validation
126 * @param mapping the ActionMapping object of the current action
127 * @param errors the ActionError list to fill with possible errors
128 * @param request Description of the Parameter
129 * @return true if user has permissions for execute this action,
130 * false otherwise
131 */
132 public boolean validatePermissions(User user,
133 ACLDAO acl,
134 ActionMapping mapping,
135 HttpServletRequest request,
136 ActionErrors errors)
137 {
138 return true;
139 }
140 }
This page was automatically generated by Maven