Skip to content

Handle an unauthorized request

Log a denied authorization attempt and redirect the user to the error page. Trigger: AuthorizeCore returned false.

Field Value
Operation ID OP-10
Trigger AuthorizeCore returned false
Inputs AuthorizationContext; injected ILogService and IEnvironmentService
Outputs Logged SecurityException; RedirectResult to the error page
Primary components SaifAuthorizeAttribute.HandleUnauthorizedRequest(AuthorizationContext)
Entry point src/Web.Mvc/ActionFilters/SaifAuthorizeAttribute.cs

Steps

  1. Enforce.ArgumentNotNull on filterContext, LogService, and EnvironmentService (BR-01, BR-15).
  2. Build context text "User: {EnvironmentService.UserId()}{NewLine}Page: {Request.Url}".
  3. Call LogService.LogException(applicationName, controllerAndActionName, state, new SecurityException("The user '{_userId}' is not authorized for this view.")) (BR-19).
  4. Set filterContext.Result = new RedirectResult("//saifonline/weberror/processerror.aspx?MSG=Not%20Authorized") — a hard-coded literal rather than Constants.ErrorUrl (BR-20).

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start([AuthorizeCore returned false])
    Guard[Guard filterContext/services]
    Build[Build context text]
    Log[LogService.LogException SecurityException]
    Redir[Set Result to RedirectResult]
    EndOk(["Denied, redirected"])
    Start --> Guard
    Guard --> Build
    Build --> Log
    Log --> Redir
    Redir --> EndOk

Failure and edge-case behavior

  • No unexpected failure paths beyond argument-guard exceptions and delegated dependency behavior were identified for this operation.

Sources

  • src/Web.Mvc/ActionFilters/SaifAuthorizeAttribute.cs