Authentication and authorization are implemented using the Iauthenticationfilter and Iauthorizationfilter interfaces provided by the ASP. The IIdentity and IPrincipal interfaces are used.
The specific type of iidentity is used to identify the user authenticated by the user credentials (credential) to create a user with the specified name.
Interface Definition:
Defines the basic functionality of the identity object.
public interface IIdentity
{
Gets the type of authentication used.
String AuthenticationType {get;}
Gets a value that indicates whether the user is authenticated.
BOOL IsAuthenticated {get;}
Gets the name of the current user
String Name {get;}
}
Different authentication types have different implementations for IIdentity. such as: WindowsIdentity (Windows Integration), FormsIdentity (Forms), and GenericIdentity (general users).
If the custom implementation validates, the user identity can be identified by using GenericIdentity, and the authenticated user is a genericidentity with the specified name.
GenericIdentity type definition:
public class Genericidentity:claimsidentity
{
Initializes the System.Security.Principal.GenericIdentity using the specified System.Security.Principal.GenericIdentity object
A new instance of the class.
Protected GenericIdentity (GenericIdentity identity);
Initializes a new instance of the System.Security.Principal.GenericIdentity class that represents the user with the specified name.
Public GenericIdentity (string name);
Initializes a new instance of the System.Security.Principal.GenericIdentity class that represents the user with the specified name and authentication type.
Public GenericIdentity (string name, String type);
Gets the type of authentication used to identify the user.
public override string AuthenticationType {get;}
Get all the claims represented by this most common identity for the user.
public override ienumerable<claim> Claims {get;}
Gets a value that indicates whether the user is authenticated.
public override bool IsAuthenticated {get;}
Gets the name of the user.
public override string Name {get;}
Creates a new object as a copy of the current instance.
public override Claimsidentity Clone ();
}
The specific type of IPrincipal represents an object that has been authenticated and authorized.
Interface Definition:
public interface IPrincipal
{
Gets the identity of the current user.
IIdentity Identity {get;}
Determines whether the current user belongs to the specified role.
BOOL IsInRole (string role);
}
The GenericPrincipal type, initialized with an array of user identities and role names.
public class Genericprincipal:claimsprincipal
{
Initializes the System.Security.Principal.GenericPrincipal from the user ID and the role name Array (the identity represented by the user belongs to the array)
A new instance of the class.
Public GenericPrincipal (IIdentity identity, string[] roles);
Gets the System.Security.Principal.GenericIdentity of the user currently represented by the System.Security.Principal.GenericPrincipal.
public override IIdentity Identity {get;}
Determines whether the current System.Security.Principal.GenericPrincipal belongs to the specified role.
public override bool IsInRole (string role);
}
Verification (authentication) and Authorization (Authorization) (i):