Wierd authentication problem

Wierd authentication problem

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


GPhillips posted on Monday, April 23, 2007

I am using custom Csla authentication (with appropriate AppSettings in the App.config file) and I have created an inherited class from BusinessPrincipalBase and implemented an IIdentity Class.

The application has an MDI Form and a Login Form.  The MDI form does a ShowDialog on the login form in its Shown event that requests and validates the username and password.  It then sets the IPrincipal using Csla.ApplicationContext.User = mPrincipal and closes the login form.  The problem is that when I access Csla.ApplicationContext.User in the MDI form (or any Child forms) it is set to WindowsPrincipal, not my custom Principal.

If I set the MDIParent of the Login form to the MDI form and do a Show on it and log in that way, then Csla.ApplicationContext.User remains unaltered (the custom one).  I looked at the Thread numbers in Debug and the MDI form and the Login form both show the same thread #'s.

Any suggestions would be greatly appreciated.

RockfordLhotka replied on Tuesday, April 24, 2007

Is this VB or C#? VB has My.Application, which includes a setting as to whether you want to use Windows or custom authentication, and it may be automatically resetting the value if you are set to use Windows.

C# and VB both rely on the Thread object, and it in turn relies on a policy value that is set on the AppDomain. If that policy value is set to Windows authentication that could be your issue as well. I don't remember the method name, but it is off the AppDomain object and has something to do with principal policy.

GPhillips replied on Wednesday, April 25, 2007

Thanks for the response.  I hacked at it a lot of different ways and I think I have determined the problem.  For anyone else, here goes:

The application is written using VB.NET with the Application Framework turned on.  My MDI form is set as the start up form.  CSLA Authentication is set to Csla in the app.settings file.  Since the application requires the user be logged in and we wanted to show the login form on top of the MDI form, the login form was displayed in the Shown event of the MDI form for login.

To make a long story short, apparantly .NET sets the CurrentPrincipal AFTER the Shown event of the startup form has occurred, thus wiping out any Principal established during that event so the Csla login/Principal is replaced with whatever the default principal is.

Not a CSLA problem (which so far is a great template), but Windows wierdness.

Thanks again

Copyright (c) Marimer LLC