forked from NTTLimitedRD/PowerShell.REST.API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthorizeIfEnabledAttribute.cs
36 lines (34 loc) · 1.07 KB
/
AuthorizeIfEnabledAttribute.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Controllers;
using DynamicPowerShellApi.Configuration;
namespace DynamicPowerShellApi
{
/// <summary> Attribute for authorize HTTP request if enabled. </summary>
/// <remarks> Anthony, 5/28/2015. </remarks>
/// <seealso cref="T:System.Web.Http.AuthorizeAttribute"/>
public class AuthorizeIfEnabledAttribute
: AuthorizeAttribute
{
/// <summary> Calls when an action is being authorized. </summary>
/// <remarks> Anthony, 5/28/2015. </remarks>
/// <param name="actionContext"> The context. </param>
/// <seealso cref="M:System.Web.Http.AuthorizeAttribute.OnAuthorization(HttpActionContext)"/>
public override void OnAuthorization(HttpActionContext actionContext)
{
// Skip authentication if it's disabled in the config file.
if (!WebApiConfiguration.Instance.Authentication.Enabled)
{
return;
}
if (!IsAuthorized(actionContext))
{
HandleUnauthorizedRequest(actionContext);
}
}
}
}