Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Dynamic Links Based on Definitions in AppContext file

  1. #1

    Default Dynamic Links Based on Definitions in AppContext file

    I would like to display links based on whether the user has permission to view the URL as defined in my AppContext file. I have already defined in my ApplicationContext the URLs and the roles that are permitted to see them in the objectDefinitionSource of the FilterSecurityInterceptor. I don't want to use the current Ageci taglibs because I have already defined if the user can go to that URL in the context file and want to keep this centralized.

    So basically I was wondering how I could write a tag which would do this:

    1. Take in a URL
    2. Get the GrantedAuthorities from the Authentication obj
    3. Lookup the URL in the objectDefinitionSource and get it's valid roles
    4. Compare the GrantedAuthorities to the URL's valid roles

    How do I get the objectDefinitionSource in my custom tag and consequently the ConfigAttributes?

    Thanks,

    Rexxe

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

    Default

    Could you use WebApplicationContextUtils.getRequiredWebApplicati onContext to obtain the executing application context and then the objectDefinitionSource bean?

  3. #3

    Default

    Ben,

    Once I get the ObjectDefinitionSource, how do I query it to get the correct URL's attributes?

    Here is what I have so far (my tag extends RequestContextAwareTag):

    Code:
    String resolvedURL = ExpressionEvaluationUtils.evaluateString("url", this.url, pageContext);
    Map beans = this.getRequestContext().getWebApplicationContext().getBeansOfType(FilterSecurityInterceptor.class);
    
    //Get the 1 FSI definition
    FilterSecurityInterceptor fsi = (FilterSecurityInterceptor) beans.values().iterator().next();
    
    //How do I do this??
    ConfigAttributeDefinition attr = fsi.obtainObjectDefinitionSource().getAttributes(Need FilterInvocation obj????)
                    
    
    if (attr != null) {
                Authentication auth = ((SecureContext) ContextHolder.getContext())
                        .getAuthentication();
                try {
                    fsi.getAccessDecisionManager().decide(auth, resolvedURL, attr);
                } catch (AccessDeniedException e) {
                    return SKIP_BODY;
                }
            }
    
            return EVAL_BODY_INCLUDE;
    --Rexxe

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

    Default

    Once you get the FilterSecurityInterceptor from the application context, use filterSecurityInterceptor.getObjectDefinitionSourc e(). This will return a FilterInvocationDefinitionSource, which is usually RegExpBasedFilterInvocationDefinitionMap or PathBasedFilterInvocationDefinitionMap depending on what the FilterInvocationDefinitionSourceEditor property editor setup when wiring the bean.

    The XXXFilterInvocationDefinitionMap has a getAttributes(Object) method, which delegates to lookupAttributes(FilterInvocation filterInvocation). You'll need to use this method. You will need to create a FilterInvocation containing the URL you are requesting configuration attributes for. Specifically, the XXXFilterInvocationDefinitionMap will call filterInvocation.getRequestUrl() to determine the URL, so ensure that you provide a mock ServletRequest that can provide the properties used in the FilterInvocation.getRequestUrl() method. The other mock objects needed by FilterInvocation (ie ServletResponse and FilterChain) can safely throw UnsupportedOperationException for all of their methods, as your XXXFilterInvocationDefinitionMap does not use them.

    Don't forget an ObjectDefinitionSource (which includes XXXFilterInvocationDefinitionMap) can return null from its getAttributes(Object) method if it cannot find configuration attributes for the secure object. So expect to handle this in your code.

  5. #5

    Default

    Ben,

    Got it to work, though it's kind of a hack since I had to create a DummyFilterChain object. But, nevertheless it works!

    Thanks again....

    --Rexxe

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

    Default

    I recent refactored out the MethodInvocation-related ObjectDefinitionSources to work with a java.lang.reflect.Method rather than MethodInvocation.

    We could do the same with the FilterInvocation-related objects. Instead of pass around a FilterInvocation, just pass a new object containing the getRequestUrl(). This would make implementations a lot cleaner, at risk of not exposing some HttpServletRequest property people may wish to consider in their ObjectDefinitionSource that is not already part of getRequestUrl(). Such people could always implement their own ObjectDefinitionSource that works with the FilterInvocation itself, like we presently do.

    As someone actually using this area of the code, how would you feel about this proposed refactoring? I personally think it would tidy things up and make it easier to implement the more common usage case you're addressing.

  7. #7

    Default

    I agree, I think it would definitely tidy things up and make it more generalized. It makes a lot more sense for me to just create an object with the getRequestUrl() method instead of creating an entire dummy FilterChain object just so I can create a FilterInvocation object so I can get at the ConfigAttributes.

    Very cool!

    --Rexxe

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

    Default

    I've just added to CVS the above refactoring. Views can now access the config attributes defined against FilterSecurityInterceptor simply via a String representation of the web request URL pattern.

  9. #9

    Default

    Awesome! Thanks.

  10. #10
    Join Date
    Oct 2005
    Posts
    1

    Default

    How do you create a dummy Filter Chain?

Similar Threads

  1. Replies: 5
    Last Post: Mar 17th, 2010, 04:32 AM
  2. Saving large files to a db using hibernate?
    By Dan Washusen in forum Data
    Replies: 10
    Last Post: Sep 20th, 2006, 12:18 PM
  3. Virtual Directories & Dynamic file creation
    By mrbuddylee in forum Web
    Replies: 0
    Last Post: Oct 4th, 2005, 03:36 PM
  4. Replies: 6
    Last Post: Apr 13th, 2005, 08:35 AM
  5. hsqldb: using file based db in WEB-INF dir
    By briankuhn in forum Data
    Replies: 4
    Last Post: Aug 24th, 2004, 04:59 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
  •