io.github.dengchen2020.security.properties.SecurityProperties Maven / Gradle / Ivy
package io.github.dengchen2020.security.properties;
import io.github.dengchen2020.security.principal.Authentication;
import jakarta.validation.constraints.Min;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.List;
/**
* token配置信息
*
* @author dengchen
* @since 2019/10/8 13:06
*/
@Validated
@ConfigurationProperties(prefix = "dc.security")
public class SecurityProperties {
/**
* 访问资源配置
*/
private Resource resource = new Resource();
/**
* Token属性配置
*/
private Token token = new Token();
/**
* JWT属性配置
*/
private Jwt jwt = new Jwt();
/**
* 权限校验配置
*/
private Permission permission = new Permission();
public Resource getResource() {
return resource;
}
public void setResource(Resource resource) {
this.resource = resource;
}
public Token getToken() {
return token;
}
public void setToken(Token token) {
this.token = token;
}
public Jwt getJwt() {
return jwt;
}
public void setJwt(Jwt jwt) {
this.jwt = jwt;
}
public Permission getPermission() {
return permission;
}
public void setPermission(Permission permission) {
this.permission = permission;
}
public static class Resource {
/**
* 无需Token认证的访问资源路径
*/
private List permitPath = new ArrayList<>();
public List getPermitPath() {
return permitPath;
}
public void setPermitPath(List permitPath) {
this.permitPath = permitPath;
}
}
public static class Token {
/**
* 有效期(秒)
*/
@Min(300)
private long expireSeconds = 7200;
/**
* 刷新Token有效期(秒)
*/
@Min(600)
private long refreshExpireSeconds = 0;
/**
* 是否无状态
*/
private boolean stateless = true;
/**
* 最大在线客户端数量(不支持无状态模式)
*/
@Min(1)
private int maxOnlineNum = 1;
/**
* 是否开启Token刷新功能
*/
private boolean enabledRefresh = true;
/**
* 用户认证信息实例类型
*/
private Class extends Authentication> principalClass = Authentication.class;
public long getExpireSeconds() {
return expireSeconds;
}
public void setExpireSeconds(long expireSeconds) {
this.expireSeconds = expireSeconds;
}
public long getRefreshExpireSeconds() {
return refreshExpireSeconds;
}
public void setRefreshExpireSeconds(long refreshExpireSeconds) {
this.refreshExpireSeconds = refreshExpireSeconds;
}
public boolean isStateless() {
return stateless;
}
public void setStateless(boolean stateless) {
this.stateless = stateless;
}
public int getMaxOnlineNum() {
return maxOnlineNum;
}
public void setMaxOnlineNum(int maxOnlineNum) {
this.maxOnlineNum = maxOnlineNum;
}
public Class extends Authentication> getPrincipalClass() {
return principalClass;
}
public void setPrincipalClass(Class extends Authentication> principalClass) {
this.principalClass = principalClass;
}
public boolean isEnabledRefresh() {
return enabledRefresh;
}
public void setEnabledRefresh(boolean enabledRefresh) {
this.enabledRefresh = enabledRefresh;
}
}
public static class Jwt {
/**
* jwt密钥
*/
private String secret;
public String getSecret() {
return secret;
}
public void setSecret(String secret) {
this.secret = secret;
}
}
public static class Permission {
/**
* 是否开启权限校验,默认不开启,实际开发中权限校验可能比较复杂
* 可通过实现{@link io.github.dengchen2020.security.core.support.permission.PermissionVerifier}完成复杂的权限校验
*/
private boolean enabled = false;
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}
}