a099d68915
Initial Release; Includes Database and MVC refactoring
42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using Disco.Services.Users;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web.Mvc;
|
|
|
|
namespace Disco.Services.Authorization
|
|
{
|
|
public class DiscoAuthorizeAllAttribute : AuthorizeAttribute
|
|
{
|
|
string[] authorizedClaims;
|
|
|
|
public DiscoAuthorizeAllAttribute(params string[] AuthorisedClaims)
|
|
{
|
|
if (AuthorisedClaims == null || AuthorisedClaims.Length == 0)
|
|
throw new ArgumentNullException("AuthorisedClaims");
|
|
|
|
this.authorizedClaims = AuthorisedClaims;
|
|
}
|
|
|
|
protected override bool AuthorizeCore(System.Web.HttpContextBase httpContext)
|
|
{
|
|
if (httpContext == null)
|
|
throw new ArgumentNullException("httpContext");
|
|
|
|
var authToken = UserService.CurrentAuthorization;
|
|
|
|
if (authToken == null)
|
|
return false; // No Current User
|
|
|
|
return authToken.HasAll(authorizedClaims);
|
|
}
|
|
|
|
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
|
|
{
|
|
filterContext.Result = new HttpUnauthorizedResult(AuthorizationToken.BuildRequireAllMessage(authorizedClaims));
|
|
}
|
|
}
|
|
}
|