C# Class BlogEngine.Core.Security

Class to provide a unified area of authentication/authorization checking.
Inheritance: IHttpModule
Show file Open project: rasmuskl/ReSharperCourse Class Usage Examples

Public Methods

Method Description
AuthenticateUser ( string username, string password, bool rememberMe ) : bool
CurrentUserRights ( ) : IEnumerable

Returns an IEnumerable of Rights that belong to the ecurrent user.

DemandUserHasRight ( AuthorizationCheck authCheck, bool redirectIfUnauthorized ) : void

If the current user does not have the requested rights, either redirects to the login page, or throws a SecurityException.

DemandUserHasRight ( Rights right, bool redirectToLoginPage ) : void

If the current user does not have the requested right, either redirects to the login page, or throws a SecurityException.

Dispose ( ) : void

Disposes of the resources (other than memory) used by the module that implements T:System.Web.IHttpModule.

GetCurrentUserRoles ( ) : string[]

Helper method that returns the correct roles based on authentication.

ImpersonateUser ( string username, string password ) : bool

Impersonates a user for the duration of the HTTP request.

Init ( System.Web.HttpApplication context ) : void

Initializes a module and prepares it to handle requests.

IsAuthorizedTo ( AuthorizationCheck authCheck ) : bool

Returns whether the current user passes authorization on the rights based on the given AuthorizationCheck.

IsAuthorizedTo ( AuthorizationCheck authCheck, IEnumerable rights ) : bool

Returns whether the current user passes authorization on the rights based on the given AuthorizationCheck.

IsAuthorizedTo ( Rights right ) : bool

Returns whether or not the current user has the passed in Right.

IsSystemRole ( string roleName ) : bool

Returns whether a role is a System role.

RedirectForUnauthorizedRequest ( ) : void
SignOut ( ) : void

Private Methods

Method Description
ContextAuthenticateRequest ( object sender, EventArgs e ) : void

Handles the AuthenticateRequest event of the context control.

Security ( ) : System

Method Details

AuthenticateUser() public static method

public static AuthenticateUser ( string username, string password, bool rememberMe ) : bool
username string
password string
rememberMe bool
return bool

CurrentUserRights() public static method

Returns an IEnumerable of Rights that belong to the ecurrent user.
public static CurrentUserRights ( ) : IEnumerable
return IEnumerable

DemandUserHasRight() public static method

If the current user does not have the requested rights, either redirects to the login page, or throws a SecurityException.
public static DemandUserHasRight ( AuthorizationCheck authCheck, bool redirectIfUnauthorized ) : void
authCheck AuthorizationCheck
redirectIfUnauthorized bool /// If true and user does not have rights, redirects to the login page or homepage. /// If false and user does not have rights, throws a security exception. ///
return void

DemandUserHasRight() public static method

If the current user does not have the requested right, either redirects to the login page, or throws a SecurityException.
public static DemandUserHasRight ( Rights right, bool redirectToLoginPage ) : void
right Rights
redirectToLoginPage bool /// If true and user does not have rights, redirects to the login page. /// If false and user does not have rights, throws a security exception. ///
return void

Dispose() public method

Disposes of the resources (other than memory) used by the module that implements T:System.Web.IHttpModule.
public Dispose ( ) : void
return void

GetCurrentUserRoles() public static method

Helper method that returns the correct roles based on authentication.
public static GetCurrentUserRoles ( ) : string[]
return string[]

ImpersonateUser() public static method

Impersonates a user for the duration of the HTTP request.
public static ImpersonateUser ( string username, string password ) : bool
username string The username
password string The password
return bool

Init() public method

Initializes a module and prepares it to handle requests.
public Init ( System.Web.HttpApplication context ) : void
context System.Web.HttpApplication An that provides access to the methods, properties, and events common to all application objects within an ASP.NET application
return void

IsAuthorizedTo() public static method

Returns whether the current user passes authorization on the rights based on the given AuthorizationCheck.
public static IsAuthorizedTo ( AuthorizationCheck authCheck ) : bool
authCheck AuthorizationCheck
return bool

IsAuthorizedTo() public static method

Returns whether the current user passes authorization on the rights based on the given AuthorizationCheck.
public static IsAuthorizedTo ( AuthorizationCheck authCheck, IEnumerable rights ) : bool
authCheck AuthorizationCheck
rights IEnumerable
return bool

IsAuthorizedTo() public static method

Returns whether or not the current user has the passed in Right.
public static IsAuthorizedTo ( Rights right ) : bool
right Rights
return bool

IsSystemRole() public static method

Returns whether a role is a System role.
public static IsSystemRole ( string roleName ) : bool
roleName string The name of the role.
return bool

RedirectForUnauthorizedRequest() public static method

public static RedirectForUnauthorizedRequest ( ) : void
return void

SignOut() public static method

public static SignOut ( ) : void
return void