AuthenticationProvider instantiation problem

Topics: Security Application Block
Dec 2, 2008 at 3:51 PM
Hi. I am trying to use custom AuthenticationProvider which will authenticate with rules stored in database. I have created new DLL project and within it a new class ( MyAuthenticationProvider ) that implements required interface. From source code of AuthorizationRuleProvider i copied almost everything but i added in constructor code to populate rules list from D . In AuthorizationRuleProvider source code that list was passed as parameter to constructor. Here is my App.config  that references DLL named Autorizacija with MyAuthenticationProvider class.

  <securityConfiguration defaultAuthorizationInstance="MyAuthorizationProvider" defaultSecurityCacheInstance="">
      <add type="Autorizacija.MyAuthorizationProvider, Autorizacija" name="MyAuthorizationProvider" />

Problem is when i try to instantiate a my provider with code 

IAuthorizationProvider ruleProvider = AuthorizationFactory.GetAuthorizationProvider("MyAuthorizationProvider");
IAuthorizationProvider ruleProvider = AuthorizationFactory.GetAuthorizationProvider();

returned provider is of type AuthorizationRuleProvider (????). Currently i am solving problem with code 

IAuthorizationProvider ruleProvider = new Autorizacija.MyAuthorizationProvider(); 

which works fine and that way i can successfuly authorize actions from database rules list - so the problem (as i see it) is not in the class.

Is anyone had similiar problem, and/or how did you solve it?


Dec 3, 2008 at 3:12 AM
Did you add a constructor in your MyAuthorizationProvider class accepting a NameValueCollection?

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
Dec 3, 2008 at 3:14 AM
No i didn't. I made a parameterless constructor and within it i query
the database to get rules.
Dec 3, 2008 at 3:21 AM
Edited Dec 3, 2008 at 3:23 AM
You should.  Didn't you get any buildfailed exception?  I actually made that mistake before, I only have a parameterless constructor and I was getting a buildfailed exception saying that it cannot find the constructor for my custom authorization provider.
It's actually in the documentation.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
Dec 3, 2008 at 3:23 AM
Ill try it now. But no, there are no errors, nor compile time nor
runtime. Just when calling factory method it returns
Dec 3, 2008 at 3:28 AM
I just tried to add

public MyAuthorizationProvider(IDictionary<string, IAuthorizationRule>

constructor but same problem.
IAuthorizationProvider ruleProvider2 =
always return AuthorizationRuleProvider.
Dec 3, 2008 at 4:07 AM
You should use the NameValueCollection  type. 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.