34 lines
1.3 KiB
C#
34 lines
1.3 KiB
C#
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;
|
|
}
|
|
}
|
|
} |