docs: 注释优化

This commit is contained in:
Ray.Hao
2024-12-25 22:39:07 +08:00
parent eaf03138b9
commit 38469fefe5
7 changed files with 24 additions and 24 deletions

View File

@@ -1,19 +1,26 @@
package com.youlai.boot.common.annotation; package com.youlai.boot.common.annotation;
import com.youlai.boot.core.validator.FieldValidator; import com.youlai.boot.core.validator.FieldValidator;
import jakarta.validation.Constraint; import jakarta.validation.Constraint;
import jakarta.validation.Payload; import jakarta.validation.Payload;
import java.lang.annotation.*; import java.lang.annotation.*;
/**
* 用于验证字段值是否合法的注解
*
* @author Ray.Hao
* @since 2.18.0
*/
@Documented @Documented
@Constraint(validatedBy = FieldValidator.class) @Constraint(validatedBy = FieldValidator.class)
@Target({ElementType.FIELD, ElementType.PARAMETER}) @Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface ValidField { public @interface ValidField {
/**
* 验证失败时的错误信息。
*/
String message() default "非法字段"; String message() default "非法字段";
Class<?>[] groups() default {}; Class<?>[] groups() default {};
@@ -21,7 +28,7 @@ public @interface ValidField {
Class<? extends Payload>[] payload() default {}; Class<? extends Payload>[] payload() default {};
/** /**
* 允许的字段值 * 允许的合法值列表。
*/ */
String[] allowedValues(); String[] allowedValues();

View File

@@ -5,7 +5,7 @@ import com.alibaba.excel.event.AnalysisEventListener;
/** /**
* 自定义解析结果监听器 * 自定义解析结果监听器
* *
* @author haoxr * @author Ray.Hao
* @since 2023/03/01 * @since 2023/03/01
*/ */
public abstract class BaseAnalysisEventListener<T> extends AnalysisEventListener<T> { public abstract class BaseAnalysisEventListener<T> extends AnalysisEventListener<T> {

View File

@@ -1,9 +1,9 @@
package com.youlai.boot.common.constant; package com.youlai.boot.common.constant;
/** /**
* 缓存常量 * 安全模块常量
* *
* @author haoxr * @author Ray.Hao
* @since 2023/11/24 * @since 2023/11/24
*/ */
public interface SecurityConstants { public interface SecurityConstants {
@@ -23,25 +23,18 @@ public interface SecurityConstants {
*/ */
String BLACKLIST_TOKEN_PREFIX = "token:blacklist:"; String BLACKLIST_TOKEN_PREFIX = "token:blacklist:";
/** /**
* 登录路径 * 登录路径
*/ */
String LOGIN_PATH = "/api/v1/auth/login"; String LOGIN_PATH = "/api/v1/auth/login";
/** /**
* JWT Token 前缀 * JWT Token 前缀
*/ */
String JWT_TOKEN_PREFIX = "Bearer "; String JWT_TOKEN_PREFIX = "Bearer ";
/** /**
* 微信登录路径 * 角色前缀,用于区分 authorities 角色和权限, ROLE_* 角色 、没有前缀的是权限
*/
String WECHAT_LOGIN_PATH = "/api/v1/auth/wechat-login";
/**
* 角色前缀 Spring Security 的 authorities 角色前缀,用于区分角色和权限
*/ */
String ROLE_PREFIX = "ROLE_"; String ROLE_PREFIX = "ROLE_";
} }

View File

@@ -15,7 +15,7 @@ import java.nio.charset.StandardCharsets;
/** /**
* 响应工具类 * 响应工具类
* *
* @author Ray Hao * @author Ray.Hao
* @since 2.0.0 * @since 2.0.0
*/ */
@Slf4j @Slf4j

View File

@@ -12,7 +12,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
/** /**
* mybatis-plus 自动配置类 * mybatis-plus 配置类
* *
* @author Ray.Hao * @author Ray.Hao
* @since 2022/7/2 * @since 2022/7/2

View File

@@ -11,15 +11,16 @@ import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
/** /**
* Spring Security访问异常处理器 * 无权限访问处理器
* *
* @author haoxr * @author Ray.Hao
* @since 2022/10/18 * @since 2.0.0
*/ */
@Component
public class MyAccessDeniedHandler implements AccessDeniedHandler { public class MyAccessDeniedHandler implements AccessDeniedHandler {
@Override @Override
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException { public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) {
ResponseUtils.writeErrMsg(response, ResultCode.ACCESS_UNAUTHORIZED); ResponseUtils.writeErrMsg(response, ResultCode.ACCESS_UNAUTHORIZED);
} }
} }

View File

@@ -15,12 +15,11 @@ import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
/** /**
* 认证异常处理 * 认证处理
* *
* @author Ray.Hao * @author Ray.Hao
* @since 2.0.0 * @since 2.0.0
*/ */
@Component
public class MyAuthenticationEntryPoint implements AuthenticationEntryPoint { public class MyAuthenticationEntryPoint implements AuthenticationEntryPoint {
@Override @Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
@@ -29,7 +28,7 @@ public class MyAuthenticationEntryPoint implements AuthenticationEntryPoint {
// 资源不存在 // 资源不存在
ResponseUtils.writeErrMsg(response, ResultCode.USER_RESOURCE_NOT_FOUND); ResponseUtils.writeErrMsg(response, ResultCode.USER_RESOURCE_NOT_FOUND);
} else { } else {
if (authException instanceof UsernameNotFoundException || authException instanceof BadCredentialsException) { if (authException instanceof BadCredentialsException) {
// 用户名或密码错误 // 用户名或密码错误
ResponseUtils.writeErrMsg(response, ResultCode.USER_PASSWORD_ERROR); ResponseUtils.writeErrMsg(response, ResultCode.USER_PASSWORD_ERROR);
} else { } else {