wip: 临时提交
This commit is contained in:
@@ -10,7 +10,7 @@ import com.youlai.boot.core.security.exception.MyAuthenticationEntryPoint;
|
||||
import com.youlai.boot.core.security.extension.sms.SmsAuthenticationProvider;
|
||||
import com.youlai.boot.core.security.extension.wechat.WechatAuthenticationProvider;
|
||||
import com.youlai.boot.core.security.filter.CaptchaValidationFilter;
|
||||
import com.youlai.boot.core.security.filter.TokenFilter;
|
||||
import com.youlai.boot.core.security.filter.TokenAuthenticationFilter;
|
||||
import com.youlai.boot.core.security.manager.TokenManager;
|
||||
import com.youlai.boot.core.security.service.SysUserDetailsService;
|
||||
import com.youlai.boot.system.service.ConfigService;
|
||||
@@ -94,7 +94,7 @@ public class SecurityConfig {
|
||||
// 验证码校验过滤器
|
||||
.addFilterBefore(new CaptchaValidationFilter(redisTemplate, codeGenerator), UsernamePasswordAuthenticationFilter.class)
|
||||
// 验证和解析过滤器
|
||||
.addFilterBefore(new TokenFilter(tokenManager), UsernamePasswordAuthenticationFilter.class)
|
||||
.addFilterBefore(new TokenAuthenticationFilter(tokenManager), UsernamePasswordAuthenticationFilter.class)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,88 +1,108 @@
|
||||
package com.youlai.boot.config.property;
|
||||
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 安全配置属性
|
||||
*
|
||||
* @author haoxr
|
||||
* @author Ray.Hao
|
||||
* @since 2024/4/18
|
||||
*/
|
||||
@Data
|
||||
@Validated
|
||||
@ConfigurationProperties(prefix = "security")
|
||||
public class SecurityProperties {
|
||||
|
||||
/**
|
||||
* 会话方式
|
||||
* 免认证请求路径白名单
|
||||
*/
|
||||
private SessionProperty session;
|
||||
private List<String> ignoreUrls = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* JWT 配置
|
||||
* 静态资源路径(不经过安全过滤器)
|
||||
*/
|
||||
private JwtProperty jwt;
|
||||
private List<String> unsecuredUrls = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Redis-Token 配置
|
||||
* 认证核心配置
|
||||
*/
|
||||
private RedisTokenProperty redisToken;
|
||||
private Auth auth = new Auth();
|
||||
|
||||
/**
|
||||
* 白名单 URL 集合
|
||||
*/
|
||||
private String[] ignoreUrls;
|
||||
|
||||
private String[] unsecuredUrls;
|
||||
|
||||
/**
|
||||
* 会话属性
|
||||
*/
|
||||
@Data
|
||||
public static class SessionProperty {
|
||||
private String type;
|
||||
public static class Auth {
|
||||
/**
|
||||
* 认证策略类型
|
||||
*/
|
||||
@NotNull
|
||||
private AuthType type = AuthType.JWT;
|
||||
|
||||
/**
|
||||
* 访问令牌有效期(秒)
|
||||
*/
|
||||
@Min(-1)
|
||||
private int accessTokenTtl = 3600;
|
||||
|
||||
/**
|
||||
* 刷新令牌有效期(秒)
|
||||
*/
|
||||
@Min(-1)
|
||||
private int refreshTokenTtl = 604800;
|
||||
|
||||
/**
|
||||
* JWT 配置
|
||||
*/
|
||||
private JwtConfig jwtConfig = new JwtConfig();
|
||||
|
||||
/**
|
||||
* Redis Token 配置
|
||||
*/
|
||||
private RedisTokenConfig redisTokenConfig = new RedisTokenConfig();
|
||||
|
||||
@Data
|
||||
public static class JwtConfig {
|
||||
/**
|
||||
* JWT 密钥
|
||||
*/
|
||||
@NotBlank
|
||||
@Size(min = 32, message = "HS256算法密钥至少需要32字符")
|
||||
private String key;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class RedisTokenConfig {
|
||||
/**
|
||||
* 最大并发会话数
|
||||
*/
|
||||
@Min(-1)
|
||||
private int maxSessions = 1;
|
||||
|
||||
/**
|
||||
* 会话超限处理策略
|
||||
*/
|
||||
private SessionControlStrategy sessionControl = SessionControlStrategy.REVOKE_OLDEST;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* JWT 配置
|
||||
* 认证策略类型枚举
|
||||
*/
|
||||
@Data
|
||||
public static class JwtProperty {
|
||||
|
||||
/**
|
||||
* JWT 密钥
|
||||
*/
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* 访问令牌有效期(单位:秒)
|
||||
*/
|
||||
private Integer accessTokenTimeToLive;
|
||||
|
||||
/**
|
||||
* 刷新令牌有效期(单位:秒)
|
||||
*/
|
||||
private Integer refreshTokenTimeToLive;
|
||||
|
||||
public enum AuthType {
|
||||
JWT, REDIS_TOKEN
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class RedisTokenProperty {
|
||||
/**
|
||||
* 是否允许多点登录
|
||||
*/
|
||||
private Boolean multiLogin;
|
||||
|
||||
/**
|
||||
* 访问令牌有效期(单位:秒)
|
||||
*/
|
||||
private Integer accessTokenTimeToLive;
|
||||
|
||||
/**
|
||||
* 刷新令牌有效期(单位:秒)
|
||||
*/
|
||||
private Integer refreshTokenTimeToLive;
|
||||
/**
|
||||
* 会话控制策略枚举
|
||||
*/
|
||||
public enum SessionControlStrategy {
|
||||
REVOKE_OLDEST, DENY_NEW
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user