View Javadoc
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 * You may obtain a copy of the License at http://www.mozilla.org/MPL/ 6 * Software distributed under the License is distributed on an "AS IS" basis, 7 * WITHOUT WARRANTY OF ANY KIND, either express or implied. 8 * See the License for the specific language governing rights and limitations 9 * under the License. 10 * The Original Code is pow2ACL library. 11 * The Initial Owner of the Original Code is Power Of Two S.R.L. 12 * Portions created by Power Of Two S.R.L. are Copyright 13 * (C) Power Of Two S.R.L. All Rights Reserved. 14 * 15 * Contributor(s): 16 */ 17 18 package com.pow2.acl.struts.action; 19 20 import javax.servlet.http.HttpServletRequest; 21 import javax.servlet.http.HttpServletResponse; 22 import javax.servlet.http.HttpSession; 23 24 import org.apache.struts.action.*; 25 26 import com.pow2.util.Util; 27 import com.pow2.acl.*; 28 import com.pow2.acl.dao.ACLDAO; 29 import com.pow2.user.User; 30 31 /*** 32 * Abstract class that extends the ACLAction class. <br> 33 * Provides a <code>validatePermissions</code> method implementation that 34 * checks if the current user owns the acl role (and belongs to the acl group, 35 * if specified) retrieved from the ACLActionMapping object of the current 36 * action. 37 * 38 * @author Luca Fossato 39 * @created 8 aprile 2002 40 */ 41 public class ACLRoleAction extends ACLDispatcherAction 42 { 43 /*** 44 * Validate user permissions. <br> 45 * This method checks if the current user owns the acl role and belongs to 46 * the acl group retrieved from the ACLActionMapping object of the current 47 * action. 48 * 49 * @param user the current User object 50 * @param acl the data access object for ACL validation 51 * @param mapping the ActionMapping object of the current action 52 * @param errors the ActionError list to fill with possible errors 53 * @param request Description of the Parameter 54 * @return true if user has permissions for execute this action, 55 * false otherwise 56 */ 57 public boolean validatePermissions(User user, 58 ACLDAO acl, 59 ActionMapping mapping, 60 HttpServletRequest request, 61 ActionErrors errors) 62 { 63 ACLActionMapping myMapping = (ACLActionMapping)mapping; 64 String role = null; 65 String group = null; 66 boolean validated = false; 67 68 role = myMapping.getRole(); 69 group = myMapping.getGroup(); 70 71 // role is defined ? 72 if (!Util.isNull(role)) 73 { 74 Role myRole = new Role(role); 75 76 try 77 { 78 // group is defined ? 79 validated = ((Util.isNull(group)) ? 80 acl.isUserInRole(user, myRole) : 81 acl.isUserInRole(user, new Group(group), myRole)); 82 } 83 catch (Exception e) 84 { 85 cat.error("::validatePermissions - error in isUserInRole control", e); 86 } 87 } 88 else 89 { 90 cat.warn("::validatePermissions - acl role is not defined; validation fails"); 91 } 92 93 if (cat.isDebugEnabled()) 94 { 95 cat.debug(new StringBuffer("::validatePermissions - user is in role, group [") 96 .append(role) 97 .append(", ") 98 .append(group) 99 .append("] ? ") 100 .append(validated)); 101 } 102 103 return validated; 104 } 105 }

This page was automatically generated by Maven