Question about Principal Objects (Need some advice )

Question about Principal Objects (Need some advice )

Old forum URL: forums.lhotka.net/forums/t/1176.aspx


RangerGuy posted on Sunday, September 10, 2006

I found a post regarding a custom principal today but now I don't seem to be able to track it down. I need to implement IsInRole that
excepts an int not string as a parameter. Also, I need a method that will check for a specific right. I did the following in BusinessPrincipalBase

public virtual bool RoleHasPermission(int roleid, int permissionid)
{
return false;
}
public virtual bool IsInRole(int role)
{
return false;
}


Then I implemented the above methods in my PTPrincipal object. I found the only way I can see them is by casting the User to
MyCustomPrincipal is that correct?

((MyCustomPrincipal)Csla.ApplicationContext.User).IsInRole(1)

guyroch replied on Sunday, September 10, 2006

Yep, you have to cast it!  The reason is that the current IsInRole(string role) method come directly from the IPrincipal interface.  Csla.ApplicationContext.User is an instance of IPrincipal and not your BusinessPrincipalBase which contains your addtional methods.

 

RangerGuy replied on Sunday, September 10, 2006

Thank you sir :) I take it this is common practice if you need added functionality? It seems silly that MS would make that method only except a string. They gotta know that alot of applications especially web apps have their security model database driven. Anyways it works great! :) Thanks for the help!

figuerres replied on Monday, September 11, 2006

RangerGuy:
Thank you sir :) I take it this is common practice if you need added functionality? It seems silly that MS would make that method only except a string. They gotta know that alot of applications especially web apps have their security model database driven. Anyways it works great! :) Thanks for the help!

well think of it like this: 

.Net is a framework, they gave us one set of interfaces and base classes.

they work for many apps, and we can extend them with our own derived classes as we see fit.

how many versions could MSFT have made  ? Guid, LongInt,ShortInt,Double, and who knows ?

they did the quick and simple one and left the others for us to play with. Smile [:)]

Copyright (c) Marimer LLC