Upgrading from 1.x to 2.x BusinessPrincipal.Login

Upgrading from 1.x to 2.x BusinessPrincipal.Login

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


Craig Douglas posted on Monday, October 22, 2007

Hi,

I've inherited an app that's written in 1.x and I am part-way through upgrading it to 2.x, 

I've come across the use of: BusinessPrincipal.Login()

I'm not sure how to upgrade this method and can't see something that directly replaces it.

What's the best way of upgrading this and how much work does this feel like?

Thanks.

Craig

PS.  Great Book!

 

 

 

 

Craig Douglas replied on Tuesday, October 23, 2007

I should probably add into the thread, that the application has alrady been deployed for a few years and now has had users registered on it, so it's not a new-build application.

What I need to a way to upgrade that preserves these users signin information such that the new version is is as transparent to the users as it can be.

I'm not really sure how BusinessPrincipal.Login works in 1.x.  (Does it provide a usernmame / password system?? )

Thanks

Craig

 

JoeFallon1 replied on Tuesday, October 23, 2007

Hi,

In CSLA 1.x in a class named MyUser (copied from BusinessPrincipal, not inherited) you would have a Login method like this:

Public Shared Sub Login(ByVal Username As String, ByVal Password As String)
 
Dim p As New MyUser(Username, Password)
End Sub

The constuctor of the class includes code like this:

Private Sub New(ByVal Username As String, ByVal Password As String)
  SetThread()
  mIdentity = MyBusinessIdentity.LoadIdentity(Username, Password)
End Sub

Private Sub SetThread()

Dim currentdomain As AppDomain = Thread.GetDomain
currentdomain.SetPrincipalPolicy(PrincipalPolicy.UnauthenticatedPrincipal)
Dim OldPrincipal As IPrincipal = Thread.CurrentPrincipal
Thread.CurrentPrincipal =
Me

Try
  If Not TypeOf OldPrincipal Is MyUser Then
   
currentdomain.SetThreadPrincipal(Me)
 
End If
Catch
 
'failed, but we don't care because there's nothing we can do in this case.
End Try

End Sub

===========================================================

In CSLA 2.x it looks more like this:

<Serializable()> _
Public Class MyUser
 
Inherits Csla.Security.BusinessPrincipalBase

Public Shared Function Login(ByVal username As String, ByVal password As String) As Boolean
 
Dim identity As MyBusinessIdentity = MyBusinessIdentity.GetIdentity(username, password)
 
Dim principal As New MyUser(identity)
  Csla.ApplicationContext.User = principal
 
Return identity.IsAuthenticated
End Function

Private Sub New(ByVal identity As IIdentity)
 
MyBase.New(identity)
End Sub

Joe

Craig Douglas replied on Wednesday, October 24, 2007

Thanks Joe.

I've got the app to compile and allow me to login.

Basically I did the following:

Lift Security.PTPrincipal  and Security.PTIdentity from the project tracker example and re-name and namespace them to suit.

Change references in my Login class [MyUser] to BusinessPrincipal.Login(user, password, connection string) to Security.PTPrincipal(user, password)

Updated the connection string used by PTPrincipal to use my connection string.

I guess I've not changed anything by ideology, but hopefully the custom?? lockout logic will still work as before.

The class I have here 'login.cs' (inherited from BusinessBase) seems to have quite a bit of aditional code and would probably take quite a bit of thought to refactor, so I'll leave it at that for now!

Craig

 

 

 

 

 

Copyright (c) Marimer LLC