docs: 注释优化
This commit is contained in:
@@ -1,19 +1,26 @@
|
||||
package com.youlai.boot.common.annotation;
|
||||
|
||||
|
||||
import com.youlai.boot.core.validator.FieldValidator;
|
||||
import jakarta.validation.Constraint;
|
||||
import jakarta.validation.Payload;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 用于验证字段值是否合法的注解
|
||||
*
|
||||
* @author Ray.Hao
|
||||
* @since 2.18.0
|
||||
*/
|
||||
@Documented
|
||||
@Constraint(validatedBy = FieldValidator.class)
|
||||
@Target({ElementType.FIELD, ElementType.PARAMETER})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ValidField {
|
||||
|
||||
|
||||
/**
|
||||
* 验证失败时的错误信息。
|
||||
*/
|
||||
String message() default "非法字段";
|
||||
|
||||
Class<?>[] groups() default {};
|
||||
@@ -21,7 +28,7 @@ public @interface ValidField {
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
|
||||
/**
|
||||
* 允许的字段值
|
||||
* 允许的合法值列表。
|
||||
*/
|
||||
String[] allowedValues();
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.alibaba.excel.event.AnalysisEventListener;
|
||||
/**
|
||||
* 自定义解析结果监听器
|
||||
*
|
||||
* @author haoxr
|
||||
* @author Ray.Hao
|
||||
* @since 2023/03/01
|
||||
*/
|
||||
public abstract class BaseAnalysisEventListener<T> extends AnalysisEventListener<T> {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.youlai.boot.common.constant;
|
||||
|
||||
/**
|
||||
* 缓存常量
|
||||
* 安全模块常量
|
||||
*
|
||||
* @author haoxr
|
||||
* @author Ray.Hao
|
||||
* @since 2023/11/24
|
||||
*/
|
||||
public interface SecurityConstants {
|
||||
@@ -23,25 +23,18 @@ public interface SecurityConstants {
|
||||
*/
|
||||
String BLACKLIST_TOKEN_PREFIX = "token:blacklist:";
|
||||
|
||||
|
||||
/**
|
||||
* 登录路径
|
||||
*/
|
||||
String LOGIN_PATH = "/api/v1/auth/login";
|
||||
|
||||
|
||||
/**
|
||||
* JWT Token 前缀
|
||||
*/
|
||||
String JWT_TOKEN_PREFIX = "Bearer ";
|
||||
|
||||
/**
|
||||
* 微信登录路径
|
||||
*/
|
||||
String WECHAT_LOGIN_PATH = "/api/v1/auth/wechat-login";
|
||||
|
||||
/**
|
||||
* 角色前缀 Spring Security 的 authorities 角色前缀,用于区分角色和权限
|
||||
* 角色前缀,用于区分 authorities 角色和权限, ROLE_* 角色 、没有前缀的是权限
|
||||
*/
|
||||
String ROLE_PREFIX = "ROLE_";
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.nio.charset.StandardCharsets;
|
||||
/**
|
||||
* 响应工具类
|
||||
*
|
||||
* @author Ray Hao
|
||||
* @author Ray.Hao
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Slf4j
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
/**
|
||||
* mybatis-plus 自动配置类
|
||||
* mybatis-plus 配置类
|
||||
*
|
||||
* @author Ray.Hao
|
||||
* @since 2022/7/2
|
||||
|
||||
@@ -11,15 +11,16 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Spring Security访问异常处理器
|
||||
* 无权限访问处理器
|
||||
*
|
||||
* @author haoxr
|
||||
* @since 2022/10/18
|
||||
* @author Ray.Hao
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Component
|
||||
public class MyAccessDeniedHandler implements AccessDeniedHandler {
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,12 +15,11 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 认证异常处理
|
||||
* 未认证处理器
|
||||
*
|
||||
* @author Ray.Hao
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Component
|
||||
public class MyAuthenticationEntryPoint implements AuthenticationEntryPoint {
|
||||
@Override
|
||||
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);
|
||||
} else {
|
||||
if (authException instanceof UsernameNotFoundException || authException instanceof BadCredentialsException) {
|
||||
if (authException instanceof BadCredentialsException) {
|
||||
// 用户名或密码错误
|
||||
ResponseUtils.writeErrMsg(response, ResultCode.USER_PASSWORD_ERROR);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user