Hi NG
Please bear with me. I am battling a serious learning curve with both .Net and CSLA. I am using VB.Net2 and CSLA2.1
I am wanting to control Authorization Rules from my DB.
My table structure is along the lines of : Object|Role|CanAdd|CanGet|CanEdit|CanDelete.
I would like to be able to be able to load this structure on a perType basis, and read from a shared list instaed of hardcoding it into the CanXxxxObject() functions.
Regards
Des Norton
How many objects/records are we talking about? If the data is not going to hog too much memory, it may be feasible to try the following:
That's pretty much what I did. I created a SecurityManager class that loads/caches the relevant security detail at app startup. Then, it was just a matter of changing the authorization lookups as you mentioned...
private static System.Type OBJECT_TYPE = typeof(MyObjectType);
public static bool CanGetObject
{
get
{
return SecurityManager.CanGetObject(OBJECT_TYPE)
}
}
public static bool CanAddObject
{
get
{
return SecurityManager.CanAddObject(OBJECT_TYPE);
}
}
public static bool CanEditObject
{
get
{
return SecurityManager.CanEditObject(OBJECT_TYPE);
}
}
public static bool CanDeleteObject
{
get
{
return SecurityManager.CanDeleteObject(OBJECT_TYPE);
}
}
Only negative - I had to define the OBJECT_TYPE variable in each class, but that wasn't too painful. Might even be a better way of doing it with reflection...
- Mark
Izak/Mark
Thanks for the input. This seems quite workable.
However, authorised users will have the ability to modify the permissions. New instances of the app will automatically have the newest auth settings. What about existing instances of the app? They somehow need to be aware that the auth settings have changed.
Regards
De Norton
Thanks Izak
Perhaps I'm chasing my tail due to ignorance ... I have no problem with the caching of the list if an authorised user changes the auth settings, and then continues to use the app. What about another user that logged in before the changes were made. My understanding is that the 2 users are essentially using 2 different instances of the application.
Scenario ...
DB is corrupted(hacked?) and all users have View/Add/Edit/Delete rights to everything. BadBob user takes the oppertunity to start causing havoc with objects. Admin logs in and fixes auth settings, giving BadBob View only rights. Problem solved? Or does BadBob firts have to log off and log on again to refresh his auth settings form DB?
If BabBob has to log off/on I will need to add some sort of expiration policy to the AuthList ... After every x(Read from config) hits or y(Read from config) minutes (whichever comes first), call InvalidateCache().
Thanks
Des Norton
Yes, you'll need to invalidate the cache at some point if you want existing instances of the app to reflect changes that others have made. You might need extra code to ensure the application handles itself properly. For example, if you revoke GetObject() access for a person, but they have already have a screen up with the object that they no longer have access to, how should your application respond? Etc, etc...
That wasn't a big concern for me, so I didn't worry about it. Just as an FYI - Windows works the same way (not that it's necessarily a *good* thing). When you login, you get a "token" that specifies what rights you have. If you go into Active Directory and make security changes to a user account - for example, adding or removing the account from a security group, the user actually has to logoff and login back for those changes to take effect.
I load the object permissions into my SecurityManager at login, but authorization is performed throughout the lifetime of the application. However, since I never invalidate my security cache, it's basically working against a static list.
The problem you'll run into is *how* to invalidate the cache. If I'm on workstation #1 and change security permissions, how do I notify workstations #2-10 that they need to reload the security information? That gets a bit more complex and is beyond the scope of CSLA. You'd basically need a bi-directional channel that remains open between client/server so the server could send the notifications to all the clients. You could also implement some timer-based refresh, but with that approach, there is a possibility that an unauthorized request could slip through between the time that the security change was made and the time that the cache was invalidated.
However, each application should code to its needs. In the 15+ CSLA-based apps that I've rolled out over the last 5 years, only 3 were complex enough to warrant the need for DB-driven security. The rest are hard-coded (and have never changed). And the 3 apps I have where security is DB-driven? The object permissions tables for those apps have also never been changed or updated since being deployed. One - I think we did a bang-up job setting security during deployment, and 2) our business environment/rules are mature enough where they're not changing often.
Mark, Izak
Sorry about my disappearing act, but I'd forgtotten about a holiday that was booked and approved months ago.
I will definately be implementing a SecurityManager that is loaded at login, and valiadted against each time any object is accessed. I will be implementing a cache expiration policy which is controlled via config to allow the client to tweak it. I agree that most security implementations rarely change, if ever. However the client insists... So we will give them the ability to change the security policy on th efly, and set expiration plocies from the config.
Basically the cache wil invalidate itself after evry (X) reads, or (Y) minutes, whichever comes first.
Thanks again for you input.
Des Norton
OK a newbie here, so maybe I am off base, but could you not add a method the security manager class that checks the db for a "last update" of security policy tables. and if that time is more recent than the cached last update value, invalidate the cache.
I know that is a DB call for each security check, so it adds some overhead. Maybe you can do it everytime a "destructive" (delete, update that is not tracked in a history, etc) permission is cheked but only every so often on "read" permissions.
I know this thread is a little old without updates but I am looking through old message as I (might) need to implement this type of system.
Mike
Copyright (c) Marimer LLC