| Visual Basic (Declaration) | |
|---|---|
<ObsoleteAttribute("Will be removed after 9/1/2012. Use Authenticator.Instance.Login instead.")> Public Overloads Function Login( _ Optional ByVal credential As ILoginCredential _ ) As Boolean | |
| Visual Basic (Usage) | Copy Code |
|---|---|
Dim instance As EntityManager Dim credential As ILoginCredential Dim value As Boolean value = instance.Login(credential) | |
| C# | |
|---|---|
[ObsoleteAttribute("Will be removed after 9/1/2012. Use Authenticator.Instance.Login instead.")] public bool Login( ILoginCredential credential ) | |
| C++/CLI | |
|---|---|
[ObsoleteAttribute("Will be removed after 9/1/2012. Use Authenticator.Instance.Login instead.")] public: bool Login( ILoginCredential^ credential ) | |
Parameters
- credential
- Login credentials
Return Value
A boolean indicating success or failure.| Exception | Description |
|---|---|
| System.InvalidOperationException | Connect() must be called before Login |
| IdeaBlade.EntityModel.LoginException | Login failure |
| C# | Copy Code |
|---|---|
// Sample showing Login, and implementation of IEntityLoginManager // Create an EntityManager - this will also do an implicit Connect(). EntityManager mgr = new DomainModelEntityManager(); // create a LoginCredential string userName = "demo"; string password = "demo"; string domain = "Earth"; LoginCredential credential = new LoginCredential(userName, password, domain); MessageBox.Show("Current user: " + System.Threading.Thread.CurrentPrincipal.Identity.Name); try { // "Login" to EntityServer mgr.Login(credential); // note change in current principal MessageBox.Show("Current user: " + System.Threading.Thread.CurrentPrincipal.Identity.Name); } catch (LoginException le) { MessageBox.Show(le.Message); } catch (EntityServerException ese) { MessageBox.Show("Login failed: " + ese.Message); } catch (Exception ex) { MessageBox.Show(ex.Message); } //..... Retrieve data, etc. // Now logout mgr.Logout(); // Sample LoginManager class public class LoginManager : IEntityLoginManager { public LoginManager() {} public IPrincipal Login(ILoginCredential pCredential, EntityManager pManager) { // note that Login runs on server-side -- this will return false bool isClient = pManager.IsClient; // You would normally validate the credentials, eg against a database, AD, etc, and then // build and return an object implementing IPrincipal. if (pCredential.Domain != "Earth") { throw new LoginException(LoginExceptionType.InvalidUserName, pCredential.Domain, pCredential.UserName); } // We'll just return a GenericPrincipal GenericIdentity identity = new GenericIdentity(pCredential.UserName); return new GenericPrincipal(identity, new String[] { "user" }); } public void Logout(IPrincipal principal, EntityManager entityManager) { // Use if logout processing is needed - eg, release resources, audit user logout } } | |
| Visual Basic | Copy Code |
|---|---|
' Sample showing Login, and implementation of IEntityLoginManager ' Create an EntityManager - this will also do an implicit Connect(). Dim mgr As EntityManager = new DomainModelEntityManager(); ' create a LoginCredential Dim userName As String = "demo" Dim password As String = "demo" Dim domain As String = "Earth" Dim credential As New LoginCredential(userName, password, domain) MessageBox.Show(("Current user: " + System.Threading.Thread.CurrentPrincipal.Identity.Name)) Try ' "Login" to EntityServer mgr.Login(credential) ' note change in current principal MessageBox.Show(("Current user: " + System.Threading.Thread.CurrentPrincipal.Identity.Name)) Catch le As LoginException MessageBox.Show(le.Message) Catch pse As EntityServerException MessageBox.Show("Login failed: " + pse.Message) Catch ex As Exception MessageBox.Show(ex.Message) End Try '..... Retrieve data, etc. ' Now logout mgr.Logout() Public Class LoginManager : Implements IEntityLoginManager Public Sub New() End Sub Public Function Login(ByVal pCredential As ILoginCredential, ByVal pManager As EntityManager) As IPrincipal _ Implements IEntityLoginManager.Login ' note that Login runs on server-side -- this will return false Dim isClient As Boolean = pManager.IsClient ' You would normally validate the credentials, eg against a database, and then ' build and return an object implementing IPrincipal. If pCredential.Domain <> "Earth" Then Throw New LoginException(LoginExceptionType.InvalidUserName, pCredential.Domain, pCredential.UserName) End If ' We'll just return a GenericPrincipal Dim identity As New GenericIdentity(pCredential.UserName) Return New GenericPrincipal(identity, New [String]() {"user"}) End Function Public Sub Logout(ByVal principal As IPrincipal, ByVal entityManager As EntityManager) '' Use if logout processing is needed - eg, release resources, audit user logout End Sub End Class | |
You can pass a null (Nothing in Visual Basic) in place of an ILoginCredential object. Null credentials can indicate either that the user is logging in as a guest or anonymous user, or when using the AspAuthenticatingLoginManager that the current authenticated user should be loaded. When using ASP.NET the current authenticated user is one authenticated via Windows authentication, or is the user already logged in because of either a persistent cookie or a login performed elsewhere in the ASP.NET application. If you are not using the AspAuthenticationLoginManager then your implementation of IEntityLoginManager should handle a null credential if your client application can provide one.
The AllowAnonymousLogin flag in the IdeaBlade configuration determines whether "anonymous" users can login to your application. Anonymous users are ones who have not supplied credentials and who also cannot be authenticated by other means, such as ASP.NET authentication.
Call Login to validate the user after calling Connect and before calling any other EntityManager functions. This call does not cause a connection to any backend data source, nor does it maintain an open conversation with the EntityServer.
If EntityManagerOptions.UseDefaultAuthenticationContext is true, the Login call will set the IdeaBlade.EntityModel.Security.Authenticator.DefaultAuthenticationContext, otherwise the AuthenticationContext is set.
Credentials are passed in clear text. Use a secure channel (such as SSL) or provide your own encryption if secure communications are necessary.
Note that a IdeaBlade.EntityModel.LoginException will be thrown for bad credentials; false is not returned from this method.
Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family