Home All Groups Group Topic Archive Search About

Emulating the [PrincipalPermissionAttribute ...] attribute

Author
21 Apr 2005 1:30 PM
Oriane
Hi,

I use the Enterprise Library, and the custom rule provider. A rule is check
with this piece of code:

public void HireEmployee (....) {
    string rule = "Hire Employee";
     // The next line fetch the rule definition in a config file, and checks
it with the role the object "myPrincipal" belongs to.
    if (! this.ruleProvider.Authorize (this.myPrincipal, rule))  {
        MessageBox.Show ("Youe are not authorise to hire en employee");
        return;
    }
     ... // plenty of interesting lines
}
____________________________________________________________________________
____
I would like to have this style of code:
[PrincipalRuleAttribute Name="Hire Employee"]
public void HireEmployee (....) {

    ... // plenty of interesting lines
}

In that case, if a call is made to "HireEmployee", a security exception is
thrown...

I know only the basics of the Attribute class, and I don't really see what
to do...

Oriane

Author
21 Apr 2005 2:10 PM
Dominick Baier [DevelopMentor]
Hello Oriane,

you have to implement a custom permission to accomplish that -

maybe this is a starting point
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/HTCustEncr.asp


---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com

Show quoteHide quote
> Hi,
>
> I use the Enterprise Library, and the custom rule provider. A rule is
> check with this piece of code:
>
> public void HireEmployee (....) {
> string rule = "Hire Employee";
> // The next line fetch the rule definition in a config file, and
> checks
> it with the role the object "myPrincipal" belongs to.
> if (! this.ruleProvider.Authorize (this.myPrincipal, rule))  {
> MessageBox.Show ("Youe are not authorise to hire en
> employee");
> return;
> }
> ... // plenty of interesting lines
> }
> ______________________________________________________________________
> ______
> ____
> I would like to have this style of code:
> [PrincipalRuleAttribute Name="Hire Employee"]
> public void HireEmployee (....) {
> ... // plenty of interesting lines
> }
> In that case, if a call is made to "HireEmployee", a security
> exception is thrown...
>
> I know only the basics of the Attribute class, and I don't really see
> what to do...
>
> Oriane
>
Author
21 Apr 2005 2:16 PM
Oriane
OK.

Thank you.


"Dominick Baier [DevelopMentor]" <dbaier@pleasepleasenospamdevelop.com>
wrote in message news:288289632496929039837184@news.microsoft.com...
> Hello Oriane,
>
> you have to implement a custom permission to accomplish that -
>
> maybe this is a starting point
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/HTCustEncr.asp
Show quoteHide quote
>
>
> ---------------------------------------
> Dominick Baier - DevelopMentor
> http://www.leastprivilege.com
>
> > Hi,
> >
> > I use the Enterprise Library, and the custom rule provider. A rule is
> > check with this piece of code:
> >
> > public void HireEmployee (....) {
> > string rule = "Hire Employee";
> > // The next line fetch the rule definition in a config file, and
> > checks
> > it with the role the object "myPrincipal" belongs to.
> > if (! this.ruleProvider.Authorize (this.myPrincipal, rule))  {
> > MessageBox.Show ("Youe are not authorise to hire en
> > employee");
> > return;
> > }
> > ... // plenty of interesting lines
> > }
> > ______________________________________________________________________
> > ______
> > ____
> > I would like to have this style of code:
> > [PrincipalRuleAttribute Name="Hire Employee"]
> > public void HireEmployee (....) {
> > ... // plenty of interesting lines
> > }
> > In that case, if a call is made to "HireEmployee", a security
> > exception is thrown...
> >
> > I know only the basics of the Attribute class, and I don't really see
> > what to do...
> >
> > Oriane
> >
>
>
>