Read Rule from Database (Security Block)

Topics: Building and extending application blocks, Enterprise Library Core, Security Application Block
Jul 10, 2007 at 8:37 AM
I have read the sample from Enterprise library and the sample is good.

However, the rule are stored under the app.config. If I want to store in DB which allows my applicaiton administrator to modify the access right. How could I do it?

Thanks
Alex
Jul 11, 2007 at 12:22 PM
Hi Alex,

I assume you're talking about the AuthorizationRuleProvider. If you want to store the rules themselves on the database you'll need to write your own provider, based on the existing one . Unfortunately you will not be able to leverage the existing implementation by inheriting from it, but on the bright side most of the complex logic, like parsing the expressions, is factored out of the provider class.

Here's a short list of what you'd need to do:
  • Create your provider class based on AuthorizationRuleProvider. It will likely receive a Database object as a constructor parameter, and instead of looking for the rule on a dictionary it will query the database (or cache the rules during construction).
  • Create the configuration support for your provider. You should clone the objects related to the AuthorizationRuleProvider; in the case of the configuration object, you'll likely have a reference to a database.

The Application Block Factory will take care of most of the heavy lifting for you, including creating the design time support classes, you investing some time learning to use it might pay off for you.

Hope this helps,
Fernando
Sep 6, 2007 at 9:26 PM
hey Alex,

i have the same issue. did you ever get around to doing what Fernando recommended or other solution?

tom
Sep 8, 2007 at 7:41 AM
Hi Tom

I have use another approach but not create the provider. Please see the link below.

If you need more information. Please let me know.

http://www.codeplex.com/websf/Thread/View.aspx?ThreadId=14757

Regards
Alex
http://princechan.blogspot.com
Sep 10, 2007 at 3:34 PM
thanks Alex. was hoping someone out there already had an example of this but i will take a look at it.

thanks,
Tom