mirror of
https://gitee.com/dromara/sa-token.git
synced 2024-12-02 03:47:50 +08:00
优化 sa-token-reactor-spring-boot-starter3 模块注释
This commit is contained in:
parent
844ff900e9
commit
b2064c75e6
@ -13,7 +13,7 @@ import cn.dev33.satoken.reactor.model.SaResponseForReactor;
|
||||
import cn.dev33.satoken.reactor.model.SaStorageForReactor;
|
||||
|
||||
/**
|
||||
* Reactor上下文操作 [同步],持有当前请求的 ServerWebExchange 全局引用
|
||||
* Reactor上下文操作(同步),持有当前请求的 ServerWebExchange 全局引用
|
||||
*
|
||||
* @author click33
|
||||
* @since <= 1.34.0
|
||||
|
@ -13,7 +13,7 @@ import cn.dev33.satoken.context.model.SaStorage;
|
||||
public class SaStorageForReactor implements SaStorage {
|
||||
|
||||
/**
|
||||
* 底层Request对象
|
||||
* 底层 ServerWebExchange 对象
|
||||
*/
|
||||
protected ServerWebExchange exchange;
|
||||
|
||||
|
@ -5,9 +5,10 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* Reactor上下文操作 [异步]
|
||||
* @author click33
|
||||
* Reactor 上下文操作(异步),持有当前请求的 ServerWebExchange 全局引用
|
||||
*
|
||||
* @author click33
|
||||
* @since <= 1.34.0
|
||||
*/
|
||||
public class SaReactorHolder {
|
||||
|
||||
|
@ -13,9 +13,10 @@ import cn.dev33.satoken.reactor.model.SaResponseForReactor;
|
||||
import cn.dev33.satoken.reactor.model.SaStorageForReactor;
|
||||
|
||||
/**
|
||||
* Reactor上下文操作 [同步]
|
||||
* @author click33
|
||||
* Reactor上下文操作(同步),持有当前请求的 ServerWebExchange 全局引用
|
||||
*
|
||||
* @author click33
|
||||
* @since <= 1.34.0
|
||||
*/
|
||||
public class SaReactorSyncHolder {
|
||||
|
||||
|
@ -1,20 +1,20 @@
|
||||
package cn.dev33.satoken.reactor.error;
|
||||
|
||||
/**
|
||||
* 定义 sa-token-reactor-spring-boot-starter 所有异常细分状态码
|
||||
* 定义 sa-token-reactor3-spring-boot-starter 所有异常细分状态码
|
||||
*
|
||||
* @author click33
|
||||
* @since: 2022-10-30
|
||||
* @since <= 1.34.0
|
||||
*/
|
||||
public interface SaReactorSpringBootErrorCode {
|
||||
|
||||
/** 对象转 JSON 字符串失败 */
|
||||
public static final int CODE_20203 = 20203;
|
||||
int CODE_20203 = 20203;
|
||||
|
||||
/** JSON 字符串转 Map 失败 */
|
||||
public static final int CODE_20204 = 20204;
|
||||
int CODE_20204 = 20204;
|
||||
|
||||
/** 默认的 Filter 异常处理函数 */
|
||||
public static final int CODE_20205 = 20205;
|
||||
int CODE_20205 = 20205;
|
||||
|
||||
}
|
||||
|
@ -23,9 +23,13 @@ import cn.dev33.satoken.util.SaTokenConsts;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* Reactor全局过滤器
|
||||
* @author click33
|
||||
* Reactor 全局鉴权过滤器
|
||||
* <p>
|
||||
* 默认优先级为 -100,尽量保证在其它过滤器之前执行
|
||||
* </p>
|
||||
*
|
||||
* @author click33
|
||||
* @since <= 1.34.0
|
||||
*/
|
||||
@Order(SaTokenConsts.ASSEMBLY_ORDER)
|
||||
public class SaReactorFilter implements SaFilter, WebFilter {
|
||||
@ -132,6 +136,8 @@ public class SaReactorFilter implements SaFilter, WebFilter {
|
||||
String result = (e instanceof BackResultException) ? e.getMessage() : String.valueOf(error.run(e));
|
||||
|
||||
// 2. 写入输出流
|
||||
// 请注意此处默认 Content-Type 为 text/plain,如果需要返回 JSON 信息,需要在 return 前自行设置 Content-Type 为 application/json
|
||||
// 例如:SaHolder.getResponse().setHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
if(exchange.getResponse().getHeaders().getFirst("Content-Type") == null) {
|
||||
exchange.getResponse().getHeaders().set("Content-Type", "text/plain; charset=utf-8");
|
||||
}
|
||||
|
@ -18,9 +18,10 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Request for Reactor
|
||||
* @author click33
|
||||
* 对 SaRequest 包装类的实现(Reactor 响应式编程版)
|
||||
*
|
||||
* @author click33
|
||||
* @since <= 1.34.0
|
||||
*/
|
||||
public class SaRequestForReactor implements SaRequest {
|
||||
|
||||
|
@ -8,9 +8,10 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import cn.dev33.satoken.context.model.SaResponse;
|
||||
|
||||
/**
|
||||
* Response for Reactor
|
||||
* @author click33
|
||||
* 对 SaResponse 包装类的实现(Reactor 响应式编程版)
|
||||
*
|
||||
* @author click33
|
||||
* @since <= 1.34.0
|
||||
*/
|
||||
public class SaResponseForReactor implements SaResponse {
|
||||
|
||||
|
@ -5,14 +5,15 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
import cn.dev33.satoken.context.model.SaStorage;
|
||||
|
||||
/**
|
||||
* Storage for Reactor
|
||||
* @author click33
|
||||
* 对 SaStorage 包装类的实现(Reactor 响应式编程版)
|
||||
*
|
||||
* @author click33
|
||||
* @since <= 1.34.0
|
||||
*/
|
||||
public class SaStorageForReactor implements SaStorage {
|
||||
|
||||
/**
|
||||
* 底层Request对象
|
||||
* 底层 ServerWebExchange 对象
|
||||
*/
|
||||
protected ServerWebExchange exchange;
|
||||
|
||||
|
@ -4,10 +4,10 @@ import cn.dev33.satoken.context.SaTokenContextForThreadLocal;
|
||||
import cn.dev33.satoken.spring.SaPathMatcherHolder;
|
||||
|
||||
/**
|
||||
* Sa-Token 上下文处理器 [ Spring Reactor 版本实现 ]
|
||||
* Sa-Token 上下文处理器 [ Spring Reactor 版本实现 ] ,基于 SaTokenContextForThreadLocal 定制
|
||||
*
|
||||
* @author click33
|
||||
*
|
||||
* @since <= 1.34.0
|
||||
*/
|
||||
public class SaTokenContextForSpringReactor extends SaTokenContextForThreadLocal {
|
||||
|
||||
|
@ -5,17 +5,17 @@ import org.springframework.context.annotation.Bean;
|
||||
import cn.dev33.satoken.context.SaTokenContext;
|
||||
|
||||
/**
|
||||
* 注册Sa-Token所需要的Bean
|
||||
* <p> Bean 的注册与注入应该分开在两个文件中,否则在某些场景下会造成循环依赖
|
||||
* @author click33
|
||||
* 注册 Sa-Token 所需要的 Bean
|
||||
*
|
||||
* @author click33
|
||||
* @since <= 1.34.0
|
||||
*/
|
||||
public class SaTokenContextRegister {
|
||||
|
||||
/**
|
||||
* 获取容器交互Bean (ThreadLocal版)
|
||||
*
|
||||
* @return 容器交互Bean (ThreadLocal版)
|
||||
* 获取上下文处理器组件 (Spring Reactor 版)
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
@Bean
|
||||
public SaTokenContext getSaTokenContextForSpringReactor() {
|
||||
|
Loading…
Reference in New Issue
Block a user