diff --git a/kernel-d-auth/auth-api/src/main/java/cn/stylefeng/roses/kernel/auth/api/expander/LoginConfigExpander.java b/kernel-d-auth/auth-api/src/main/java/cn/stylefeng/roses/kernel/auth/api/expander/LoginConfigExpander.java new file mode 100644 index 000000000..c535a4f59 --- /dev/null +++ b/kernel-d-auth/auth-api/src/main/java/cn/stylefeng/roses/kernel/auth/api/expander/LoginConfigExpander.java @@ -0,0 +1,22 @@ +package cn.stylefeng.roses.kernel.auth.api.expander; + +import cn.stylefeng.roses.kernel.config.api.context.ConfigContext; + +/** + * 登录相关配置快速获取 + * + * @author xixiaowei + * @date 2022/1/24 15:47 + */ +public class LoginConfigExpander { + + /** + * 获取帐号错误次数校验开关 + * + * @author xixiaowei + * @date 2022/1/24 15:48 + */ + public static boolean getAccountErrorDetectionFlag() { + return ConfigContext.me().getSysConfigValueWithDefault("ACCOUNT_ERROR_DETECTION", Boolean.class, false); + } +} diff --git a/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/auth/AuthServiceImpl.java b/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/auth/AuthServiceImpl.java index 1c10fbad0..bc7118abc 100644 --- a/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/auth/AuthServiceImpl.java +++ b/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/auth/AuthServiceImpl.java @@ -24,7 +24,6 @@ */ package cn.stylefeng.roses.kernel.auth.auth; -import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.codec.Base64; import cn.hutool.core.convert.Convert; import cn.hutool.core.util.CharsetUtil; @@ -42,6 +41,7 @@ import cn.stylefeng.roses.kernel.auth.api.context.LoginContext; import cn.stylefeng.roses.kernel.auth.api.exception.AuthException; import cn.stylefeng.roses.kernel.auth.api.exception.enums.AuthExceptionEnum; import cn.stylefeng.roses.kernel.auth.api.expander.AuthConfigExpander; +import cn.stylefeng.roses.kernel.auth.api.expander.LoginConfigExpander; import cn.stylefeng.roses.kernel.auth.api.password.PasswordStoredEncryptApi; import cn.stylefeng.roses.kernel.auth.api.password.PasswordTransferEncryptApi; import cn.stylefeng.roses.kernel.auth.api.pojo.SsoProperties; @@ -49,9 +49,7 @@ import cn.stylefeng.roses.kernel.auth.api.pojo.auth.LoginRequest; import cn.stylefeng.roses.kernel.auth.api.pojo.auth.LoginResponse; import cn.stylefeng.roses.kernel.auth.api.pojo.auth.LoginWithTokenRequest; import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser; -import cn.stylefeng.roses.kernel.auth.session.cache.loginuser.RedisLoginUserCache; import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi; -import cn.stylefeng.roses.kernel.cache.memory.operator.DefaultMemoryCacheOperator; import cn.stylefeng.roses.kernel.demo.expander.DemoConfigExpander; import cn.stylefeng.roses.kernel.jwt.JwtTokenOperator; import cn.stylefeng.roses.kernel.jwt.api.context.JwtContext; @@ -77,7 +75,6 @@ import cn.stylefeng.roses.kernel.validator.api.exception.enums.ValidatorExceptio import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import io.jsonwebtoken.Claims; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -133,9 +130,6 @@ public class AuthServiceImpl implements AuthServiceApi { @Resource private CacheOperatorApi loginCacheOperatorApi; - @Value("${login.enable}") - private Boolean enable; - @Override public LoginResponse login(LoginRequest loginRequest) { return loginAction(loginRequest, true, null); @@ -273,7 +267,7 @@ public class AuthServiceImpl implements AuthServiceApi { private LoginResponse loginAction(LoginRequest loginRequest, Boolean validatePassword, String caToken) { SysUser userByAccount = sysUserService.getUserByAccount(loginRequest.getAccount()); // 判断登录错误检测是否开启 - if (enable) { + if (LoginConfigExpander.getAccountErrorDetectionFlag()) { // 判断错误次数,超过最大放入缓存中 if (StrUtil.isBlank(loginCacheOperatorApi.get(userByAccount.getUserId().toString()))) { if (userByAccount.getLoginCount() > LoginCacheConstants.MAX_LOGIN_COUNT) { diff --git a/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/config/AccountErrorDetectionConfig.java b/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/config/AccountErrorDetectionConfig.java deleted file mode 100644 index cc8d63ea7..000000000 --- a/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/config/AccountErrorDetectionConfig.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.stylefeng.roses.kernel.auth.config; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; - -/** - * 控制帐号错误检测开关 - * - * @author xixiaowei - * @date 2022/1/23 23:42 - */ -@Data -@Component -@ConfigurationProperties(prefix = "login") -public class AccountErrorDetectionConfig { - - /** - * 开关:true-开启错误检测,false-关闭错误检测 - */ - private Boolean enable; -} diff --git a/kernel-d-db/db-spring-boot-starter/pom.xml b/kernel-d-db/db-spring-boot-starter/pom.xml index 851f11cc0..0f929a392 100644 --- a/kernel-d-db/db-spring-boot-starter/pom.xml +++ b/kernel-d-db/db-spring-boot-starter/pom.xml @@ -37,12 +37,6 @@ db-sdk-flyway ${roses.version} - - - com.alibaba - druid-spring-boot-starter - 1.2.8 - diff --git a/kernel-d-db/db-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/db/starter/RemoveDruidAdConfig.java b/kernel-d-db/db-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/db/starter/RemoveDruidAdConfig.java index 1128773b0..db446987e 100644 --- a/kernel-d-db/db-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/db/starter/RemoveDruidAdConfig.java +++ b/kernel-d-db/db-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/db/starter/RemoveDruidAdConfig.java @@ -1,38 +1,29 @@ package cn.stylefeng.roses.kernel.db.starter; -import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; -import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties; +import cn.stylefeng.roses.kernel.db.api.pojo.druid.DruidProperties; import com.alibaba.druid.util.Utils; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; - import javax.servlet.*; import java.io.IOException; @Configuration -@ConditionalOnWebApplication -@AutoConfigureAfter(DruidDataSourceAutoConfigure.class) -@ConditionalOnProperty(name = "spring.datasource.druid.stat-view-servlet.enabled", havingValue = "true", matchIfMissing = true) +@AutoConfigureBefore(DataSourceAutoConfiguration.class) public class RemoveDruidAdConfig { - /** - * 方法名: removeDruidAdFilterRegistrationBean - * 方法描述: 除去页面底部的广告 - * @param properties - * @return org.springframework.boot.web.servlet.FilterRegistrationBean - * @throws + * 除去页面底部的广告 + * + * @author xixiaowei + * @date 2022/1/24 15:23 */ @Bean - public FilterRegistrationBean removeDruidAdFilterRegistrationBean(DruidStatProperties properties) { - // 获取web监控页面的参数 - DruidStatProperties.StatViewServlet config = properties.getStatViewServlet(); + public FilterRegistrationBean removeDruidAdFilterRegistrationBean() { // 提取common.js的配置路径 - String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*"; + String pattern = "/druid/*"; String commonJsPattern = pattern.replaceAll("\\*", "js/common.js"); final String filePath = "support/http/resources/js/common.js";