When I try to use acegi at my recent project. I find that it's JSP tag prevent me from using velocity template in my project. After search the forum and read the JSP tag lib source code, I decided to build a POJO (Let's name it Authz) which can be usd in velocity templates.
This POJO should wraps the JSP Tag implements because I hope the Authz can evolveup with Acegi JSP tag.
here is the AuthenticationTag's counterpart:
here is the AclTag's counterpart:Code:$authz.getPrincipal()
here is the AuthorizeTagCode:#if ($authz.hasPermission($domainObject, $permissions)) #end
I define Authz interface for this POJO. And I also have a AuthzImpl implementation which do the actually job.Code:#if ($authz.allGranted("ROLE_DIRECTOR")&& $authz.anyGranted("ROLE_TELLER")&& $authz.noneGranted("ROLE_CUSTOMER")) ... #end
If this post got enough support (>10) or acegi developer think this is a good idea. I will contribute my code to acegi (although I don't know how to do that.)
Code:package net.sf.acegisecurity.velocitytool; import org.springframework.context.ApplicationContext; import net.sf.acegisecurity.acl.AclManager; /** * Wrapper the implementation of Acegi Security for Spring JSP tag * includes: {@link AuthenticationTag}, {@link AclTag}, * {@link AuthorizeTag} * * @author tiepi * @version $Id: Authz,v 1.2 2005/09/22 16:09:03 wangq Exp $ * */ public interface Authz { /** * return the principal's name, supports the various type of principals that * can exist in the {@link Authentication} object, such as a String or * {@link UserDetails} instance * * @return string representation of principal's name */ public String getPrincipal(); /** * return true if the principal holds either permission specified for the provided * domain object * * <P> * Only works with permissions that are subclasses of {@link * net.sf.acegisecurity.acl.basic.AbstractBasicAclEntry}. * </p> * * <p> * For this class to operate it must be able to access the application context * via the <code>WebApplicationContextUtils</code> and locate an {@link * AclManager}. * </p> * @param domainObject - domain object need acl control * @param permissions - comma separate integer permissions * @return got acl permission (true|false) */ public boolean hasPermission(Object domainObject, String permissions); /** * all the listed roles must be granted to return true, otherwise fasle; * @param roles - comma separate GrantedAuthoritys * @return granted (true|false) */ public boolean allGranted(String roles); /** * any the listed roles must be granted to return true, otherwise fasle; * @param roles - comma separate GrantedAuthoritys * @return granted (true|false) */ public boolean anyGranted(String roles); /** * none the listed roles must be granted to return true, otherwise fasle; * @param roles - comma separate GrantedAuthoritys * @return granted (true|false) */ public boolean noneGranted(String roles); /** * get Spring application context which contains acegi related bean */ public void setAppCtx(ApplicationContext appCtx); /** * set Spring application context which contains acegi related bean */ public ApplicationContext getAppCtx(); }


