Interface for server-side user authentication.
Syntax
| Visual Basic (Declaration) | |
|---|
<InterfaceExportAttribute(ContractName="", ContractType=IdeaBlade.EntityModel.IEntityLoginManager)>
Public Interface IEntityLoginManager |
| C# | |
|---|
[InterfaceExportAttribute(ContractName="", ContractType=IdeaBlade.EntityModel.IEntityLoginManager)]
public interface IEntityLoginManager |
| C++/CLI | |
|---|
[InterfaceExportAttribute(ContractName="", ContractType=IdeaBlade.EntityModel.IEntityLoginManager)]
public interface class IEntityLoginManager |
Example
| 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 |
Remarks
Requirements
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
See Also