解决swagger2不可见
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
package org.nl.modules.security.satoken;
|
||||
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import cn.dev33.satoken.interceptor.SaAnnotationInterceptor;
|
||||
import cn.dev33.satoken.interceptor.SaRouteInterceptor;
|
||||
import cn.dev33.satoken.interceptor.SaInterceptor;
|
||||
import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
|
||||
import cn.dev33.satoken.router.SaRouter;
|
||||
import cn.dev33.satoken.stp.StpLogic;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -12,7 +9,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
@@ -38,44 +34,9 @@ public class SaTokenConfigure implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
// 注册 Sa-Token 拦截器,打开注解式鉴权功能
|
||||
// registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
|
||||
// .addPathPatterns("/**")
|
||||
// .excludePathPatterns(securityProperties.getExcludes()); // 白名单
|
||||
registry.addInterceptor(new SaRouteInterceptor((request, response, handler) -> {
|
||||
System.out.println(SaHolder.getRequest().getRequestPath());
|
||||
// 登录验证 -- 排除多个路径
|
||||
SaRouter
|
||||
// 获取所有的
|
||||
.match("/**")
|
||||
// 排除下不需要拦截的
|
||||
.notMatch(securityProperties.getExcludes())
|
||||
// 对未排除的路径进行检查
|
||||
.check(() -> {
|
||||
// 检查是否登录 是否有token
|
||||
StpUtil.checkLogin();
|
||||
|
||||
// 有效率影响 用于临时测试
|
||||
// if (log.isDebugEnabled()) {
|
||||
// log.debug("剩余有效时间: {}", StpUtil.getTokenTimeout());
|
||||
// log.debug("临时有效时间: {}", StpUtil.getTokenActivityTimeout());
|
||||
// }
|
||||
|
||||
});
|
||||
})).addPathPatterns("/**");
|
||||
registry.addInterceptor(new SaAnnotationInterceptor()).addPathPatterns("/**");
|
||||
|
||||
|
||||
|
||||
registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns(securityProperties.getExcludes()); // 白名单
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加资源处理程序
|
||||
* @param registry 注册表
|
||||
*/
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/**").addResourceLocations("classpath:/resources/")
|
||||
.addResourceLocations("classpath:/static/").addResourceLocations("classpath:/public/")
|
||||
.resourceChain(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,4 +66,23 @@ public class UserDto extends BaseDTO implements Serializable {
|
||||
### 加密规则
|
||||
```
|
||||
SaSecureUtil.md5BySalt("123456", "salt")
|
||||
```
|
||||
|
||||
### 另一种拦截
|
||||
```
|
||||
registry.addInterceptor(new SaRouteInterceptor((request, response, handler) -> {
|
||||
System.out.println(SaHolder.getRequest().getRequestPath());
|
||||
// 登录验证 -- 排除多个路径
|
||||
SaRouter
|
||||
// 获取所有的
|
||||
.match("/**")
|
||||
// 排除下不需要拦截的
|
||||
.notMatch(securityProperties.getExcludes())
|
||||
// 对未排除的路径进行检查
|
||||
.check(() -> {
|
||||
// 检查是否登录 是否有token
|
||||
StpUtil.checkLogin();
|
||||
});
|
||||
})).addPathPatterns("/**");
|
||||
registry.addInterceptor(new SaAnnotationInterceptor()).addPathPatterns("/**");
|
||||
```
|
||||
Reference in New Issue
Block a user