mirror of
https://gitee.com/dromara/sa-token.git
synced 2026-02-27 16:50:24 +08:00
新增Reactor响应式编程支持,WebFlux集成!
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
package cn.dev33.satoken.autowired;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
/**
|
||||
* 将此注解加到springboot启动类上,即可完成sa-token与springboot的集成
|
||||
* <p>注: v1.7版本以上已不再需要此注解,直接引入sa-token-spring-boot-starter依赖即可
|
||||
* <p>请直接忽略此注解
|
||||
* @author kong
|
||||
*
|
||||
*/
|
||||
@Documented
|
||||
@Target({java.lang.annotation.ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Configuration
|
||||
@Import({SaTokenSpringAutowired.class})
|
||||
public @interface SaTokenSetup {
|
||||
|
||||
}
|
||||
@@ -5,9 +5,9 @@ import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import cn.dev33.satoken.context.model.servlet.SaRequestForServlet;
|
||||
import cn.dev33.satoken.context.model.servlet.SaResponseForServlet;
|
||||
import cn.dev33.satoken.router.SaRouteFunction;
|
||||
import cn.dev33.satoken.servlet.model.SaRequestForServlet;
|
||||
import cn.dev33.satoken.servlet.model.SaResponseForServlet;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package cn.dev33.satoken.spring;
|
||||
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import org.springframework.util.PathMatcher;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kong
|
||||
*
|
||||
*/
|
||||
public class SaPathMatcherHolder {
|
||||
|
||||
/**
|
||||
* 路由匹配器
|
||||
*/
|
||||
public static PathMatcher pathMatcher;
|
||||
|
||||
/**
|
||||
* 获取路由匹配器
|
||||
* @return 路由匹配器
|
||||
*/
|
||||
public static PathMatcher getPathMatcher() {
|
||||
if(pathMatcher == null) {
|
||||
pathMatcher = new AntPathMatcher();
|
||||
}
|
||||
return pathMatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入路由匹配器
|
||||
* @param pathMatcher 路由匹配器
|
||||
*/
|
||||
public static void setPathMatcher(PathMatcher pathMatcher) {
|
||||
SaPathMatcherHolder.pathMatcher = pathMatcher;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
package cn.dev33.satoken.spring;
|
||||
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import org.springframework.util.PathMatcher;
|
||||
|
||||
import cn.dev33.satoken.context.SaTokenContext;
|
||||
import cn.dev33.satoken.context.model.SaRequest;
|
||||
import cn.dev33.satoken.context.model.SaResponse;
|
||||
import cn.dev33.satoken.context.model.servlet.SaRequestForServlet;
|
||||
import cn.dev33.satoken.context.model.servlet.SaResponseForServlet;
|
||||
import cn.dev33.satoken.context.model.SaStorage;
|
||||
import cn.dev33.satoken.servlet.model.SaRequestForServlet;
|
||||
import cn.dev33.satoken.servlet.model.SaResponseForServlet;
|
||||
import cn.dev33.satoken.servlet.model.SaStorageForServlet;
|
||||
|
||||
/**
|
||||
* sa-token 对Cookie的相关操作 接口实现类
|
||||
@@ -34,27 +33,11 @@ public class SaTokenContextForSpring implements SaTokenContext {
|
||||
}
|
||||
|
||||
/**
|
||||
* 路由匹配器
|
||||
* 获取当前请求的 [存储器] 对象
|
||||
*/
|
||||
private static PathMatcher pathMatcher;
|
||||
|
||||
/**
|
||||
* 获取路由匹配器
|
||||
* @return 路由匹配器
|
||||
*/
|
||||
public static PathMatcher getPathMatcher() {
|
||||
if(pathMatcher == null) {
|
||||
pathMatcher = new AntPathMatcher();
|
||||
}
|
||||
return pathMatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入路由匹配器
|
||||
* @param pathMatcher 路由匹配器
|
||||
*/
|
||||
public static void setPathMatcher(PathMatcher pathMatcher) {
|
||||
SaTokenContextForSpring.pathMatcher = pathMatcher;
|
||||
@Override
|
||||
public SaStorage getStorage() {
|
||||
return new SaStorageForServlet(SpringMVCUtil.getRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,7 +45,9 @@ public class SaTokenContextForSpring implements SaTokenContext {
|
||||
*/
|
||||
@Override
|
||||
public boolean matchPath(String pattern, String path) {
|
||||
return getPathMatcher().match(pattern, path);
|
||||
return SaPathMatcherHolder.getPathMatcher().match(pattern, path);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.dev33.satoken.autowired;
|
||||
package cn.dev33.satoken.spring;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@@ -11,7 +11,8 @@ import cn.dev33.satoken.action.SaTokenAction;
|
||||
import cn.dev33.satoken.config.SaTokenConfig;
|
||||
import cn.dev33.satoken.context.SaTokenContext;
|
||||
import cn.dev33.satoken.dao.SaTokenDao;
|
||||
import cn.dev33.satoken.spring.SaTokenContextForSpring;
|
||||
import cn.dev33.satoken.filter.SaFilterErrorStrategy;
|
||||
import cn.dev33.satoken.filter.SaFilterStrategy;
|
||||
import cn.dev33.satoken.stp.StpInterface;
|
||||
|
||||
/**
|
||||
@@ -94,6 +95,26 @@ public class SaTokenSpringAutowired {
|
||||
SaTokenManager.setSaTokenContext(saTokenContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入[sa-token全局过滤器-认证策略]
|
||||
*
|
||||
* @param strategy see note
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaFilterStrategy(SaFilterStrategy strategy) {
|
||||
SaTokenManager.setSaFilterStrategy(strategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入[sa-token全局过滤器-异常处理策略]
|
||||
*
|
||||
* @param errorStrategy see note
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setSaFilterErrorStrategy(SaFilterErrorStrategy errorStrategy) {
|
||||
SaTokenManager.setSaFilterErrorStrategy(errorStrategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 利用自动匹配特性,获取SpringMVC框架内部使用的路由匹配器
|
||||
*
|
||||
@@ -101,7 +122,7 @@ public class SaTokenSpringAutowired {
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public void setPathMatcher(PathMatcher pathMatcher) {
|
||||
SaTokenContextForSpring.setPathMatcher(pathMatcher);
|
||||
SaPathMatcherHolder.setPathMatcher(pathMatcher);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user