You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.9 KiB
106 lines
3.9 KiB
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
|
using Microsoft.AspNetCore.Mvc.Authorization;
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
using System.Text;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp.AspNetCore.ExceptionHandling;
|
|
using Volo.Abp.AspNetCore.Mvc;
|
|
using Volo.Abp.AspNetCore.Mvc.ExceptionHandling;
|
|
using Volo.Abp.Authorization;
|
|
using Volo.Abp.DependencyInjection;
|
|
using Volo.Abp.ExceptionHandling;
|
|
using Volo.Abp.Http;
|
|
using Volo.Abp.Json;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Authorization.Policy;
|
|
using System.Reflection.Metadata;
|
|
using Microsoft.AspNetCore.Authentication;
|
|
using System.Linq;
|
|
using Microsoft.AspNetCore.Mvc.Controllers;
|
|
using System.Net;
|
|
|
|
namespace Shentun.Peis
|
|
{
|
|
|
|
// public class AuthorizationMiddlewareResultHandler : IAuthorizationMiddlewareResultHandler, ITransientDependency
|
|
public class AuthorizationMiddlewareResultHandler
|
|
{
|
|
|
|
|
|
//public async Task HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult)
|
|
//{
|
|
// var endPoint = context.GetEndpoint();
|
|
// var controllerActionDescriptor = (ControllerActionDescriptor)endPoint.Metadata
|
|
// .ToList().FirstOrDefault(d => d is ControllerActionDescriptor);
|
|
// var controllerName = controllerActionDescriptor.ControllerName;
|
|
// var actionName = controllerActionDescriptor.ActionName;
|
|
// if (!context.User.Identity.IsAuthenticated)
|
|
// {
|
|
// context.Response.StatusCode = (int)HttpStatusCode.OK;
|
|
// // await context.Response.WriteAsync("{\"data\":{\"succeeded\":false,\"code\":401,\"message\":\"登录已过期,请重新登录\"}}");
|
|
// return;
|
|
// }
|
|
// //else if (!await HandleRequirementEvaluateAsync(context.User, controllerName, actionName))
|
|
// //{
|
|
// // context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
|
// // await context.Response.WriteAsync("{\"data\":{\"succeeded\":false,\"code\":403,\"message\":\"您暂⽆⾜够的权限执⾏该操作\"}}");
|
|
// // return;
|
|
// //}
|
|
// await next(context);
|
|
//}
|
|
|
|
|
|
|
|
|
|
//public Task HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult)
|
|
//{
|
|
// if (authorizeResult.Succeeded)
|
|
// {
|
|
// return next(context);
|
|
// }
|
|
|
|
// return Handle();
|
|
|
|
// async Task Handle()
|
|
// {
|
|
// if (authorizeResult.Challenged)
|
|
// {
|
|
// if (policy.AuthenticationSchemes.Count > 0)
|
|
// {
|
|
// foreach (var scheme in policy.AuthenticationSchemes)
|
|
// {
|
|
// await context.ChallengeAsync(scheme);
|
|
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// await context.ChallengeAsync();
|
|
// }
|
|
// }
|
|
// else if (authorizeResult.Forbidden)
|
|
// {
|
|
// if (policy.AuthenticationSchemes.Count > 0)
|
|
// {
|
|
// foreach (var scheme in policy.AuthenticationSchemes)
|
|
// {
|
|
// await context.ForbidAsync(scheme);
|
|
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// await context.ForbidAsync();
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
}
|
|
}
|