Verification (authentication) and Authorization (Authorization) (i):

Source: Internet
Author: User

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):

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.