|
From: Keith D. <kd...@cs...> - 2004-03-10 20:18:02
|
I was browsing Ben and Cameron's new security stuff (looks great) and I =
like
how they did the attribute markup for the security roles required for
certain methods:
=20
/**
* @@SecurityConfig("ROLE_TELLER")
* @@SecurityConfig("ROLE_SUPERVISOR")
* @@SecurityConfig("BANKSECURITY_CUSTOMER")
* @@SecurityConfig("RUN_AS_SERVER")
*/
public float getBalance(int id);
Specifically, I like how they didn't use a qualified class name, which =
makes
the attribute more compact & easier to type out. Also I liked how they =
went
with a generic "SecurityConfig" attribute. I was thinking of applying
something similiar to the validator attributes markup. So instead of
instantating the rule classes directly, you just instantiate a
ValidationRule attribute metadata class, with a String identifier for =
the
rule, and then a string list for any rule-specific properties. =
Something
like this:
=20
/**
* @@ValidationRule("required")
* @@ValidationRule("range", "minimum=3D0.0, maximum=3D100,000.0")
*/
public float getBalance(int id);
The question I have regarding this is with commons-attributes:
=20
1. Does it let you instantiate arbitrary objects using their =
constructors
within an attribute declaration? For example, can I say something like:
* @@ValidationRule("range", new NumberRange(0.0, 100,000.0))?
Somehow I doubt it, but I was curious how extensive its support was for
instantating objects declared as attributes (I mean obviously it can =
handle
Strings, but does it do type conversion too?)
=20
What I am thinking abut doing is just having something like this:
* @@ValidationRule("range", "minimum=3D0.0, maximum=3D100,000.0")
.. where the first parameter is a String identifier for the rule, whose
backing PropertyValidationRule instance is looked up using a rule =
factory
configured by Spring, and the second parameter is a string-separated =
list of
bean property->value pairs where I'll likely just use BeanWrapper or =
OGNL
later on...
=20
Keith
|
|
From: Cameron B. <ca...@da...> - 2004-03-10 23:51:08
|
First of all a short description of commons attributes :
Commons attributes is quite flexable because it converts the attribute
declarations into a source class, which you then compile with your
application.
This allows you to use any java code in the declaration of the attribute.
The technique for not using the fully qualified class name is to specify all
package imports in the attributes-compiler ant task call.
For Example : the SecurityConfig class exists in the
au.acegi.springsecurity.attribute packge therefore the ant task call is :
<taskdef name='attribute-compiler'
classname="org.apache.commons.attributes.compiler.AttributeCompiler"
classpathref="attribute-compiler-classpath"/>
<attribute-compiler destdir="generated"
attributePackages="au.acegi.springsecurity.attribute">
<fileset dir="java"/>
</attribute-compiler>
An extract of the generated code for that getBalance method is :
import au.acegi.springsecurity.attribute.*;
public class BankService$__attributeRepository implements
org.apache.commons.attributes.AttributeRepositoryClass {
---stripped for brevity---
private void initClassAttributes () {
{
SecurityAttribute _attr = new SecurityAttribute("ROLE_TELLER" //
D:/workspace3/acegi-attributes/sample/java/BankService.java:10
);
Object _oattr = _attr; // Need to erase type information
if (_oattr instanceof org.apache.commons.attributes.Sealable)
{((org.apache.commons.attributes.Sealable) _oattr).seal ();}
classAttributes.add ( _attr );
}
---stripped for brevity---
}
so you can see that it basically treats the @@ declaration as a java
constructor call, with one exception.. it converts named values in to bean
property setters.
i.e
@@RoleConstraint(role="ROLE_TELLER")
This will generate code like :
RoleConstraint _attr = new RoleConstraint();
_attr.setRole("ROLE_TELLER")
Also notice that your attribute classes can implement Sealable which means
that their seal() method gets called when they get initialised, allowing you
to do some initialisation.
Therefore to answer your question ;) you can use any java class, as long as
you either fully qualify it, or include the package in the compiler task.
I suggest that you avoid using the same attribute class for all rules, and
instead use a type hierarchy :
For example instead of using
@@ValidationRule("range", "minimum=0.0, maximum=100,000.0")
Have a RangeValidationRule class and do this :
@@RangeValidationRule(minimum=0.0, maximum=100000.0)
I think this is better than
@@ValidationRule("range", new NumberRange(0.0, 100,000.0))
Cameron.
_____
From: spr...@li...
[mailto:spr...@li...] On Behalf Of
Keith Donald
Sent: Thursday, 11 March 2004 6:00 AM
To: spr...@li...
Subject: [Springframework-developer] commons attributes questions
I was browsing Ben and Cameron's new security stuff (looks great) and I like
how they did the attribute markup for the security roles required for
certain methods:
/**
* @@SecurityConfig("ROLE_TELLER")
* @@SecurityConfig("ROLE_SUPERVISOR")
* @@SecurityConfig("BANKSECURITY_CUSTOMER")
* @@SecurityConfig("RUN_AS_SERVER")
*/
public float getBalance(int id);
Specifically, I like how they didn't use a qualified class name, which makes
the attribute more compact & easier to type out. Also I liked how they went
with a generic "SecurityConfig" attribute. I was thinking of applying
something similiar to the validator attributes markup. So instead of
instantating the rule classes directly, you just instantiate a
ValidationRule attribute metadata class, with a String identifier for the
rule, and then a string list for any rule-specific properties. Something
like this:
/**
* @@ValidationRule("required")
* @@ValidationRule("range", "minimum=0.0, maximum=100,000.0")
*/
public float getBalance(int id);
The question I have regarding this is with commons-attributes:
1. Does it let you instantiate arbitrary objects using their constructors
within an attribute declaration? For example, can I say something like:
* @@ValidationRule("range", new NumberRange(0.0, 100,000.0))?
Somehow I doubt it, but I was curious how extensive its support was for
instantating objects declared as attributes (I mean obviously it can handle
Strings, but does it do type conversion too?)
What I am thinking abut doing is just having something like this:
* @@ValidationRule("range", "minimum=0.0, maximum=100,000.0")
.. where the first parameter is a String identifier for the rule, whose
backing PropertyValidationRule instance is looked up using a rule factory
configured by Spring, and the second parameter is a string-separated list of
bean property->value pairs where I'll likely just use BeanWrapper or OGNL
later on...
Keith
|
|
From: Seth L. <se...@eh...> - 2004-03-11 00:08:07
|
> I suggest that you avoid using the same attribute class for all rules,
> and instead use a type hierarchy :
>
> For example instead of using
>
> @@ValidationRule("range", "minimum=0.0, maximum=100,000.0")
>
> Have a RangeValidationRule class and do this :
>
> @@RangeValidationRule(minimum=0.0, maximum=100000.0)
>
> I think this is better than
>
> @@ValidationRule("range", new NumberRange(0.0, 100,000.0))
Thanks Cameron! That was a great explanation.
I agree with Cameron on the above. I like a type hierarchy much better
than string identifiers. I'm not sure they buy us much, other than
another mapping configuration.
I'm glad to learn we can shorten the attribute declarations by leaving
off the package. Very nice!
Thanks,
Seth
|
|
From: Rod J. <rod...@in...> - 2004-03-11 00:18:05
|
> I'm glad to learn we can shorten the attribute declarations by leaving > off the package. Very nice! That was actually my suggestion, based on Mark's attrib4j. I also requested the support for JavaBean properties, to make it easier to use with Spring. Is anyone using Commons Attributes for declarative tx mgt (as in jPetStore /attributes)? Or the commons attributes handler mapping? Regards, Rod |
|
From: Seth L. <se...@eh...> - 2004-03-11 00:33:13
|
> Is anyone using Commons Attributes for declarative tx mgt (as in jPetStore > /attributes)? Not yet, though might when I start using Spring for txn management. > > Or the commons attributes handler mapping? Not yet, but will very shortly. I find that type of markup useful except for the view mappings. We develop some complicated workflows and the "success" view is calculated, so we can't predefine that. But the other types of attributes for a Controller will come in very handy. Are there some examples of the handler/controller attributes? Seth |
|
From: Rod J. <rod...@in...> - 2004-03-11 00:43:31
|
> Are there some examples of the handler/controller attributes? Look under metadata in the reference manual. There isn't (yet) an example in the sample apps. |
|
From: Cameron B. <ca...@da...> - 2004-03-11 01:31:18
|
Yeah, I am using commons attributes for transaction declaration. We have a system where we use a method name match transaction attribute source as the fallback, and allow declarations on at the method level to override these defaults, since most of the time the defaults work perfectly, and these defaults are defined per application anyway. Something like this in applicationContext.xml <bean id="commonsAttributes" class="org.springframework.metadata.commons.CommonsAttributes"/> <!-- transaction attribute source to provide a method name based map --> <bean id="attributesMatchMethodNamePattern" class="org.springframework.transaction.interceptor.NameMatchTransactionAttri buteSource"> <property name="properties"> <props> <!-- read only methods --> <prop key="list*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop> <!-- the default is transactional (least specific, match everything) --> <prop key="*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <bean id="attributesAttributeSource" class="org.springframework.transaction.interceptor.AttributesTransactionAttr ibuteSource"> <constructor-arg><ref bean="commonsAttributes"/></constructor-arg> </bean> <bean id="multiAttributeSource" class="transaction.interceptor.ListTransactionAttributeSource"> <property name="attributeSources"> <list> <ref bean="attributesAttributeSource"/> <ref bean="attributesMatchMethodNamePattern"/> </list> </property> </bean> > -----Original Message----- > From: spr...@li... > [mailto:spr...@li...] > On Behalf Of Rod Johnson > Sent: Thursday, 11 March 2004 10:00 AM > To: spr...@li... > Subject: Re: [Springframework-developer] commons attributes questions > > > I'm glad to learn we can shorten the attribute declarations > by leaving > > off the package. Very nice! > > That was actually my suggestion, based on Mark's attrib4j. I > also requested the support for JavaBean properties, to make > it easier to use with Spring. > > Is anyone using Commons Attributes for declarative tx mgt (as > in jPetStore /attributes)? > > Or the commons attributes handler mapping? > > Regards, > Rod > > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials Free > Linux tutorial presented by Daniel Robbins, President and CEO > of GenToo technologies. Learn everything from fundamentals to > system > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer > > |