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());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user