Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AuthorizeForRoleAttribute : AuthorizeAttribute
- {
- /// <summary>
- /// Injected application context
- /// </summary>
- /// <value>
- /// The application context.
- /// </value>
- [Inject]
- public IAppContextProvider appContext { get; set; }
- /// <summary>
- /// Processes requests that fail authorization.
- /// </summary>
- /// <param name="actionContext">The context.</param>
- protected override void HandleUnauthorizedRequest(System.Web.Http.Controllers.HttpActionContext actionContext)
- {
- base.HandleUnauthorizedRequest(actionContext);
- }
- /// <summary>
- /// Indicates whether the specified control is authorized.
- /// </summary>
- /// <param name="actionContext">The context.</param>
- /// <returns>
- /// true if the control is authorized; otherwise, false.
- /// </returns>
- /// <exception cref="System.NullReferenceException">Failed to inject application context provider</exception>
- protected override bool IsAuthorized(System.Web.Http.Controllers.HttpActionContext actionContext)
- {
- if (appContext == null)
- throw new NullReferenceException("Failed to inject application context provider");
- return appContext.IsInRole(HttpContext.Current.User.Identity.Name, this.Roles);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement