Skip to main content

RequiredRoleAttribute

Protect access to this API to only Authenticated Users assigned with all specified Roles

Assembly: ServiceStack.dll
View Source
Declaration
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
public class RequiredRoleAttribute : AuthenticateAttribute, _Attribute, IHasRequestFilterAsync, IRequestFilterBase

Properties

RequiredRoles

View Source
Declaration
public List<string> RequiredRoles { get; set; }

Inherited Properties

HtmlRedirect

Redirect the client to a specific URL if authentication failed. If this property is null, simply 401 Unauthorized is returned.

View Source
Declaration
public string HtmlRedirect { get; set; }

Provider

Restrict authentication to a specific ServiceStack.Auth.IAuthProvider. For example, if this attribute should only permit access if the user is authenticated with ServiceStack.Auth.BasicAuthProvider, you should set this property to ServiceStack.Auth.BasicAuthProvider.Name.

View Source
Declaration
public string Provider { get; set; }

Methods

ExecuteAsync(IRequest, IResponse, Object)

View Source
Declaration
public override async Task ExecuteAsync(IRequest req, IResponse res, object requestDto)
Returns

System.Threading.Tasks.Task

Parameters
TypeName
ServiceStack.Web.IRequestreq
ServiceStack.Web.IResponseres
System.ObjectrequestDto

HasAllRoles(IRequest, IAuthSession, IAuthRepository)

View Source
Declaration
[Obsolete("Use HasAllRolesAsync")]
public bool HasAllRoles(IRequest req, IAuthSession session, IAuthRepository authRepo)
Returns

System.Boolean

Parameters
TypeName
ServiceStack.Web.IRequestreq
ServiceStack.Auth.IAuthSessionsession
ServiceStack.Auth.IAuthRepositoryauthRepo

HasAllRolesAsync(IRequest, IAuthSession, IAuthRepositoryAsync)

View Source
Declaration
public async Task<bool> HasAllRolesAsync(IRequest req, IAuthSession session, IAuthRepositoryAsync authRepo)
Returns

System.Threading.Tasks.Task<System.Boolean>

Parameters
TypeName
ServiceStack.Web.IRequestreq
ServiceStack.Auth.IAuthSessionsession
ServiceStack.Auth.IAuthRepositoryAsyncauthRepo

HasAllRoles(IRequest, IAuthSession, ICollection<String>)

View Source
Declaration
[Obsolete("Use HasAllRolesAsync")]
public static bool HasAllRoles(IRequest req, IAuthSession session, ICollection<string> requiredRoles)
Returns

System.Boolean

Parameters
TypeName
ServiceStack.Web.IRequestreq
ServiceStack.Auth.IAuthSessionsession
System.Collections.Generic.ICollection<System.String>requiredRoles

HasAllRolesAsync(IRequest, ICollection<String>, CancellationToken)

View Source
Declaration
public static async Task<bool> HasAllRolesAsync(IRequest req, ICollection<string> requiredRoles, CancellationToken token = default(CancellationToken))
Returns

System.Threading.Tasks.Task<System.Boolean>

Parameters
TypeName
ServiceStack.Web.IRequestreq
System.Collections.Generic.ICollection<System.String>requiredRoles
System.Threading.CancellationTokentoken

HasAllRolesAsync(IRequest, IAuthSession, ICollection<String>, CancellationToken)

View Source
Declaration
public static async Task<bool> HasAllRolesAsync(IRequest req, IAuthSession session, ICollection<string> requiredRoles, CancellationToken token = default(CancellationToken))
Returns

System.Threading.Tasks.Task<System.Boolean>

Parameters
TypeName
ServiceStack.Web.IRequestreq
ServiceStack.Auth.IAuthSessionsession
System.Collections.Generic.ICollection<System.String>requiredRoles
System.Threading.CancellationTokentoken

AssertRequiredRoles(IRequest, String[])

View Source
Declaration
[Obsolete("Use AssertRequiredRolesAsync")]
public static void AssertRequiredRoles(IRequest req, params string[] requiredRoles)
Parameters
TypeName
ServiceStack.Web.IRequestreq
System.String[]requiredRoles

AssertRequiredRoleAsync(IRequest, String, CancellationToken)

Check all session is in all supplied roles otherwise a 401 HttpError is thrown

View Source
Declaration
public static Task AssertRequiredRoleAsync(IRequest req, string requiredRole, CancellationToken token = default(CancellationToken))
Returns

System.Threading.Tasks.Task

Parameters
TypeName
ServiceStack.Web.IRequestreq
System.StringrequiredRole
System.Threading.CancellationTokentoken

AssertRequiredRolesAsync(IRequest, String[], CancellationToken)

Check all session is in all supplied roles otherwise a 401 HttpError is thrown

View Source
Declaration
public static async Task AssertRequiredRolesAsync(IRequest req, string[] requiredRoles, CancellationToken token = default(CancellationToken))
Returns

System.Threading.Tasks.Task

Parameters
TypeName
ServiceStack.Web.IRequestreq
System.String[]requiredRoles
System.Threading.CancellationTokentoken

HasRequiredRoles(IRequest, String[])

View Source
Declaration
[Obsolete("Use HasRequiredRolesAsync")]
public static bool HasRequiredRoles(IRequest req, string[] requiredRoles)
Returns

System.Boolean

Parameters
TypeName
ServiceStack.Web.IRequestreq
System.String[]requiredRoles

HasRequiredRolesAsync(IRequest, String[])

View Source
Declaration
public static Task<bool> HasRequiredRolesAsync(IRequest req, string[] requiredRoles)
Returns

System.Threading.Tasks.Task<System.Boolean>

Parameters
TypeName
ServiceStack.Web.IRequestreq
System.String[]requiredRoles

PreAuthenticatedValidForAllRoles(IRequest, ICollection<String>)

View Source
Declaration
public static bool PreAuthenticatedValidForAllRoles(IRequest req, ICollection<string> requiredRoles)
Returns

System.Boolean

Parameters
TypeName
ServiceStack.Web.IRequestreq
System.Collections.Generic.ICollection<System.String>requiredRoles

Equals(RequiredRoleAttribute)

View Source
Declaration
protected bool Equals(RequiredRoleAttribute other)
Returns

System.Boolean

Parameters
TypeName
ServiceStack.RequiredRoleAttributeother

Equals(Object)

View Source
Declaration
public override bool Equals(object obj)
Returns

System.Boolean

Parameters
TypeName
System.Objectobj

GetHashCode()

View Source
Declaration
public override int GetHashCode()
Returns

System.Int32

Inherited Methods

AssertAuthenticated(IRequest, Object, IAuthSession, IAuthProvider[])

View Source
Declaration
[Obsolete("Use AuthenticateAsync")]
public static void AssertAuthenticated(IRequest req, object requestDto = null, IAuthSession session = null, IAuthProvider[] authProviders = null)
Parameters
TypeName
ServiceStack.Web.IRequestreq
System.ObjectrequestDto
ServiceStack.Auth.IAuthSessionsession
ServiceStack.Auth.IAuthProvider[]authProviders

AssertAuthenticatedAsync(IRequest, Object, IAuthSession, IAuthProvider[])

View Source
Declaration
public static async Task AssertAuthenticatedAsync(IRequest req, object requestDto = null, IAuthSession session = null, IAuthProvider[] authProviders = null)
Returns

System.Threading.Tasks.Task

Parameters
TypeName
ServiceStack.Web.IRequestreq
System.ObjectrequestDto
ServiceStack.Auth.IAuthSessionsession
ServiceStack.Auth.IAuthProvider[]authProviders

Authenticate(IRequest, Object, IAuthSession, IAuthProvider[])

View Source
Declaration
[Obsolete("Use AuthenticateAsync")]
public static bool Authenticate(IRequest req, object requestDto = null, IAuthSession session = null, IAuthProvider[] authProviders = null)
Returns

System.Boolean

Parameters
TypeName
ServiceStack.Web.IRequestreq
System.ObjectrequestDto
ServiceStack.Auth.IAuthSessionsession
ServiceStack.Auth.IAuthProvider[]authProviders

AuthenticateAsync(IRequest, Object, IAuthSession, IAuthProvider[])

View Source
Declaration
public static async Task<bool> AuthenticateAsync(IRequest req, object requestDto = null, IAuthSession session = null, IAuthProvider[] authProviders = null)
Returns

System.Threading.Tasks.Task<System.Boolean>

Parameters
TypeName
ServiceStack.Web.IRequestreq
System.ObjectrequestDto
ServiceStack.Auth.IAuthSessionsession
ServiceStack.Auth.IAuthProvider[]authProviders

Equals(AuthenticateAttribute)

View Source
Declaration
protected bool Equals(AuthenticateAttribute other)
Returns

System.Boolean

Parameters
TypeName
ServiceStack.AuthenticateAttributeother

Equals(Object)

View Source
Declaration
public override bool Equals(object obj)
Returns

System.Boolean

Parameters
TypeName
System.Objectobj

ExecuteAsync(IRequest, IResponse, Object)

View Source
Declaration
public override async Task ExecuteAsync(IRequest req, IResponse res, object requestDto)
Returns

System.Threading.Tasks.Task

Parameters
TypeName
ServiceStack.Web.IRequestreq
ServiceStack.Web.IResponseres
System.ObjectrequestDto

GetHashCode()

View Source
Declaration
public override int GetHashCode()
Returns

System.Int32

HandleShortCircuitedErrors(IRequest, IResponse, Object, HttpStatusCode, String)

View Source
Declaration
protected virtual Task HandleShortCircuitedErrors(IRequest req, IResponse res, object requestDto, HttpStatusCode statusCode, string statusDescription = null)
Returns

System.Threading.Tasks.Task

Parameters
TypeName
ServiceStack.Web.IRequestreq
ServiceStack.Web.IResponseres
System.ObjectrequestDto
System.Net.HttpStatusCodestatusCode
System.StringstatusDescription

ThrowInvalidPermission(IRequest)

View Source
Declaration
public static void ThrowInvalidPermission(IRequest req = null)
Parameters
TypeName
ServiceStack.Web.IRequestreq

ThrowInvalidRole(IRequest)

View Source
Declaration
public static void ThrowInvalidRole(IRequest req = null)
Parameters
TypeName
ServiceStack.Web.IRequestreq

ThrowNotAuthenticated(IRequest)

View Source
Declaration
public static void ThrowNotAuthenticated(IRequest req = null)
Parameters
TypeName
ServiceStack.Web.IRequestreq

Implements