feat: 数据权限服务.
This commit is contained in:
@@ -8,10 +8,8 @@ import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* redis 工具类
|
||||
@@ -57,6 +55,54 @@ public class RedisUtils {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫描并删除 key
|
||||
*
|
||||
* @param match match
|
||||
*/
|
||||
public static void scanKeysDelete(String match) {
|
||||
Set<String> keys = scanKeys(match);
|
||||
if (keys.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
redisTemplate.delete(keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫描并删除 key
|
||||
*
|
||||
* @param match match
|
||||
*/
|
||||
public static void scanKeysDelete(String... match) {
|
||||
if (Arrays1.isEmpty(match)) {
|
||||
return;
|
||||
}
|
||||
List<String> keys = Arrays.stream(match)
|
||||
.map(RedisUtils::scanKeys)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
if (keys.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
redisTemplate.delete(keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫描并删除 key
|
||||
*
|
||||
* @param match match
|
||||
*/
|
||||
public static void scanKeysDelete(List<String> match) {
|
||||
List<String> keys = match.stream()
|
||||
.map(RedisUtils::scanKeys)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
if (keys.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
redisTemplate.delete(keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 key
|
||||
*
|
||||
|
||||
@@ -41,7 +41,7 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
|
||||
if (!Strings.isBlank(token)) {
|
||||
// 通过 token 获取用户信息
|
||||
LoginUser loginUser = securityFrameworkService.getUserByToken(token);
|
||||
// 设置上下文
|
||||
// 设置用户上下文
|
||||
if (loginUser != null) {
|
||||
SecurityUtils.setLoginUser(loginUser, request);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,9 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 认证失败处理器
|
||||
* 未认证处理器
|
||||
* <p>
|
||||
* 过滤器执行完还未设置用户上下文则会进入此处理器
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
@@ -22,7 +24,7 @@ public class AuthenticationEntryPointHandler implements AuthenticationEntryPoint
|
||||
|
||||
@Override
|
||||
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException {
|
||||
log.debug("AuthenticationEntryPoint-commence-未登录 {}", request.getRequestURI(), e);
|
||||
log.debug("AuthenticationEntryPoint-commence-unauthorized {}", request.getRequestURI(), e);
|
||||
Servlets.writeHttpWrapper(response, ErrorCode.UNAUTHORIZED.getWrapper());
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 权限不足处理器
|
||||
* <p>
|
||||
* {@code @PreAuthorize("@ss.has('xxx')") } 返回 false 会进入此处理器
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
@@ -23,7 +25,7 @@ public class ForbiddenAccessDeniedHandler implements AccessDeniedHandler {
|
||||
|
||||
@Override
|
||||
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) throws IOException {
|
||||
log.warn("AccessDeniedHandlerImpl-handle-无权限 {} {}", SecurityUtils.getLoginUserId(), request.getRequestURI());
|
||||
log.warn("AccessDeniedHandlerImpl-handle-forbidden {} {}", SecurityUtils.getLoginUserId(), request.getRequestURI());
|
||||
Servlets.writeHttpWrapper(response, ErrorCode.FORBIDDEN.getWrapper());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.orion.ops.module.infra.api;
|
||||
|
||||
import com.orion.ops.module.infra.entity.dto.data.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据权限 对外服务类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-11-21 10:32
|
||||
*/
|
||||
public interface DataPermissionApi {
|
||||
|
||||
/**
|
||||
* 创建数据权限
|
||||
*
|
||||
* @param dto dto
|
||||
* @return id
|
||||
*/
|
||||
Long createDataPermission(DataPermissionCreateDTO dto);
|
||||
|
||||
/**
|
||||
* 更新数据权限
|
||||
*
|
||||
* @param dto dto
|
||||
* @return effect
|
||||
*/
|
||||
Integer updateDataPermissionById(DataPermissionUpdateDTO dto);
|
||||
|
||||
/**
|
||||
* 根据条件更新数据权限
|
||||
*
|
||||
* @param query query
|
||||
* @param update update
|
||||
* @return effect
|
||||
*/
|
||||
Integer updateDataPermission(DataPermissionQueryDTO query, DataPermissionUpdateDTO update);
|
||||
|
||||
/**
|
||||
* 查询数据权限
|
||||
*
|
||||
* @param id id
|
||||
* @return row
|
||||
*/
|
||||
DataPermissionDTO getDataPermissionById(Long id);
|
||||
|
||||
/**
|
||||
* 批量查询数据权限
|
||||
*
|
||||
* @param idList idList
|
||||
* @return rows
|
||||
*/
|
||||
List<DataPermissionDTO> getDataPermissionByIdList(List<Long> idList);
|
||||
|
||||
/**
|
||||
* 查询全部数据权限
|
||||
*
|
||||
* @param dto dto
|
||||
* @return rows
|
||||
*/
|
||||
List<DataPermissionDTO> getDataPermissionList(DataPermissionQueryDTO dto);
|
||||
|
||||
/**
|
||||
* 查询数据权限数量
|
||||
*
|
||||
* @param dto dto
|
||||
* @return count
|
||||
*/
|
||||
Long getDataPermissionCount(DataPermissionQueryDTO dto);
|
||||
|
||||
/**
|
||||
* 删除数据权限
|
||||
*
|
||||
* @param id id
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteDataPermissionById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除数据权限
|
||||
*
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteDataPermissionByIdList(List<Long> idList);
|
||||
|
||||
/**
|
||||
* 根据条件删除数据权限
|
||||
*
|
||||
* @param dto dto
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteDataPermission(DataPermissionQueryDTO dto);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.orion.ops.module.infra.entity.dto.data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.math.*;
|
||||
|
||||
/**
|
||||
* 数据权限 创建请求业务对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-11-21 10:32
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "DataPermissionCreateDTO", description = "数据权限 创建请求业务对象")
|
||||
public class DataPermissionCreateDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "角色id")
|
||||
private Long roleId;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "引用id")
|
||||
private Long relId;
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 32)
|
||||
@Schema(description = "数据类型")
|
||||
private String type;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.orion.ops.module.infra.entity.dto.data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.io.Serializable;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.math.*;
|
||||
|
||||
/**
|
||||
* 数据权限 业务对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-11-21 10:32
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "DataPermissionDTO", description = "数据权限 业务对象")
|
||||
public class DataPermissionDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "角色id")
|
||||
private Long roleId;
|
||||
|
||||
@Schema(description = "引用id")
|
||||
private Long relId;
|
||||
|
||||
@Schema(description = "数据类型")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@Schema(description = "修改时间")
|
||||
private Date updateTime;
|
||||
|
||||
@Schema(description = "创建人")
|
||||
private String creator;
|
||||
|
||||
@Schema(description = "修改人")
|
||||
private String updater;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.orion.ops.module.infra.entity.dto.data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.math.*;
|
||||
|
||||
/**
|
||||
* 数据权限 查询请求业务对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-11-21 10:32
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "DataPermissionQueryDTO", description = "数据权限 查询请求业务对象")
|
||||
public class DataPermissionQueryDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "角色id")
|
||||
private Long roleId;
|
||||
|
||||
@Schema(description = "引用id")
|
||||
private Long relId;
|
||||
|
||||
@Size(max = 32)
|
||||
@Schema(description = "数据类型")
|
||||
private String type;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.orion.ops.module.infra.entity.dto.data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.math.*;
|
||||
|
||||
/**
|
||||
* 数据权限 更新请求业务对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-11-21 10:32
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "DataPermissionUpdateDTO", description = "数据权限 更新请求业务对象")
|
||||
public class DataPermissionUpdateDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "角色id")
|
||||
private Long roleId;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "引用id")
|
||||
private Long relId;
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 32)
|
||||
@Schema(description = "数据类型")
|
||||
private String type;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
// package com.orion.ops.module.infra.api.impl;
|
||||
//
|
||||
// import com.alibaba.fastjson.JSON;
|
||||
// import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
// import com.orion.lang.utils.collect.Lists;
|
||||
// import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
// import com.orion.ops.framework.common.utils.Valid;
|
||||
// import com.orion.ops.module.infra.entity.vo.*;
|
||||
// import com.orion.ops.module.infra.entity.request.data.*;
|
||||
// import com.orion.ops.module.infra.convert.*;
|
||||
// import com.orion.ops.module.infra.define.operator.*;
|
||||
// import com.orion.ops.module.infra.api.*;
|
||||
// import com.orion.ops.module.infra.api.impl.*;
|
||||
// import com.orion.ops.module.infra.entity.dto.data.*;
|
||||
// import com.orion.ops.module.infra.convert.*;
|
||||
// import com.orion.ops.module.infra.entity.domain.DataPermissionDO;
|
||||
// import com.orion.ops.module.infra.dao.DataPermissionDAO;
|
||||
// import com.orion.ops.module.infra.service.DataPermissionService;
|
||||
// import lombok.extern.slf4j.Slf4j;
|
||||
// import org.springframework.stereotype.Service;
|
||||
//
|
||||
// import javax.annotation.Resource;
|
||||
// import java.util.ArrayList;
|
||||
// import java.util.List;
|
||||
// import java.util.stream.Collectors;
|
||||
//
|
||||
// /**
|
||||
// * 数据权限 对外服务实现类
|
||||
// *
|
||||
// * @author Jiahang Li
|
||||
// * @version 1.0.0
|
||||
// * @since 2023-11-21 10:32
|
||||
// */
|
||||
// @Slf4j
|
||||
// @Service
|
||||
// public class DataPermissionApiImpl implements DataPermissionApi {
|
||||
//
|
||||
// @Resource
|
||||
// private DataPermissionService dataPermissionService;
|
||||
//
|
||||
// @Resource
|
||||
// private DataPermissionDAO dataPermissionDAO;
|
||||
//
|
||||
// @Override
|
||||
// public Long createDataPermission(DataPermissionCreateDTO dto) {
|
||||
// log.info("DataPermissionApi.createDataPermission dto: {}", JSON.toJSONString(dto));
|
||||
// Valid.valid(dto);
|
||||
// // 转换
|
||||
// DataPermissionCreateRequest request = DataPermissionProviderConvert.MAPPER.toRequest(dto);
|
||||
// // 创建
|
||||
// return dataPermissionService.createDataPermission(request);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Integer updateDataPermissionById(DataPermissionUpdateDTO dto) {
|
||||
// log.info("DataPermissionApi.updateDataPermissionById dto: {}", JSON.toJSONString(dto));
|
||||
// Valid.valid(dto);
|
||||
// // 转换
|
||||
// DataPermissionUpdateRequest request = DataPermissionProviderConvert.MAPPER.toRequest(dto);
|
||||
// // 修改
|
||||
// return dataPermissionService.updateDataPermissionById(request);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Integer updateDataPermission(DataPermissionQueryDTO query, DataPermissionUpdateDTO update) {
|
||||
// log.info("DataPermissionApi.updateDataPermission query: {}, update: {}", JSON.toJSONString(query), JSON.toJSONString(update));
|
||||
// Valid.valid(query);
|
||||
// Valid.valid(update);
|
||||
// // 更新
|
||||
// int effect = dataPermissionService.updateDataPermission(DataPermissionProviderConvert.MAPPER.toRequest(query),
|
||||
// DataPermissionProviderConvert.MAPPER.toRequest(update));
|
||||
// log.info("DataPermissionApi.updateDataPermission effect: {}", effect);
|
||||
// return effect;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public DataPermissionDTO getDataPermissionById(Long id) {
|
||||
// log.info("DataPermissionApi.getDataPermissionById id: {}", id);
|
||||
// Valid.notNull(id, ErrorMessage.ID_MISSING);
|
||||
// // 修改
|
||||
// DataPermissionDO record = dataPermissionDAO.selectById(id);
|
||||
// if (record == null) {
|
||||
// return null;
|
||||
// }
|
||||
// // 转换
|
||||
// return DataPermissionProviderConvert.MAPPER.to(record);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<DataPermissionDTO> getDataPermissionByIdList(List<Long> idList) {
|
||||
// log.info("DataPermissionApi.getDataPermissionByIdList idList: {}", idList);
|
||||
// if (Lists.isEmpty(idList)) {
|
||||
// return new ArrayList<>();
|
||||
// }
|
||||
// // 查询
|
||||
// List<DataPermissionDO> rows = dataPermissionDAO.selectBatchIds(idList);
|
||||
// // 转换
|
||||
// return DataPermissionProviderConvert.MAPPER.toList(rows);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<DataPermissionDTO> getDataPermissionList(DataPermissionQueryDTO dto) {
|
||||
// log.info("DataPermissionApi.getDataPermissionList dto: {}", JSON.toJSONString(dto));
|
||||
// Valid.valid(dto);
|
||||
// // 条件
|
||||
// LambdaQueryWrapper<DataPermissionDO> wrapper = this.buildQueryWrapper(dto);
|
||||
// // 查询
|
||||
// return dataPermissionDAO.of(wrapper).list(DataPermissionProviderConvert.MAPPER::to);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Long getDataPermissionCount(DataPermissionQueryDTO dto) {
|
||||
// log.info("DataPermissionApi.getDataPermissionCount dto: {}", JSON.toJSONString(dto));
|
||||
// Valid.valid(dto);
|
||||
// // 条件
|
||||
// LambdaQueryWrapper<DataPermissionDO> wrapper = this.buildQueryWrapper(dto);
|
||||
// // 查询
|
||||
// return dataPermissionDAO.selectCount(wrapper);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Integer deleteDataPermissionById(Long id) {
|
||||
// log.info("DataPermissionApi.deleteDataPermissionById id: {}", id);
|
||||
// Valid.notNull(id, ErrorMessage.ID_MISSING);
|
||||
// // 删除
|
||||
// Integer effect = dataPermissionService.deleteDataPermissionById(id);
|
||||
// log.info("DataPermissionApi.deleteDataPermissionById id: {}, effect: {}", id, effect);
|
||||
// return effect;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Integer deleteDataPermissionByIdList(List<Long> idList) {
|
||||
// log.info("DataPermissionApi.deleteDataPermissionByIdList idList: {}", idList);
|
||||
// Valid.notEmpty(idList, ErrorMessage.ID_MISSING);
|
||||
// // 删除
|
||||
// Integer effect = dataPermissionService.deleteDataPermissionByIdList(idList);
|
||||
// log.info("DataPermissionApi.deleteDataPermissionByIdList effect: {}", effect);
|
||||
// return effect;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Integer deleteDataPermission(DataPermissionQueryDTO dto) {
|
||||
// log.info("DataPermissionApi.deleteDataPermission dto: {}", JSON.toJSONString(dto));
|
||||
// Valid.valid(dto);
|
||||
// // 删除
|
||||
// Integer effect = dataPermissionService.deleteDataPermission(DataPermissionProviderConvert.MAPPER.toRequest(dto));
|
||||
// log.info("DataPermissionApi.deleteDataPermission effect: {}", effect);
|
||||
// return effect;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 构建查询 wrapper
|
||||
// *
|
||||
// * @param dto dto
|
||||
// * @return wrapper
|
||||
// */
|
||||
// private LambdaQueryWrapper<DataPermissionDO> buildQueryWrapper(DataPermissionQueryDTO dto) {
|
||||
// return dataPermissionDAO.wrapper()
|
||||
// .eq(DataPermissionDO::getId, dto.getId())
|
||||
// .eq(DataPermissionDO::getUserId, dto.getUserId())
|
||||
// .eq(DataPermissionDO::getRoleId, dto.getRoleId())
|
||||
// .eq(DataPermissionDO::getRelId, dto.getRelId())
|
||||
// .eq(DataPermissionDO::getType, dto.getType());
|
||||
// }
|
||||
//
|
||||
// }
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.orion.ops.module.infra.convert;
|
||||
|
||||
import com.orion.ops.module.infra.entity.domain.*;
|
||||
import com.orion.ops.module.infra.entity.vo.*;
|
||||
import com.orion.ops.module.infra.entity.request.data.*;
|
||||
import com.orion.ops.module.infra.convert.*;
|
||||
import com.orion.ops.module.infra.define.operator.*;
|
||||
import com.orion.ops.module.infra.entity.dto.data.*;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据权限 对外服务对象转换器
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-11-21 10:32
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataPermissionProviderConvert {
|
||||
|
||||
DataPermissionProviderConvert MAPPER = Mappers.getMapper(DataPermissionProviderConvert.class);
|
||||
|
||||
DataPermissionDO to(DataPermissionDTO dto);
|
||||
|
||||
DataPermissionDTO to(DataPermissionDO domain);
|
||||
|
||||
DataPermissionDO to(DataPermissionQueryDTO domain);
|
||||
|
||||
DataPermissionDO to(DataPermissionUpdateDTO update);
|
||||
|
||||
DataPermissionCreateRequest toRequest(DataPermissionCreateDTO request);
|
||||
|
||||
DataPermissionUpdateRequest toRequest(DataPermissionUpdateDTO request);
|
||||
|
||||
List<DataPermissionDTO> toList(List<DataPermissionDO> list);
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import java.util.concurrent.TimeUnit;
|
||||
public interface DictCacheKeyDefine {
|
||||
|
||||
CacheKeyDefine DICT_KEY = new CacheKeyBuilder()
|
||||
.key("dict:keys")
|
||||
.key("dict:keys:list")
|
||||
.desc("字典配置项")
|
||||
.type(DictKeyCacheDTO.class)
|
||||
.struct(RedisCacheStruct.HASH)
|
||||
@@ -26,7 +26,7 @@ public interface DictCacheKeyDefine {
|
||||
.build();
|
||||
|
||||
CacheKeyDefine DICT_SCHEMA = new CacheKeyBuilder()
|
||||
.key("dict:schema:{}")
|
||||
.key("dict:key-schema:{}")
|
||||
.desc("字典配置项 schema ${key}")
|
||||
.type(JSONObject.class)
|
||||
.struct(RedisCacheStruct.STRING)
|
||||
|
||||
@@ -56,7 +56,7 @@ public class SecurityFrameworkServiceImpl implements SecurityFrameworkService {
|
||||
@Override
|
||||
public LoginUser getUserByToken(String token) {
|
||||
// 获取 token 信息
|
||||
LoginTokenDTO tokenInfo = authenticationService.getLoginTokenInfo(token, true);
|
||||
LoginTokenDTO tokenInfo = authenticationService.getLoginTokenInfo(token);
|
||||
if (tokenInfo == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -70,6 +70,9 @@ public class SecurityFrameworkServiceImpl implements SecurityFrameworkService {
|
||||
}
|
||||
// 获取登录信息
|
||||
LoginUser user = authenticationService.getLoginUser(tokenInfo.getId());
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
// 检查用户状态
|
||||
UserStatusEnum.checkUserStatus(user.getStatus());
|
||||
// 设置登录时间戳
|
||||
|
||||
@@ -53,10 +53,9 @@ public interface AuthenticationService {
|
||||
/**
|
||||
* 获取 token 信息
|
||||
*
|
||||
* @param loginToken loginToken
|
||||
* @param checkRefresh 是否检查 refreshToken
|
||||
* @param loginToken loginToken
|
||||
* @return tokenInfo
|
||||
*/
|
||||
LoginTokenDTO getLoginTokenInfo(String loginToken, boolean checkRefresh);
|
||||
LoginTokenDTO getLoginTokenInfo(String loginToken);
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.lang.utils.crypto.Signatures;
|
||||
import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
import com.orion.ops.framework.common.constant.ErrorCode;
|
||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.security.LoginUser;
|
||||
import com.orion.ops.framework.common.security.UserRole;
|
||||
@@ -134,14 +133,14 @@ public class AuthenticationServiceImpl implements AuthenticationService {
|
||||
// 查询用户信息
|
||||
SystemUserDO user = systemUserDAO.selectById(id);
|
||||
if (user == null) {
|
||||
throw Exceptions.httpWrapper(ErrorCode.UNAUTHORIZED);
|
||||
return null;
|
||||
}
|
||||
// 设置用户缓存
|
||||
return this.setUserCache(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginTokenDTO getLoginTokenInfo(String loginToken, boolean checkRefresh) {
|
||||
public LoginTokenDTO getLoginTokenInfo(String loginToken) {
|
||||
// 获取登录 key pair
|
||||
Pair<Long, Long> pair = this.getLoginTokenPair(loginToken);
|
||||
if (pair == null) {
|
||||
@@ -154,7 +153,7 @@ public class AuthenticationServiceImpl implements AuthenticationService {
|
||||
return JSON.parseObject(loginCache, LoginTokenDTO.class);
|
||||
}
|
||||
// loginToken 不存在 需要查询 refreshToken
|
||||
if (!checkRefresh || !allowRefresh) {
|
||||
if (!allowRefresh) {
|
||||
return null;
|
||||
}
|
||||
String refreshKey = UserCacheKeyDefine.LOGIN_REFRESH.format(pair.getKey(), pair.getValue());
|
||||
@@ -321,9 +320,8 @@ public class AuthenticationServiceImpl implements AuthenticationService {
|
||||
@SuppressWarnings("ALL")
|
||||
private void invalidOtherDeviceToken(Long id, long loginTime,
|
||||
String remoteAddr, String location, String userAgent) {
|
||||
String loginKey = UserCacheKeyDefine.LOGIN_TOKEN.format(id, "*");
|
||||
// 获取登录信息
|
||||
Set<String> loginKeyList = RedisUtils.scanKeys(loginKey);
|
||||
Set<String> loginKeyList = RedisUtils.scanKeys(UserCacheKeyDefine.LOGIN_TOKEN.format(id, "*"));
|
||||
if (!loginKeyList.isEmpty()) {
|
||||
// 获取有效登录信息
|
||||
List<LoginTokenDTO> loginTokenInfoList = redisTemplate.opsForValue()
|
||||
@@ -343,11 +341,7 @@ public class AuthenticationServiceImpl implements AuthenticationService {
|
||||
}
|
||||
// 删除续签信息
|
||||
if (allowRefresh) {
|
||||
String refreshKey = UserCacheKeyDefine.LOGIN_REFRESH.format(id, "*");
|
||||
Set<String> refreshKeyList = RedisUtils.scanKeys(refreshKey);
|
||||
if (!refreshKeyList.isEmpty()) {
|
||||
redisTemplate.delete(refreshKeyList);
|
||||
}
|
||||
RedisUtils.scanKeysDelete(UserCacheKeyDefine.LOGIN_REFRESH.format(id, "*"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -236,20 +236,13 @@ public class DataPermissionServiceImpl implements DataPermissionService {
|
||||
|
||||
@Override
|
||||
public void clearUserCache(List<Long> userIdList) {
|
||||
// 构建 key 匹配
|
||||
List<String> keyPatterns = userIdList.stream()
|
||||
// 扫描的 key
|
||||
List<String> keyMatchs = userIdList.stream()
|
||||
.distinct()
|
||||
.map(s -> DataPermissionCacheKeyDefine.DATA_PERMISSION_USER.format("*", s))
|
||||
.collect(Collectors.toList());
|
||||
// 扫描所有 key
|
||||
List<String> deleteKeys = keyPatterns.stream()
|
||||
.map(RedisUtils::scanKeys)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
// 删除 key
|
||||
if (!deleteKeys.isEmpty()) {
|
||||
RedisUtils.delete(deleteKeys);
|
||||
}
|
||||
// 扫描并删除
|
||||
RedisUtils.scanKeysDelete(keyMatchs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.lang.utils.Objects1;
|
||||
import com.orion.lang.utils.Strings;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.lang.utils.collect.Maps;
|
||||
import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
@@ -166,14 +165,14 @@ public class DictKeyServiceImpl implements DictKeyService {
|
||||
|
||||
@Override
|
||||
public void refreshCache() {
|
||||
Set<String> schemaKeys = RedisUtils.scanKeys(DictCacheKeyDefine.DICT_SCHEMA.format("*"));
|
||||
Set<String> valueKeys = RedisUtils.scanKeys(DictCacheKeyDefine.DICT_VALUE.format("*"));
|
||||
// 需要删除的缓存 key
|
||||
List<String> list = Lists.of(DictCacheKeyDefine.DICT_KEY.getKey());
|
||||
list.addAll(schemaKeys);
|
||||
list.addAll(valueKeys);
|
||||
// 删除缓存
|
||||
RedisUtils.delete(list);
|
||||
RedisUtils.scanKeysDelete(
|
||||
// 删除字典配置项 schema
|
||||
DictCacheKeyDefine.DICT_SCHEMA.format("*"),
|
||||
// 删除字典配置值
|
||||
DictCacheKeyDefine.DICT_VALUE.format("*")
|
||||
);
|
||||
// 删除字典配置项列表
|
||||
RedisUtils.delete(DictCacheKeyDefine.DICT_KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -260,18 +259,10 @@ public class SystemUserServiceImpl implements SystemUserService {
|
||||
// 删除登录失败次数缓存
|
||||
RedisUtils.delete(UserCacheKeyDefine.LOGIN_FAILED_COUNT.format(record.getUsername()));
|
||||
// 删除登录缓存
|
||||
String loginKey = UserCacheKeyDefine.LOGIN_TOKEN.format(id, "*");
|
||||
Set<String> loginKeyList = RedisUtils.scanKeys(loginKey);
|
||||
if (!loginKeyList.isEmpty()) {
|
||||
RedisUtils.delete(loginKeyList);
|
||||
}
|
||||
RedisUtils.scanKeysDelete(UserCacheKeyDefine.LOGIN_TOKEN.format(id, "*"));
|
||||
// 删除续签信息
|
||||
if (AuthenticationService.allowRefresh) {
|
||||
String refreshKey = UserCacheKeyDefine.LOGIN_REFRESH.format(id, "*");
|
||||
Set<String> refreshKeyList = RedisUtils.scanKeys(refreshKey);
|
||||
if (!refreshKeyList.isEmpty()) {
|
||||
RedisUtils.delete(refreshKeyList);
|
||||
}
|
||||
RedisUtils.scanKeysDelete(UserCacheKeyDefine.LOGIN_REFRESH.format(id, "*"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user