Mar 2nd, 2007, 02:45 PM
Acegi method security & Command pattern
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">
The roles are setup in the security advice:
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.
Mar 5th, 2007, 08:54 AM
Does my question have any sense that nobody replied?
Mar 5th, 2007, 12:18 PM
Where abouts is the code is the problem you are facing?
Mar 5th, 2007, 03:23 PM
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:
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.
Mar 5th, 2007, 03:43 PM
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.
Mar 5th, 2007, 03:55 PM
Not a problem, glad to help! If you want to understand this more, the reference manual should help.
Mar 6th, 2007, 02:45 AM
Thank you for this link. That knowledge may have saved me some trouble for my future Acegi stuff.
Mar 6th, 2007, 08:15 AM
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 .