增加令牌刷新逻辑
增加演示模式的开关
This commit is contained in:
@@ -49,10 +49,12 @@ public class AdminSecurityAutoConfiguration implements WebMvcConfigurer {
|
||||
.excludePathPatterns(properties.getDefaultIgnorePaths());
|
||||
logger.info("[addInterceptors][加载 AdminSecurityInterceptor 拦截器完成]");
|
||||
// AdminDemoInterceptor 拦截器
|
||||
registry.addInterceptor(this.adminDemoInterceptor())
|
||||
.excludePathPatterns(properties.getIgnorePaths())
|
||||
.excludePathPatterns(properties.getDefaultIgnorePaths());
|
||||
logger.info("[addInterceptors][加载 AdminDemoInterceptor 拦截器完成]");
|
||||
if (Boolean.TRUE.equals(properties.getDemo())) {
|
||||
registry.addInterceptor(this.adminDemoInterceptor())
|
||||
.excludePathPatterns(properties.getIgnorePaths())
|
||||
.excludePathPatterns(properties.getDefaultIgnorePaths());
|
||||
logger.info("[addInterceptors][加载 AdminDemoInterceptor 拦截器完成]");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,11 @@ public class AdminSecurityProperties {
|
||||
// Actuator 相关
|
||||
};
|
||||
|
||||
/**
|
||||
* 演示模式 - 默认值(关闭)
|
||||
*/
|
||||
private static final Boolean DEFAULT_DEMO = false;
|
||||
|
||||
/**
|
||||
* 自定义忽略 Path
|
||||
*/
|
||||
@@ -19,6 +24,10 @@ public class AdminSecurityProperties {
|
||||
* 默认忽略 Path
|
||||
*/
|
||||
private String[] defaultIgnorePaths = DEFAULT_IGNORE_PATHS;
|
||||
/**
|
||||
* 是否开启演示模式
|
||||
*/
|
||||
private Boolean demo = DEFAULT_DEMO;
|
||||
|
||||
public String[] getIgnorePaths() {
|
||||
return ignorePaths;
|
||||
@@ -38,4 +47,13 @@ public class AdminSecurityProperties {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Boolean getDemo() {
|
||||
return demo;
|
||||
}
|
||||
|
||||
public AdminSecurityProperties setDemo(Boolean demo) {
|
||||
this.demo = demo;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,8 +19,9 @@ public class AdminDemoInterceptor extends HandlerInterceptorAdapter {
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||
// 当 Admin 编号等于 0 时,约定为演示账号
|
||||
if (Objects.equals(AdminSecurityContextHolder.getAdminId(), 0)
|
||||
// 当 Admin 编号等于 1 时,约定为演示账号
|
||||
// TODO 芋艿,后续去优化
|
||||
if (Objects.equals(AdminSecurityContextHolder.getAdminId(), 1)
|
||||
&& request.getMethod().equalsIgnoreCase(HttpMethod.POST.toString())) {
|
||||
throw ServiceExceptionUtil.exception(SystemErrorCodeConstants.PERMISSION_DEMO_PERMISSION_DENY);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user