feat: 💯 change ClaimTypes.Role

This commit is contained in:
anjoy8 2023-12-13 11:04:04 +08:00
parent 5f132f0386
commit 5e4987d2f6
8 changed files with 26 additions and 19 deletions

View File

@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Security.Claims;
namespace Blog.Core.Controllers
{
@ -349,8 +350,14 @@ namespace Blog.Core.Controllers
where item.Type == "sub"
select item.Value).FirstOrDefault().ObjToLong();
roleIds = (from item in _httpContext.HttpContext.User.Claims
where item.Type == "role"
where item.Type == ClaimTypes.Role
select item.Value.ObjToLong()).ToList();
if (!roleIds.Any())
{
roleIds = (from item in _httpContext.HttpContext.User.Claims
where item.Type == "role"
select item.Value.ObjToLong()).ToList();
}
}
else
{
@ -440,8 +447,14 @@ namespace Blog.Core.Controllers
where item.Type == "sub"
select item.Value).FirstOrDefault().ObjToLong();
roleIds = (from item in _httpContext.HttpContext.User.Claims
where item.Type == "role"
where item.Type == ClaimTypes.Role
select item.Value.ObjToLong()).ToList();
if (!roleIds.Any())
{
roleIds = (from item in _httpContext.HttpContext.User.Claims
where item.Type == "role"
select item.Value.ObjToLong()).ToList();
}
}
else
{

View File

@ -111,9 +111,9 @@
</svg>
<div id="swagger-ui"></div>
<div id="footer" style="text-align: center;margin-bottom: 10px;">
Copyright © 2018-2020 老张的哲学
Copyright © 2018-2023 BCVP开发者社区
<br><span id="poweredby">Powered by .NET 5.0.0 on Docker & CentOS 7.6</span>
<br><span id="poweredby">Powered by .NET 8.0 on Docker & CentOS 7.6</span>
</div>
<!-- Workaround for https://github.com/swagger-api/swagger-editor/issues/1371 -->
<script>

View File

@ -208,21 +208,15 @@ namespace Blog.Core.AuthHelper
// 获取当前用户的角色信息
var currentUserRoles = new List<string>();
// ids4和jwt切换
// ids4
if (Permissions.IsUseIds4)
currentUserRoles = (from item in httpContext.User.Claims
where item.Type == ClaimTypes.Role
select item.Value).ToList();
if (!currentUserRoles.Any())
{
currentUserRoles = (from item in httpContext.User.Claims
where item.Type == "role"
select item.Value).ToList();
}
else
{
// jwt
currentUserRoles = (from item in httpContext.User.Claims
where item.Type == requirement.ClaimType
select item.Value).ToList();
}
//超级管理员 默认拥有所有权限
if (currentUserRoles.All(s => s != "SuperAdmin"))

View File

@ -4,7 +4,7 @@ using SqlSugar;
namespace Blog.Core.Model.Logs;
[Tenant("log")]
[SplitTable(SplitType.Month)] //按分表 (自带分表支持 年、季、月、周、日)
[SplitTable(SplitType.Month)] //按分表 (自带分表支持 年、季、月、周、日)
[SugarTable($@"{nameof(AuditSqlLog)}_{{year}}{{month}}{{day}}")]
public class AuditSqlLog: BaseLog
{

View File

@ -4,7 +4,7 @@ using SqlSugar;
namespace Blog.Core.Model.Logs;
[Tenant("log")]
[SplitTable(SplitType.Month)] //按分表 (自带分表支持 年、季、月、周、日)
[SplitTable(SplitType.Month)] //按分表 (自带分表支持 年、季、月、周、日)
[SugarTable($@"{nameof(GlobalErrorLog)}_{{year}}{{month}}{{day}}")]
public class GlobalErrorLog : BaseLog
{

View File

@ -4,7 +4,7 @@ using SqlSugar;
namespace Blog.Core.Model.Logs;
[Tenant("log")]
[SplitTable(SplitType.Month)] //按分表 (自带分表支持 年、季、月、周、日)
[SplitTable(SplitType.Month)] //按分表 (自带分表支持 年、季、月、周、日)
[SugarTable($@"{nameof(GlobalInformationLog)}_{{year}}{{month}}{{day}}")]
public class GlobalInformationLog : BaseLog
{

View File

@ -4,7 +4,7 @@ using SqlSugar;
namespace Blog.Core.Model.Logs;
[Tenant("log")]
[SplitTable(SplitType.Month)] //按分表 (自带分表支持 年、季、月、周、日)
[SplitTable(SplitType.Month)] //按分表 (自带分表支持 年、季、月、周、日)
[SugarTable($@"{nameof(GlobalWarningLog)}_{{year}}{{month}}{{day}}")]
public class GlobalWarningLog: BaseLog
{

View File

@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace Blog.Core.Model.Models
{
[SplitTable(SplitType.Day)]//按分表 (自带分表支持 年、季、月、周、日)
[SplitTable(SplitType.Day)]//按分表 (自带分表支持 年、季、月、周、日)
[SugarTable("SplitDemo_{year}{month}{day}")]//3个变量必须要有这么设计为了兼容开始按年后面改成按月、按日
public class SplitDemo
{