Initial Commit ...
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using xCommons.Configurations;
|
||||
|
||||
namespace xCommons.Extensions {
|
||||
public static partial class FilterExtensions {
|
||||
public static XAppConfiguration GetXAppConfiguration (this ActionExecutingContext source) {
|
||||
//
|
||||
var services = source.HttpContext.RequestServices;
|
||||
return (XAppConfiguration) services.GetService (typeof (XAppConfiguration));
|
||||
}
|
||||
|
||||
public static XAppConfiguration GetXAppConfiguration (this AuthorizationFilterContext source) {
|
||||
//
|
||||
var services = source.HttpContext.RequestServices;
|
||||
return (XAppConfiguration) services.GetService (typeof (XAppConfiguration));
|
||||
}
|
||||
|
||||
public static bool IsAnonymousAllowed (this AuthorizationFilterContext source) {
|
||||
//
|
||||
var result = source.Filters
|
||||
.Any (f => f.GetType () == typeof (AllowAnonymousFilter)) ||
|
||||
source.ActionDescriptor.FilterDescriptors
|
||||
.Any (f => f.GetType () == typeof (AllowAnonymousFilter)) ||
|
||||
source.ActionDescriptor.EndpointMetadata
|
||||
.Any (f => f.GetType () == typeof (AllowAnonymousAttribute));
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user