38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using System.Reflection;
|
|
using ln.http.router;
|
|
|
|
namespace ln.http
|
|
{
|
|
public static class RoleAuthorization
|
|
{
|
|
public static HttpAuthorizationDelegate Require(string roleName)
|
|
{
|
|
return context => context.AuthenticatedPrincipal?.HasRole(roleName) ?? false;
|
|
}
|
|
|
|
public static HttpAuthorizationDelegate RequireAll(params HttpAuthorizationDelegate[] authorizationDelegates)
|
|
{
|
|
return context =>
|
|
{
|
|
foreach (HttpAuthorizationDelegate authorizationDelegate in authorizationDelegates)
|
|
{
|
|
if (!authorizationDelegate(context))
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|
|
}
|
|
public static HttpAuthorizationDelegate RequireOneOf(params HttpAuthorizationDelegate[] authorizationDelegates)
|
|
{
|
|
return context =>
|
|
{
|
|
foreach (HttpAuthorizationDelegate authorizationDelegate in authorizationDelegates)
|
|
{
|
|
if (authorizationDelegate(context))
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
}
|
|
}
|
|
} |