This repository has been archived by the owner on Jan 17, 2024. It is now read-only.
forked from 18F/dol-whd-14c
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from AppliedIS/require-https
require all authenticated activity to be over https
- Loading branch information
Showing
6 changed files
with
45 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Web.Http; | ||
using System.Web.Http.Controllers; | ||
|
||
namespace DOL.WHD.Section14c.Api.Filters | ||
{ | ||
public class AuthorizeHttps : AuthorizeAttribute | ||
{ | ||
public override void OnAuthorization(HttpActionContext actionContext) | ||
{ | ||
if (SkipAuthorization(actionContext)) | ||
return; | ||
|
||
if (actionContext.Request.RequestUri.Scheme != Uri.UriSchemeHttps) | ||
{ | ||
actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Forbidden) | ||
{ | ||
ReasonPhrase = "HTTPS Required" | ||
}; | ||
} | ||
else | ||
{ | ||
base.OnAuthorization(actionContext); | ||
} | ||
} | ||
|
||
// from AuthorizeAttribute | ||
private static bool SkipAuthorization(HttpActionContext actionContext) | ||
{ | ||
if (!actionContext.ActionDescriptor.GetCustomAttributes<AllowAnonymousAttribute>().Any<AllowAnonymousAttribute>()) | ||
return actionContext.ControllerContext.ControllerDescriptor.GetCustomAttributes<AllowAnonymousAttribute>().Any<AllowAnonymousAttribute>(); | ||
return true; | ||
} | ||
} | ||
} |