配置文件优化

v1.4.1
Parker 4 years ago
parent 18728a44ce
commit 10b91dc156

@ -15,6 +15,8 @@
*/ */
package org.opsli.core.autoconfigure; package org.opsli.core.autoconfigure;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -24,16 +26,11 @@ import org.springframework.stereotype.Component;
*/ */
@Component @Component
@ConfigurationProperties(prefix = "server.servlet.api.path") @ConfigurationProperties(prefix = "server.servlet.api.path")
@Data
@EqualsAndHashCode(callSuper = false)
public class ApiPathProperties { public class ApiPathProperties {
/** 专门针对 Controller层接口路径前缀全局配置 */ /** 专门针对 Controller层接口路径前缀全局配置 */
private String globalPrefix; private String globalPrefix;
public String getGlobalPrefix() {
return globalPrefix;
}
public void setGlobalPrefix(String globalPrefix) {
this.globalPrefix = globalPrefix;
}
} }

@ -0,0 +1,107 @@
package org.opsli.core.autoconfigure;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties;
import com.google.common.collect.Maps;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import java.util.Map;
/**
*
*
* @author Parker
*/
@Slf4j
@Configuration
public class DbSourceProperties {
/** 数据库详情 */
private Map<String, DbSourceProperties.DataSourceInfo> dataSourceInfoMap;
/**
*
* @return DataSourceInfo
*/
public Map<String, DbSourceProperties.DataSourceInfo> getDataSourceInfoMap() {
return this.dataSourceInfoMap;
}
// ==================================
@Data
public static class DataSourceInfo{
/** URL */
private String url;
/** 地址 */
private String host;
/** 端口 */
private Integer port;
/** 数据库名 */
private String dbName;
/** 用户名 */
private String userName;
/** 密码 */
private String passWord;
/** 驱动类名称 */
private String driverClassName;
}
@Autowired
public void setDataSourceInfoMap(DynamicDataSourceProperties dataSourceProperties) {
if(dataSourceProperties != null){
Map<String, DataSourceProperty> datasourceMap = dataSourceProperties.getDatasource();
if(CollUtil.isNotEmpty(datasourceMap)){
dataSourceInfoMap = Maps.newTreeMap();
for (Map.Entry<String, DataSourceProperty> dataSourcePropertyEntry : datasourceMap.entrySet()) {
String key = dataSourcePropertyEntry.getKey();
DataSourceProperty datasource = dataSourcePropertyEntry.getValue();
String url = datasource.getUrl();
String username = datasource.getUsername();
String password = datasource.getPassword();
String driverClassName = datasource.getDriverClassName();
// 非法判断
if(StringUtils.isBlank(url) || StringUtils.isBlank(username) ||
StringUtils.isBlank(password)
){
return;
}
String[] split = url.split(":");
String host = String.format("%s:%s:%s", split[0], split[1], split[2]);
String[] portSplit = split[3].split("/");
String port = portSplit[0];
String[] databaseSplit = portSplit[1].split("\\?");
String dbName = databaseSplit[0];
DataSourceInfo dataSourceInfo = new DataSourceInfo();
dataSourceInfo.setUrl(url);
dataSourceInfo.setHost(host);
dataSourceInfo.setPort(Convert.toInt(port));
dataSourceInfo.setDbName(dbName);
dataSourceInfo.setUserName(username);
dataSourceInfo.setPassWord(password);
dataSourceInfo.setDriverClassName(driverClassName);
dataSourceInfoMap.put(key, dataSourceInfo);
}
}
}
}
}

@ -1,5 +1,7 @@
package org.opsli.core.autoconfigure; package org.opsli.core.autoconfigure;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -13,6 +15,8 @@ import java.util.Set;
**/ **/
@Configuration @Configuration
@ConfigurationProperties(prefix = GlobalProperties.PREFIX) @ConfigurationProperties(prefix = GlobalProperties.PREFIX)
@Data
@EqualsAndHashCode(callSuper = false)
public class GlobalProperties { public class GlobalProperties {
public static final String PREFIX = "opsli"; public static final String PREFIX = "opsli";
@ -39,69 +43,13 @@ public class GlobalProperties {
private Excel excel; private Excel excel;
// ==================================
public String getSystemName() {
return systemName;
}
public void setSystemName(String systemName) {
this.systemName = systemName;
}
public String getSystemStarterTime() {
return systemStarterTime;
}
public void setSystemStarterTime(String systemStarterTime) {
this.systemStarterTime = systemStarterTime;
}
public boolean isEnableDemo() {
return enableDemo;
}
public void setEnableDemo(boolean enableDemo) {
this.enableDemo = enableDemo;
}
public Waf getWaf() {
return waf;
}
public void setWaf(Waf waf) {
this.waf = waf;
}
public Auth getAuth() {
return auth;
}
public void setAuth(Auth auth) {
this.auth = auth;
}
public Web getWeb() {
return web;
}
public void setWeb(Web web) {
this.web = web;
}
public Excel getExcel() {
return excel;
}
public void setExcel(Excel excel) {
this.excel = excel;
}
// ============== 内部类 ============= // ============== 内部类 =============
/** /**
* *
*/ */
@Data
@EqualsAndHashCode(callSuper = false)
public static class Waf { public static class Waf {
/** 是否生效 */ /** 是否生效 */
@ -122,80 +70,25 @@ public class GlobalProperties {
/** 过滤器的优先级,值越小优先级越高 */ /** 过滤器的优先级,值越小优先级越高 */
private int order; private int order;
// =============================
public Set<String> getUrlPatterns() {
return urlPatterns;
}
public void setUrlPatterns(Set<String> urlPatterns) {
this.urlPatterns = urlPatterns;
}
public Set<String> getUrlExclusion() {
return urlExclusion;
}
public void setUrlExclusion(Set<String> urlExclusion) {
this.urlExclusion = urlExclusion;
}
public int getOrder() {
return order;
}
public void setOrder(int order) {
this.order = order;
}
public boolean isEnable() {
return enable;
}
public void setEnable(boolean enable) {
this.enable = enable;
}
public boolean isXssFilter() {
return xssFilter;
}
public void setXssFilter(boolean xssFilter) {
this.xssFilter = xssFilter;
}
public boolean isSqlFilter() {
return sqlFilter;
}
public void setSqlFilter(boolean sqlFilter) {
this.sqlFilter = sqlFilter;
}
} }
/** /**
* Web * Web
*/ */
@Data
@EqualsAndHashCode(callSuper = false)
public static class Web { public static class Web {
/** 文件上传地址 */ /** 文件上传地址 */
private String uploadPath; private String uploadPath;
// ===========================
public String getUploadPath() {
return uploadPath;
}
public void setUploadPath(String uploadPath) {
this.uploadPath = uploadPath;
}
} }
/** /**
* *
*/ */
@Data
@EqualsAndHashCode(callSuper = false)
public static class Auth { public static class Auth {
/** 超级管理员账号 */ /** 超级管理员账号 */
@ -210,43 +103,12 @@ public class GlobalProperties {
/** Login */ /** Login */
private Login login; private Login login;
// ===========================
public String getSuperAdmin() {
return superAdmin;
}
public void setSuperAdmin(String superAdmin) {
this.superAdmin = superAdmin;
}
public String getDefaultPass() {
return defaultPass;
}
public void setDefaultPass(String defaultPass) {
this.defaultPass = defaultPass;
}
public Token getToken() {
return token;
}
public void setToken(Token token) {
this.token = token;
}
public Login getLogin() {
return login;
}
public void setLogin(Login login) {
this.login = login;
}
/** /**
* *
*/ */
@Data
@EqualsAndHashCode(callSuper = false)
public static class Token { public static class Token {
/** 盐值 */ /** 盐值 */
@ -258,36 +120,13 @@ public class GlobalProperties {
/** 排除URL*/ /** 排除URL*/
private Set<String> urlExclusion; private Set<String> urlExclusion;
// ===============================
public String getSecret() {
return secret;
}
public void setSecret(String secret) {
this.secret = secret;
}
public Integer getEffectiveTime() {
return effectiveTime;
}
public void setEffectiveTime(Integer effectiveTime) {
this.effectiveTime = effectiveTime;
}
public Set<String> getUrlExclusion() {
return urlExclusion;
}
public void setUrlExclusion(Set<String> urlExclusion) {
this.urlExclusion = urlExclusion;
}
} }
/** /**
* *
*/ */
@Data
@EqualsAndHashCode(callSuper = false)
public static class Login { public static class Login {
/** 失败次数 */ /** 失败次数 */
@ -299,35 +138,14 @@ public class GlobalProperties {
/** 失败锁定时间(秒) */ /** 失败锁定时间(秒) */
private Integer slipLockSpeed; private Integer slipLockSpeed;
public Integer getSlipCount() {
return slipCount;
}
public void setSlipCount(Integer slipCount) {
this.slipCount = slipCount;
}
public Integer getSlipVerifyCount() {
return slipVerifyCount;
}
public void setSlipVerifyCount(Integer slipVerifyCount) {
this.slipVerifyCount = slipVerifyCount;
}
public Integer getSlipLockSpeed() {
return slipLockSpeed;
}
public void setSlipLockSpeed(Integer slipLockSpeed) {
this.slipLockSpeed = slipLockSpeed;
}
} }
} }
/** /**
* Excel * Excel
*/ */
@Data
@EqualsAndHashCode(callSuper = false)
public static class Excel { public static class Excel {
/** 最大导入操作数 */ /** 最大导入操作数 */
@ -336,23 +154,6 @@ public class GlobalProperties {
/** 最大导出操作数 */ /** 最大导出操作数 */
private Integer exportMaxCount; private Integer exportMaxCount;
// ===========================
public Integer getImportMaxCount() {
return importMaxCount;
}
public void setImportMaxCount(Integer importMaxCount) {
this.importMaxCount = importMaxCount;
}
public Integer getExportMaxCount() {
return exportMaxCount;
}
public void setExportMaxCount(Integer exportMaxCount) {
this.exportMaxCount = exportMaxCount;
}
} }
} }

@ -19,6 +19,7 @@ import com.fasterxml.classmate.TypeResolver;
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.opsli.core.autoconfigure.GlobalProperties;
import org.opsli.core.utils.UserTokenUtil; import org.opsli.core.utils.UserTokenUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@ -48,9 +49,9 @@ import java.util.List;
@Import(BeanValidatorPluginsConfiguration.class) @Import(BeanValidatorPluginsConfiguration.class)
public class SwaggerConfig { public class SwaggerConfig {
/** 系统名称 */ /** 配置类 */
@Value("${opsli.system-name:OPSLI 快速开发平台}") @Autowired
private String systemName; protected GlobalProperties globalProperties;
private final TypeResolver typeResolver; private final TypeResolver typeResolver;
@ -92,7 +93,7 @@ public class SwaggerConfig {
private ApiInfo apiInfo() { private ApiInfo apiInfo() {
return new ApiInfoBuilder() return new ApiInfoBuilder()
// //大标题 // //大标题
.title(systemName + " 服务API接口文档") .title(globalProperties.getSystemName() + " 服务API接口文档")
// 版本号 // 版本号
.version("1.0") .version("1.0")
// 描述 // 描述

@ -37,7 +37,7 @@ import javax.servlet.DispatcherType;
public class WafConfig { public class WafConfig {
@Autowired @Autowired
GlobalProperties globalProperties; private GlobalProperties globalProperties;
@Bean @Bean
@ConditionalOnProperty(prefix = GlobalProperties.PREFIX +".waf", name = "enable", havingValue = "true", matchIfMissing = false) @ConditionalOnProperty(prefix = GlobalProperties.PREFIX +".waf", name = "enable", havingValue = "true", matchIfMissing = false)

@ -21,9 +21,11 @@ import cn.hutool.core.lang.Console;
import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.thread.ThreadUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.opsli.core.autoconfigure.GlobalProperties;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Date; import java.util.Date;
@ -120,13 +122,41 @@ public class StartPrint {
private static final StartPrint INSTANCE = new StartPrint(); private static final StartPrint INSTANCE = new StartPrint();
} }
@Value("${opsli.system-name:OPSLI快速开发平台}")
public void setSystemName(String systemName) {
@Value("${server.port:8080}")
public void setServerPort(String serverPort) {
StartPrint.serverPort = serverPort;
}
@Value("${server.servlet.context-path:/opsli-boot}")
public void setServerContextPath(String serverContextPath) {
StartPrint.serverContextPath = serverContextPath;
}
// ===============================
/***
*
* @param globalProperties
*/
@PostConstruct
public void init(GlobalProperties globalProperties){
if(globalProperties != null){
// 设置系统名称
this.setSystemName(globalProperties.getSystemName());
// 设置系统启动时间
this.setStarterDate(globalProperties.getSystemStarterTime());
}
}
// ==============================
private void setSystemName(String systemName) {
StartPrint.systemName = systemName; StartPrint.systemName = systemName;
} }
@Value("${opsli.system-starter-time}") private void setStarterDate(String starterDate) {
public void setStarterDate(String starterDate) {
// 非空验证 // 非空验证
if(StringUtils.isEmpty(starterDate)){ if(StringUtils.isEmpty(starterDate)){
StartPrint.starterDate = DateUtil.date().toString(); StartPrint.starterDate = DateUtil.date().toString();
@ -146,14 +176,4 @@ public class StartPrint {
StartPrint.starterDate = starterDate; StartPrint.starterDate = starterDate;
} }
@Value("${server.port:8080}")
public void setServerPort(String serverPort) {
StartPrint.serverPort = serverPort;
}
@Value("${server.servlet.context-path:/opsli-boot}")
public void setServerContextPath(String serverContextPath) {
StartPrint.serverContextPath = serverContextPath;
}
} }

@ -104,24 +104,22 @@ public class JwtUtil {
// ================== // ==================
/**
*
* @param globalProperties
*/
@Autowired @Autowired
public void setExpire(GlobalProperties globalProperties) { public void init(GlobalProperties globalProperties){
// 获得 Token失效时间 //
if(globalProperties != null && globalProperties.getAuth() != null if(globalProperties != null && globalProperties.getAuth() != null
&& globalProperties.getAuth().getToken() != null && globalProperties.getAuth().getToken() != null
){ ){
EXPIRE = globalProperties.getAuth() // 获得 Token失效时间
JwtUtil.EXPIRE = globalProperties.getAuth()
.getToken().getEffectiveTime() * 60 * 1000; .getToken().getEffectiveTime() * 60 * 1000;
}
}
@Autowired // 获得 Token初始盐值
public void setEncryptJwtInitialSecret(GlobalProperties globalProperties) { JwtUtil.ENCRYPT_JWT_INITIAL_SECRET = globalProperties.getAuth()
// 获得 Token初始盐值
if(globalProperties != null && globalProperties.getAuth() != null
&& globalProperties.getAuth().getToken() != null
){
ENCRYPT_JWT_INITIAL_SECRET = globalProperties.getAuth()
.getToken().getSecret(); .getToken().getSecret();
} }
} }

@ -334,38 +334,27 @@ public class UserTokenUtil {
return token; return token;
} }
/**
*
* @param globalProperties
*/
@Autowired @Autowired
public void setRedisPlugin(RedisPlugin redisPlugin) { public void init(GlobalProperties globalProperties, RedisPlugin redisPlugin){
UserTokenUtil.redisPlugin = redisPlugin;
}
@Autowired
public void setAccountSlipCount(GlobalProperties globalProperties) {
if(globalProperties != null && globalProperties.getAuth() != null if(globalProperties != null && globalProperties.getAuth() != null
&& globalProperties.getAuth().getLogin() != null && globalProperties.getAuth().getLogin() != null
){ ){
ACCOUNT_SLIP_COUNT = globalProperties.getAuth() // 账号失败阈值
UserTokenUtil.ACCOUNT_SLIP_COUNT = globalProperties.getAuth()
.getLogin().getSlipCount(); .getLogin().getSlipCount();
} // 账号失败N次后弹出验证码
} UserTokenUtil.ACCOUNT_SLIP_VERIFY_COUNT = globalProperties.getAuth()
@Autowired
public void setAccountSlipVerifyCount(GlobalProperties globalProperties) {
if(globalProperties != null && globalProperties.getAuth() != null
&& globalProperties.getAuth().getLogin() != null
){
ACCOUNT_SLIP_VERIFY_COUNT = globalProperties.getAuth()
.getLogin().getSlipVerifyCount(); .getLogin().getSlipVerifyCount();
} // 账号锁定时间
} UserTokenUtil.ACCOUNT_SLIP_LOCK_SPEED = globalProperties.getAuth()
@Autowired
public void setAccountSlipLockSpeed(GlobalProperties globalProperties) {
if(globalProperties != null && globalProperties.getAuth() != null
&& globalProperties.getAuth().getLogin() != null
){
ACCOUNT_SLIP_LOCK_SPEED = globalProperties.getAuth()
.getLogin().getSlipLockSpeed(); .getLogin().getSlipLockSpeed();
} }
// Redis 插件
UserTokenUtil.redisPlugin = redisPlugin;
} }
} }

@ -740,10 +740,16 @@ public class UserUtil {
UserUtil.userApi = userApi; UserUtil.userApi = userApi;
} }
/**
*
* @param globalProperties
*/
@Autowired @Autowired
public void setSuperAdmin(GlobalProperties globalProperties) { public void init(GlobalProperties globalProperties){
// 获得 超级管理员 if(globalProperties != null && globalProperties.getAuth() != null
if(globalProperties != null && globalProperties.getAuth() != null ){ && globalProperties.getAuth().getToken() != null
){
// 获得 超级管理员
UserUtil.SUPER_ADMIN = globalProperties.getAuth().getSuperAdmin(); UserUtil.SUPER_ADMIN = globalProperties.getAuth().getSuperAdmin();
} }
} }

@ -61,17 +61,20 @@
{ {
"name": "opsli.system-name", "name": "opsli.system-name",
"sourceType": "org.opsli.core.autoconfigure.GlobalProperties", "sourceType": "org.opsli.core.autoconfigure.GlobalProperties",
"type": "java.lang.String",
"defaultValue": "OPSLI 快速开发平台", "defaultValue": "OPSLI 快速开发平台",
"description": "系统名称." "description": "系统名称."
}, },
{ {
"name": "opsli.system-starter-time", "name": "opsli.system-starter-time",
"sourceType": "org.opsli.core.autoconfigure.GlobalProperties", "sourceType": "org.opsli.core.autoconfigure.GlobalProperties",
"type": "java.lang.String",
"description": "系统启动时间 为空则默认 真实当前系统启动时间." "description": "系统启动时间 为空则默认 真实当前系统启动时间."
}, },
{ {
"name": "opsli.enable-demo", "name": "opsli.enable-demo",
"sourceType": "org.opsli.core.autoconfigure.GlobalProperties", "sourceType": "org.opsli.core.autoconfigure.GlobalProperties",
"type": "java.lang.Boolean",
"defaultValue": false, "defaultValue": false,
"description": "是否开启演示模式." "description": "是否开启演示模式."
}, },
@ -81,24 +84,28 @@
{ {
"name": "opsli.waf.enable", "name": "opsli.waf.enable",
"sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Waf", "sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Waf",
"type": "java.lang.Boolean",
"defaultValue": false, "defaultValue": false,
"description": "软防火墙是否开启." "description": "软防火墙是否开启."
}, },
{ {
"name": "opsli.waf.xss-filter", "name": "opsli.waf.xss-filter",
"sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Waf", "sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Waf",
"type": "java.lang.Boolean",
"defaultValue": false, "defaultValue": false,
"description": "软防火墙 xss 过滤开启状态." "description": "软防火墙 xss 过滤开启状态."
}, },
{ {
"name": "opsli.waf.sql-filter", "name": "opsli.waf.sql-filter",
"sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Waf", "sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Waf",
"type": "java.lang.Boolean",
"defaultValue": false, "defaultValue": false,
"description": "软防火墙 sql 过滤开启状态." "description": "软防火墙 sql 过滤开启状态."
}, },
{ {
"name": "opsli.waf.url-patterns", "name": "opsli.waf.url-patterns",
"sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Waf", "sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Waf",
"type": "java.util.Set<java.lang.String>",
"defaultValue": [ "defaultValue": [
"/*" "/*"
], ],
@ -107,11 +114,13 @@
{ {
"name": "opsli.waf.url-exclusion", "name": "opsli.waf.url-exclusion",
"sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Waf", "sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Waf",
"type": "java.util.Set<java.lang.String>",
"description": "软防火墙 过滤器需要排除过滤的路径." "description": "软防火墙 过滤器需要排除过滤的路径."
}, },
{ {
"name": "opsli.waf.order", "name": "opsli.waf.order",
"sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Waf", "sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Waf",
"type": "java.lang.Integer",
"defaultValue": 0, "defaultValue": 0,
"description": "软防火墙 过滤器的优先级,值越小优先级越高." "description": "软防火墙 过滤器的优先级,值越小优先级越高."
}, },
@ -121,6 +130,7 @@
{ {
"name": "opsli.web.upload-path", "name": "opsli.web.upload-path",
"sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Web", "sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Web",
"type": "java.lang.String",
"defaultValue": "", "defaultValue": "",
"description": "Web 上传地址." "description": "Web 上传地址."
}, },
@ -130,12 +140,14 @@
{ {
"name": "opsli.auth.super-admin", "name": "opsli.auth.super-admin",
"sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Auth", "sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Auth",
"type": "java.lang.String",
"defaultValue": "system", "defaultValue": "system",
"description": "认证类 超级管理员账户." "description": "认证类 超级管理员账户."
}, },
{ {
"name": "opsli.auth.default-pass", "name": "opsli.auth.default-pass",
"sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Auth", "sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Auth",
"type": "java.lang.String",
"defaultValue": "Aa123456", "defaultValue": "Aa123456",
"description": "认证类 默认密码 (密码至少包含大小写字母数字且不少于6位)." "description": "认证类 默认密码 (密码至少包含大小写字母数字且不少于6位)."
}, },
@ -143,36 +155,43 @@
{ {
"name": "opsli.auth.token.secret", "name": "opsli.auth.token.secret",
"sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Auth$Token", "sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Auth$Token",
"type": "java.lang.String",
"defaultValue": "53c0e33c9d4c5538969abf2fcf48351d", "defaultValue": "53c0e33c9d4c5538969abf2fcf48351d",
"description": "认证类 Token 有效时间." "description": "认证类 Token 盐值."
}, },
{ {
"name": "opsli.auth.token.effective-time", "name": "opsli.auth.token.effective-time",
"sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Auth$Token", "sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Auth$Token",
"type": "java.lang.Integer",
"defaultValue": 120, "defaultValue": 120,
"description": "认证类 Token 有效时间." "description": "认证类 Token 有效时间."
}, },
{ {
"name": "opsli.auth.token.url-exclusion", "name": "opsli.auth.token.url-exclusion",
"sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Auth$Token", "sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Auth$Token",
"type": "java.util.Set<java.lang.String>",
"description": "认证类 Token 排除URL." "description": "认证类 Token 排除URL."
}, },
{ {
"name": "opsli.auth.login.slip-count", "name": "opsli.auth.login.slip-count",
"sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Auth$Login", "sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Auth$Login",
"defaultValue": 3, "type": "java.lang.Integer",
"defaultValue": 5,
"description": "认证类 登录 失败次数." "description": "认证类 登录 失败次数."
}, },
{ {
"name": "opsli.auth.login.slip-verify-count", "name": "opsli.auth.login.slip-verify-count",
"sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Auth$Login", "sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Auth$Login",
"type": "java.lang.Integer",
"defaultValue": 3, "defaultValue": 3,
"description": "认证类 登录 失败N次后弹出验证码 (超过验证码阈值 弹出验证码)." "description": "认证类 登录 失败N次后弹出验证码 (超过验证码阈值 弹出验证码)."
}, },
{ {
"name": "opsli.auth.login.slip-lock-speed", "name": "opsli.auth.login.slip-lock-speed",
"sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Auth$Login", "sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Auth$Login",
"type": "java.lang.Integer",
"defaultValue": 300,
"description": "认证类 登录 失败锁定时间(秒)." "description": "认证类 登录 失败锁定时间(秒)."
}, },
@ -181,12 +200,14 @@
{ {
"name": "opsli.excel.import-max-count", "name": "opsli.excel.import-max-count",
"sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Excel", "sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Excel",
"type": "java.lang.Integer",
"defaultValue": 20000, "defaultValue": 20000,
"description": "Excel 导入最大操作数." "description": "Excel 导入最大操作数."
}, },
{ {
"name": "opsli.excel.export-max-count", "name": "opsli.excel.export-max-count",
"sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Excel", "sourceType": "org.opsli.core.autoconfigure.GlobalProperties$Excel",
"type": "java.lang.Integer",
"defaultValue": 20000, "defaultValue": 20000,
"description": "Excel 导出最大操作数." "description": "Excel 导出最大操作数."
} }

@ -27,6 +27,7 @@ import org.opsli.api.wrapper.system.user.UserModel;
import org.opsli.common.annotation.ApiRestController; import org.opsli.common.annotation.ApiRestController;
import org.opsli.common.annotation.EnableLog; import org.opsli.common.annotation.EnableLog;
import org.opsli.common.exception.ServiceException; import org.opsli.common.exception.ServiceException;
import org.opsli.core.autoconfigure.GlobalProperties;
import org.opsli.core.msg.CoreMsg; import org.opsli.core.msg.CoreMsg;
import org.opsli.core.utils.UserUtil; import org.opsli.core.utils.UserUtil;
import org.opsli.modulars.system.SystemMsg; import org.opsli.modulars.system.SystemMsg;
@ -55,8 +56,9 @@ public class RoleMenuRefRestController implements RoleMenuRefApi {
/** 内置数据 */ /** 内置数据 */
private static final String LOCK_DATA = "1"; private static final String LOCK_DATA = "1";
@Value("${opsli.enable-demo}") /** 配置类 */
private boolean enableDemo; @Autowired
protected GlobalProperties globalProperties;
@Autowired @Autowired
private IRoleService iRoleService; private IRoleService iRoleService;
@ -141,7 +143,8 @@ public class RoleMenuRefRestController implements RoleMenuRefApi {
private void demoError(){ private void demoError(){
UserModel user = UserUtil.getUser(); UserModel user = UserUtil.getUser();
// 演示模式 不允许操作 (超级管理员可以操作) // 演示模式 不允许操作 (超级管理员可以操作)
if(enableDemo && !StringUtils.equals(UserUtil.SUPER_ADMIN, user.getUsername())){ if(globalProperties.isEnableDemo() &&
!StringUtils.equals(UserUtil.SUPER_ADMIN, user.getUsername())){
throw new ServiceException(CoreMsg.EXCEPTION_ENABLE_DEMO); throw new ServiceException(CoreMsg.EXCEPTION_ENABLE_DEMO);
} }
} }

@ -24,6 +24,7 @@ import org.opsli.api.wrapper.system.user.UserModel;
import org.opsli.api.wrapper.system.user.UserOrgRefModel; import org.opsli.api.wrapper.system.user.UserOrgRefModel;
import org.opsli.common.annotation.ApiRestController; import org.opsli.common.annotation.ApiRestController;
import org.opsli.common.exception.ServiceException; import org.opsli.common.exception.ServiceException;
import org.opsli.core.autoconfigure.GlobalProperties;
import org.opsli.core.msg.CoreMsg; import org.opsli.core.msg.CoreMsg;
import org.opsli.core.utils.UserUtil; import org.opsli.core.utils.UserUtil;
import org.opsli.modulars.system.SystemMsg; import org.opsli.modulars.system.SystemMsg;
@ -43,8 +44,9 @@ import org.springframework.beans.factory.annotation.Value;
@ApiRestController("/sys/user/org") @ApiRestController("/sys/user/org")
public class UserOrgRefRestController implements UserOrgRefApi { public class UserOrgRefRestController implements UserOrgRefApi {
@Value("${opsli.enable-demo}") /** 配置类 */
private boolean enableDemo; @Autowired
protected GlobalProperties globalProperties;
@Autowired @Autowired
private IUserOrgRefService iUserOrgRefService; private IUserOrgRefService iUserOrgRefService;
@ -78,7 +80,8 @@ public class UserOrgRefRestController implements UserOrgRefApi {
private void demoError(){ private void demoError(){
UserModel user = UserUtil.getUser(); UserModel user = UserUtil.getUser();
// 演示模式 不允许操作 (超级管理员可以操作) // 演示模式 不允许操作 (超级管理员可以操作)
if(enableDemo && !StringUtils.equals(UserUtil.SUPER_ADMIN, user.getUsername())){ if(globalProperties.isEnableDemo() &&
!StringUtils.equals(UserUtil.SUPER_ADMIN, user.getUsername())){
throw new ServiceException(CoreMsg.EXCEPTION_ENABLE_DEMO); throw new ServiceException(CoreMsg.EXCEPTION_ENABLE_DEMO);
} }
} }

@ -24,6 +24,7 @@ import org.opsli.api.wrapper.system.user.UserModel;
import org.opsli.api.wrapper.system.user.UserRoleRefModel; import org.opsli.api.wrapper.system.user.UserRoleRefModel;
import org.opsli.common.annotation.ApiRestController; import org.opsli.common.annotation.ApiRestController;
import org.opsli.common.exception.ServiceException; import org.opsli.common.exception.ServiceException;
import org.opsli.core.autoconfigure.GlobalProperties;
import org.opsli.core.msg.CoreMsg; import org.opsli.core.msg.CoreMsg;
import org.opsli.core.utils.UserUtil; import org.opsli.core.utils.UserUtil;
import org.opsli.modulars.system.SystemMsg; import org.opsli.modulars.system.SystemMsg;
@ -43,8 +44,9 @@ import org.springframework.beans.factory.annotation.Value;
@ApiRestController("/sys/user/roles") @ApiRestController("/sys/user/roles")
public class UserRoleRefRestController implements UserRoleRefApi { public class UserRoleRefRestController implements UserRoleRefApi {
@Value("${opsli.enable-demo}") /** 配置类 */
private boolean enableDemo; @Autowired
protected GlobalProperties globalProperties;
@Autowired @Autowired
private IUserRoleRefService iUserRoleRefService; private IUserRoleRefService iUserRoleRefService;
@ -80,7 +82,8 @@ public class UserRoleRefRestController implements UserRoleRefApi {
private void demoError(){ private void demoError(){
UserModel user = UserUtil.getUser(); UserModel user = UserUtil.getUser();
// 演示模式 不允许操作 (超级管理员可以操作) // 演示模式 不允许操作 (超级管理员可以操作)
if(enableDemo && !StringUtils.equals(UserUtil.SUPER_ADMIN, user.getUsername())){ if(globalProperties.isEnableDemo() &&
!StringUtils.equals(UserUtil.SUPER_ADMIN, user.getUsername())){
throw new ServiceException(CoreMsg.EXCEPTION_ENABLE_DEMO); throw new ServiceException(CoreMsg.EXCEPTION_ENABLE_DEMO);
} }
} }

Loading…
Cancel
Save