Results 1 to 4 of 4

Thread: Protecting Web resources using a custom voter

  1. #1
    Join Date
    Nov 2004
    Location
    Dallas, TX (USA)
    Posts
    58

    Default Protecting Web resources using a custom voter

    I needed to protect access to web resources (project information in this case) to only projects a user was assigned to. I created a voter that looks something like:
    Code:
      public int vote(Authentication authentication, Object object, ConfigAttributeDefinition config)
      {
        if ((object == null) || !this.supports(object.getClass()))
        {
          throw new IllegalArgumentException("Does not support the presented Object type");
        }
    
        FilterInvocation invocation = (FilterInvocation) object;
        HttpServletRequest request = invocation.getHttpRequest();
        String username = authentication.getPrincipal().toString();
    
        int result = ACCESS_ABSTAIN;
    
        Iterator iter = config.getConfigAttributes();
    
        while (iter.hasNext())
        {
          ConfigAttribute attribute = (ConfigAttribute) iter.next();
          if (this.supports(attribute))
          {
            String projectId = null;
            projectId = request.getParameter(PROJECT_ID_PARAM);
            if (projectId != null)
            {
              result = ACCESS_DENIED;
              if (getAdminService().isProjectAssigned(username, projectId))
              {
                return ACCESS_GRANTED;
              }
            }
          }
        }
        return result;
      }
    I wired this in front of the role based voter in a UnanimousBased approach. This works great but I was wondering if ACL's would be better. FWIW, I used the above to replace a method intercept based approach I used earlier.
    Sleep is for the weak

  2. #2
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    Your voter seems a good approach, although I would probably have done it at a method level. Whether an AccessDeniedException is generated because of a web filter authorisation failure or a services layer authorisation failure typically is of little importance - they're both handled by Acegi Security the same way. Doing it at a method level allows better assurance your authorisations will take place, as it tolerates web application restructures etc (renames of classes on your services methods on the other hand are detected as missing classes at MethodSecurityInterceptor startup time).

    The Acegi Security ACL services might prove a better fit if you want to also control (or may want to control in the future) other aspects of domain object security, such as managing creation, edit, delete permissions etc. If the ACL securiity was limited to just access granted or access denied for a single domain object, and that could be accommodated solely through your voter, the ACL security is probably overkill as you also need to maintain the two separate ACL tables. When in doubt I'd probably use the ACL security, as it's better OO to not have the security information within the project and it accommodates future needs without any difficulty.

  3. #3
    Join Date
    Nov 2004
    Location
    Dallas, TX (USA)
    Posts
    58

    Default

    Thanks for your inputs Ben (and your amazing framework).
    I'll ponder the ACL stuff and play around with it some. I agree on the method interceptor approach but felt like I was mixing approaches. I am using the stock role voter via filter interceptor and wanted to keep everything in the filter intercept family. Pretty easy to switch around (IOC + Acegi's flex) regardless. This stuff is amazing 'cus there are so many ways to succeed. How often do you hear that today...
    Sleep is for the weak

  4. #4
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    Quote Originally Posted by dhainlin
    Pretty easy to switch around (IOC + Acegi's flex) regardless. This stuff is amazing 'cus there are so many ways to succeed. How often do you hear that today...
    Very often in anything to do with Spring! People using stock-standard J2EE don't know what they're missing.... :-)

Similar Threads

  1. Replies: 2
    Last Post: Sep 1st, 2009, 09:24 AM
  2. Using Custom Tags with Spring
    By CaptainMu in forum Web
    Replies: 7
    Last Post: Jul 7th, 2008, 07:00 AM
  3. Replies: 2
    Last Post: Aug 2nd, 2006, 10:18 PM
  4. Replies: 3
    Last Post: Nov 15th, 2005, 03:24 PM
  5. custom init with command binding ?
    By ultan in forum Web
    Replies: 0
    Last Post: Oct 17th, 2005, 12:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •