From 97ac9f7e98180c8a5e7b74e81794f56b1470df49 Mon Sep 17 00:00:00 2001
From: Ben Alex hasPermission attribute. The tag will include its body if
* any of the integer permissions have been granted to the current
- * Authentication (obtained from the SecurityContextHolder).
+ * Authentication (obtained from the
+ * SecurityContextHolder).
*
@@ -82,22 +86,6 @@ public class AclTag extends TagSupport { //~ Methods ================================================================ - public void setDomainObject(Object domainObject) { - this.domainObject = domainObject; - } - - public Object getDomainObject() { - return domainObject; - } - - public void setHasPermission(String hasPermission) { - this.hasPermission = hasPermission; - } - - public String getHasPermission() { - return hasPermission; - } - public int doStartTag() throws JspException { if ((null == hasPermission) || "".equals(hasPermission)) { return Tag.SKIP_BODY; @@ -146,16 +134,16 @@ public class AclTag extends TagSupport { .getAuthentication(); ApplicationContext context = getContext(pageContext); - Map beans = context.getBeansOfType(AclManager.class, false, false); + String[] beans = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(context, + AclManager.class, false, false); - if (beans.size() == 0) { + if (beans.length == 0) { throw new JspException( "No AclManager would found the application context: " + context.toString()); } - String beanName = (String) beans.keySet().iterator().next(); - AclManager aclManager = (AclManager) context.getBean(beanName); + AclManager aclManager = (AclManager) context.getBean(beans[0]); // Obtain aclEntrys applying to the current Authentication object AclEntry[] acls = aclManager.getAcls(resolvedDomainObject, auth); @@ -174,7 +162,7 @@ public class AclTag extends TagSupport { for (int i = 0; i < acls.length; i++) { // Locate processable AclEntrys if (acls[i] instanceof BasicAclEntry) { - BasicAclEntry processableAcl = (BasicAclEntry) acls[i]; + BasicAclEntry processableAcl = (BasicAclEntry) acls[i]; // See if principal has any of the required permissions for (int y = 0; y < requiredIntegers.length; y++) { @@ -214,6 +202,14 @@ public class AclTag extends TagSupport { return WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); } + public Object getDomainObject() { + return domainObject; + } + + public String getHasPermission() { + return hasPermission; + } + private Integer[] parseIntegersString(String integersString) throws NumberFormatException { final Set integers = new HashSet(); @@ -227,4 +223,12 @@ public class AclTag extends TagSupport { return (Integer[]) integers.toArray(new Integer[] {}); } + + public void setDomainObject(Object domainObject) { + this.domainObject = domainObject; + } + + public void setHasPermission(String hasPermission) { + this.hasPermission = hasPermission; + } }