增加swagger 权限校验

develop
old易 2023-11-20 10:10:43 +08:00
parent 18612c18a7
commit 2465b1a28f
3 changed files with 14 additions and 12 deletions

View File

@ -1109,7 +1109,7 @@
登录管理【无权限】
</summary>
</member>
<member name="M:New_College.Controllers.LoginController.#ctor(New_College.IServices.ISysUserInfoServices,New_College.IServices.IUserRoleServices,New_College.IServices.IRoleServices,New_College.AuthHelper.PermissionRequirement,New_College.IServices.IRoleModulePermissionServices)">
<member name="M:New_College.Controllers.LoginController.#ctor(New_College.IServices.ISysUserInfoServices,New_College.IServices.IUserRoleServices,New_College.IServices.IRoleServices,New_College.AuthHelper.PermissionRequirement,New_College.IServices.IRoleModulePermissionServices,Microsoft.AspNetCore.Http.IHttpContextAccessor)">
<summary>
构造函数注入
</summary>

View File

@ -50,6 +50,7 @@ namespace New_College
{
// 以下code可能与文章中不一样,对代码做了封装,具体查看右侧 Extensions 文件夹.
services.AddSingleton<IRedisCacheManager, RedisCacheManager>();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddSingleton(new Appsettings(Configuration));
services.AddSingleton(new LogLock(Env.ContentRootPath));
@ -113,7 +114,7 @@ namespace New_College
services.Configure<KestrelServerOptions>(x => x.AllowSynchronousIO = true)
.Configure<IISServerOptions>(x => x.AllowSynchronousIO = true);
// services.AddSession();
services.AddSession();
services.AddControllers(o =>
{
// 全局异常过滤
@ -164,6 +165,7 @@ namespace New_College
// 注意在Program.CreateHostBuilder添加Autofac服务工厂
public void ConfigureContainer(ContainerBuilder builder)
{
builder.RegisterModule(new AutofacModuleRegister());
}
@ -193,7 +195,7 @@ namespace New_College
// 强制实施 HTTPS 在 ASP.NET Core配合 app.UseHttpsRedirection
//app.UseHsts();
}
// app.UseSession();
app.UseSession();
app.UseSwaggerAuthorized();
// 封装Swagger展示
app.UseSwaggerMildd(() => GetType().GetTypeInfo().Assembly.GetManifestResourceStream("New_College.Api.index.html"));

View File

@ -22,18 +22,18 @@ namespace New_College.Common
{
await next.Invoke(context);
return;
//await next.Invoke(context);
//return;
// 判断权限是否正确
//if (IsAuthorized(context))
//{
// await next.Invoke(context);
// return;
//}
if (IsAuthorized(context))
{
await next.Invoke(context);
return;
}
//// 无权限跳转swagger登录页
//context.RedirectSwaggerLogin();
// 无权限跳转swagger登录页
context.RedirectSwaggerLogin();
}
else
{