feat 数据敏感分配角色可见,切换基地,定时任务lock
This commit is contained in:
@@ -89,4 +89,25 @@ public class RolesController : ControllerBase
|
||||
{
|
||||
return await _roleService.GetMyRoleAsync(userId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置混淆
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
[HttpPost("obfuscate")]
|
||||
public async Task SaveRoleObfuscateAsync(RoleObfuscateRequest request)
|
||||
{
|
||||
await _roleService.SaveRoleObfuscateAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取混淆状态
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("obfuscate")]
|
||||
public async Task<bool> GetRoleObfuscateAsync(int id)
|
||||
{
|
||||
return await _roleService.GetRoleObfuscateAsync(id);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using Dlhis.Sys.Identity.Response;
|
||||
using Dlhis.Sys.Identity.Services;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -86,4 +87,15 @@ public class UsersController : ControllerBase
|
||||
{
|
||||
await _userService.UploadUserAvatarAsync(request);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置登陆
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
[Transactional]
|
||||
[HttpPost("reloginInfo")]
|
||||
public async Task ResetLoginTenantAsync(UserResetLoginTenantRequest request)
|
||||
{
|
||||
await _userService.ResetLoginTenantAsync(request);
|
||||
}
|
||||
}
|
||||
9
Src/Dlhis.Sys/Identity/Request/RoleObfuscateRequest.cs
Normal file
9
Src/Dlhis.Sys/Identity/Request/RoleObfuscateRequest.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Dlhis.Sys.Identity.Request
|
||||
{
|
||||
public class RoleObfuscateRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public bool IsShow { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dlhis.Sys.Identity.Request;
|
||||
|
||||
public class UserResetLoginTenantRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 租户
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "{0}不可为空")]
|
||||
public string Tenant { get; set; }
|
||||
}
|
||||
@@ -17,4 +17,8 @@ public interface IRoleService : IScopeDependency
|
||||
Task RemoveRoleAsync(IdRequest request);
|
||||
|
||||
Task AssignRoleAsync(RoleAssignRequest request);
|
||||
}
|
||||
|
||||
Task SaveRoleObfuscateAsync(RoleObfuscateRequest request);
|
||||
|
||||
Task<bool> GetRoleObfuscateAsync(int id);
|
||||
}
|
||||
@@ -20,4 +20,6 @@ public interface IUserService : IScopeDependency
|
||||
Task<List<UserResponse>> GetUserByIdsAsync(List<int> ids);
|
||||
|
||||
Task CreateUserAsync(UserCreateRequest request);
|
||||
|
||||
Task ResetLoginTenantAsync(UserResetLoginTenantRequest request);
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using Kurisu.AspNetCore.CustomClass;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.Sys.Identity.Services.Implements;
|
||||
@@ -13,11 +14,13 @@ namespace Dlhis.Sys.Identity.Services.Implements;
|
||||
public class RoleService : IRoleService
|
||||
{
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly RedisCache _redisCache;
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public RoleService(ICurrentUser currentUser, IDbContext dbContext)
|
||||
public RoleService(ICurrentUser currentUser, IDbContext dbContext, RedisCache redisCache)
|
||||
{
|
||||
_currentUser = currentUser;
|
||||
_redisCache = redisCache;
|
||||
_dbContext = dbContext.ChangeDb("identity");
|
||||
}
|
||||
|
||||
@@ -112,6 +115,33 @@ public class RoleService : IRoleService
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task SaveRoleObfuscateAsync(RoleObfuscateRequest request)
|
||||
{
|
||||
var role = await _dbContext.Queryable<RoleEntity>().FirstAsync(x => x.Id == request.Id);
|
||||
role.ThrowIfNull("角色不存在");
|
||||
|
||||
var key = "datapermission:role";
|
||||
if (request.IsShow)
|
||||
{
|
||||
await _redisCache.ListLeftPushAsync(key, role.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _redisCache.ListRemoveAsync(key, role.Name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> GetRoleObfuscateAsync(int id)
|
||||
{
|
||||
var role = await _dbContext.Queryable<RoleEntity>().FirstAsync(x => x.Id == id);
|
||||
var key = "datapermission:role";
|
||||
var range = await _redisCache.ListRangeAsync(key);
|
||||
|
||||
return range.Any(x => (string)x == role.Name);
|
||||
}
|
||||
|
||||
public async Task RemoveRoleAsync(IdRequest request)
|
||||
{
|
||||
var role = await _dbContext.Queryable<RoleEntity>().FirstAsync(x => x.Id == request.Id);
|
||||
|
||||
@@ -16,12 +16,14 @@ public class UserService : IUserService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly ITenantService _tenantService;
|
||||
private readonly IDbContext _identityDbContext;
|
||||
|
||||
public UserService(IDbContext dbContext, ICurrentUser currentUser)
|
||||
public UserService(IDbContext dbContext, ICurrentUser currentUser, ITenantService tenantService)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_currentUser = currentUser;
|
||||
_tenantService = tenantService;
|
||||
_identityDbContext = dbContext.ChangeDb("identity");
|
||||
}
|
||||
|
||||
@@ -135,4 +137,25 @@ public class UserService : IUserService
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async Task ResetLoginTenantAsync(UserResetLoginTenantRequest request)
|
||||
{
|
||||
var tenants = await _tenantService.GetMyTenantsAsync();
|
||||
tenants.All(x => x.Code != request.Tenant).ThrowIfTrue($"不可切换登陆:{request.Tenant}");
|
||||
|
||||
var userId = _currentUser.GetIntSubjectId();
|
||||
|
||||
await _dbContext.Updateable<UserClaimEntity>()
|
||||
.SetColumns(x => x.ClaimValue == request.Tenant)
|
||||
.Where(x => x.UserId == userId)
|
||||
.Where(x => x.ClaimType == "tenant")
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
var tenantStr = tenants.Select(x => x.Code).Join(",");
|
||||
await _dbContext.Updateable<UserClaimEntity>()
|
||||
.SetColumns(x => x.ClaimValue == tenantStr)
|
||||
.Where(x => x.UserId == userId)
|
||||
.Where(x => x.ClaimType == "tenants")
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Kurisu.AspNetCore.Startup;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Microsoft.IdentityModel.Logging;
|
||||
|
||||
namespace Dlhis.Sys;
|
||||
@@ -17,4 +18,10 @@ public class Startup : DefaultStartup
|
||||
{
|
||||
IdentityModelEventSource.ShowPII = true;
|
||||
}
|
||||
|
||||
public override void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
base.ConfigureServices(services);
|
||||
services.AddRedis();
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,9 @@
|
||||
"SlowSqlTime": 1,
|
||||
"EnableSqlLog": false
|
||||
},
|
||||
"RedisOptions": {
|
||||
"ConnectionString": "192.168.199.150:30115,defaultDatabase=1,password=dlhis123"
|
||||
},
|
||||
"SwaggerOptions": {
|
||||
"Enable": true,
|
||||
"Authority": "http://identity.oauth.svc.cluster.local",
|
||||
|
||||
Reference in New Issue
Block a user