优化 sa-token-reactor-spring-boot-starter3 模块注释

This commit is contained in:
click33 2023-05-11 17:26:56 +08:00
parent 844ff900e9
commit b2064c75e6
11 changed files with 39 additions and 28 deletions

View File

@ -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

View File

@ -13,7 +13,7 @@ import cn.dev33.satoken.context.model.SaStorage;
public class SaStorageForReactor implements SaStorage {
/**
* 底层Request对象
* 底层 ServerWebExchange 对象
*/
protected ServerWebExchange exchange;

View File

@ -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 {

View File

@ -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 {

View File

@ -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;
}

View File

@ -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");
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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;

View File

@ -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 {

View File

@ -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() {