Results 1 to 8 of 8

Thread: Acegi method security & Command pattern

  1. #1
    Join Date
    Jan 2007
    Posts
    14

    Default Acegi method security & Command pattern

    Hi,

    I have a set of Command classes implementing a ICommand interface (with an execute method).
    Now, I want to enable role based authorization on the execute method of each command.
    I have setup my security advice, and added it to my autoproxy bean:
    <bean class="org.springframework.aop.framework.autoproxy .BeanNameAutoProxyCreator">
    <property name="beanNames"><value>*Service</value></property>
    <property name="interceptorNames">
    <list>
    <value>commandSecurityAdvice</value>
    </list>
    </property>
    </bean>

    The roles are setup in the security advice:
    ...
    <property name="objectDefinitionSource">
    <value>
    command1.execute=ROLE_SUPERVISOR
    command2.execute=ROLE_SUPERVISOR
    command3.execute=ROLE_USER,ROLE_SUPERVISOR
    </value>
    </property>
    ...

    ACEGI is evaluating my secured object (the command) as an ICommand object and therefore would not match any role.

    In the ACEGi code, it is only checked against interfaces. So what would be the right approach in my case?
    I would like to avoid setting a security advice for each command.

    Thanks

    Xavier

  2. #2
    Join Date
    Jan 2007
    Posts
    14

    Default

    Does my question have any sense that nobody replied?

    Xav.

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    Where abouts is the code is the problem you are facing?

  4. #4
    Join Date
    Jan 2007
    Posts
    14

    Default

    The ACEGI code that causes me a problem is the one that tries to match the interface of my secured object with the objectDefinitionSource.
    The code is in MethodDefinitionMap.lookupAttributes(Method).
    It is coded to match the method of my secured object to a method of an interface:
    Class[] interfaces = method.getDeclaringClass().getInterfaces();

    in my case, even though my class Command1 implements ICommand (with an execute method), I want to be able to specify in the objectDefinitionSource:
    Command1.execute=ROLE_USER
    But this would match nothing because of the getInterfaces().

    I am no saying there is a problem in the lookupAttributes method but rather am asking if there is another way to achieve that: assigning ROLEs to methods defined on classes implementing the same interface.

    X.

  5. #5
    Join Date
    Jan 2007
    Posts
    14

    Default

    Cool, wow it works by specifying the following in my BeanNameAutoProxyCreator:

    <property name="proxyTargetClass" value="true" />

    That uses now the implementation class, not the interface.

    Thanks for the help.

    X.

  6. #6
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    Not a problem, glad to help! If you want to understand this more, the reference manual should help.
    http://www.springframework.org/docs/...l#aop-proxying

  7. #7
    Join Date
    Feb 2007
    Posts
    26

    Default

    Thank you for this link. That knowledge may have saved me some trouble for my future Acegi stuff.

  8. #8
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    If in doubt it's always worth while having a read of the reference manual! It saves many hours of frustration and pulling your hair out .

Posting Permissions

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