Re: Custom Compile Time Attributes?
- From: "Chris Newby" <Chris.Newby@xxxxxxxxxxxxxxxxxxx>
- Date: Wed, 9 Nov 2005 09:15:41 -0500
In fact, my plan is to throw an exception from the call to Authorize(). In
the code outline of my original post, I was just trying to make it clear
that the "inner" code of the method would not be run if the Authorize() call
failed (or literally in that case returned false).
My primary concern was not so much the logic of my authorization rules, but
instead how I declare the authorization rules in my code. Given the
following method:
public Customer GetCustomer( String Id )
{
... logic that gets an instance of Customer
}
To me, authorization rules don't necessarily have anything to do with the
logic of getting an instance of Customer, and therefore a method that looks
like:
public Customer GetCustomer( String Id )
{
if( Principal.Authorize( "GetCustomerAuthorizationRule" ) )
{
... logic that gets an instance of Customer
}
}
Now has two purposes instead of just one ... authorization and Customer
object logic. In short, it's a bit less elegant than:
[AuthorizationRule( "GetCustomerAuthorizationRule" )]
public Customer GetCustomer( String Id )
{
... logic that gets an instance of Customer
}
<sarin.rajendran@xxxxxxxxx> wrote in message
news:1131512915.773118.308140@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Wouldn't it be more appropriate to throw a NotAuthorized Exception from
> your AuthorizationRule class instead? - so that if the required
> authorization rules are not met then the code that requires
> authorization will not be executed (since the AuthorizationRule
> Attribute class will be instantiated before the method is executed).
>
> If you still need to continue further processing, then you should
> probably catch the NotAuthorized Exception in the method calling
> MethodRequiringAuthorization()
>
> Regards,
> Sarin.
>
.
- References:
- Custom Compile Time Attributes?
- From: Chris Newby
- Custom Compile Time Attributes?
- Prev by Date: Re: Sleeping thread problem when closing app
- Next by Date: Re: Custom Compile Time Attributes?
- Previous by thread: Custom Compile Time Attributes?
- Next by thread: Re: Custom Compile Time Attributes?
- Index(es):
Relevant Pages
|