From e0a274fada04d0410a5bcfb5d735439a4d35350c Mon Sep 17 00:00:00 2001 From: MaxKey Date: Thu, 13 Jan 2022 10:46:38 +0800 Subject: [PATCH] mv to repository --- .../google/code/kaptcha/impl/LightNoise.java | 19 +- .../com/google/code/kaptcha/impl/Ripple.java | 17 ++ .../text/impl/RandomColorWordRenderer.java | 17 ++ .../realm/AbstractAuthenticationRealm.java | 30 +- .../realm/jdbc/JdbcAuthenticationRealm.java | 31 +- .../AuthenticationAutoConfiguration.java | 18 +- .../main/java/org/maxkey/util/ExcelUtils.java | 17 ++ .../src/test/java/org/maxkey/Copyright.java | 2 +- .../java/org/maxkey/Integer2LongTest.java | 17 ++ .../src/test/java/org/maxkey/copyright.txt | 2 +- .../java/org/maxkey/util/InstanceTest.java | 17 ++ .../java/org/maxkey/word/RunJavaEnvs.java | 17 ++ .../ApplicationAutoConfiguration.java | 17 +- .../autoconfigure/MvcAutoConfiguration.java | 16 +- .../java/org/maxkey/entity/LdapContext.java | 280 ++++++++++++++++++ .../java/org/maxkey/entity/Localization.java | 17 ++ .../InstitutionsRepository.java} | 8 +- .../LocalizationRepository.java} | 14 +- .../LoginHistoryRepository.java} | 8 +- .../LoginRepository.java} | 10 +- .../PasswordPolicyMessageResolver.java | 2 +- .../repository/PasswordPolicyRepository.java | 185 ++++++++++++ .../PasswordPolicyValidator.java | 171 +---------- .../maxkey/web/SessionListenerAdapter.java | 36 +-- .../org/maxkey/web/WebInstRequestFilter.java | 10 +- .../maxkey/web/tag/LocaleTagDirective.java | 4 +- .../java/org/gateway/GatewayApplication.java | 17 ++ .../controller/FallbackController.java | 17 ++ .../org/gateway/filter/AuthAndLogFilter.java | 17 ++ .../route/NacosDynamicRouteService.java | 17 ++ .../scim/resources/ScimParameters.java | 17 ++ .../persistence/service/UserInfoService.java | 2 +- .../provider/OAuth2UserDetailsService.java | 19 +- .../Oauth20AutoConfiguration.java | 6 +- .../boot/monitor/MaxKeyBootMonitor.java | 17 ++ .../monitor/MonitorSecurityConfigurer.java | 17 ++ .../main/java/org/maxkey/MaxKeyConfig.java | 10 +- .../contorller/ForgotPasswordContorller.java | 2 +- .../maxkey/web/contorller/SafeController.java | 2 +- .../contorller/LoginSessionController.java | 12 +- .../main/java/org/maxkey/MaxKeyMgtConfig.java | 14 +- .../contorller/LocalizationController.java | 10 +- .../contorller/LoginSessionController.java | 12 +- 43 files changed, 884 insertions(+), 306 deletions(-) create mode 100644 maxkey-core/src/main/java/org/maxkey/entity/LdapContext.java rename maxkey-core/src/main/java/org/maxkey/persistence/{db/InstitutionService.java => repository/InstitutionsRepository.java} (95%) rename maxkey-core/src/main/java/org/maxkey/persistence/{db/LocalizationService.java => repository/LocalizationRepository.java} (93%) rename maxkey-core/src/main/java/org/maxkey/persistence/{db/LoginHistoryService.java => repository/LoginHistoryRepository.java} (95%) rename maxkey-core/src/main/java/org/maxkey/persistence/{db/LoginService.java => repository/LoginRepository.java} (98%) rename maxkey-core/src/main/java/org/maxkey/persistence/{db => repository}/PasswordPolicyMessageResolver.java (98%) create mode 100644 maxkey-core/src/main/java/org/maxkey/persistence/repository/PasswordPolicyRepository.java rename maxkey-core/src/main/java/org/maxkey/persistence/{db => repository}/PasswordPolicyValidator.java (63%) diff --git a/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/impl/LightNoise.java b/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/impl/LightNoise.java index f9f236c5..28c8362c 100644 --- a/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/impl/LightNoise.java +++ b/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/impl/LightNoise.java @@ -1,3 +1,20 @@ +/* + * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package com.google.code.kaptcha.impl; import java.awt.BasicStroke; @@ -91,4 +108,4 @@ public class LightNoise extends Configurable implements NoiseProducer graph.dispose(); } -} \ No newline at end of file +} diff --git a/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/impl/Ripple.java b/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/impl/Ripple.java index 718b7df0..859a4d54 100644 --- a/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/impl/Ripple.java +++ b/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/impl/Ripple.java @@ -1,3 +1,20 @@ +/* + * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package com.google.code.kaptcha.impl; import java.awt.Graphics2D; diff --git a/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/text/impl/RandomColorWordRenderer.java b/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/text/impl/RandomColorWordRenderer.java index 050770cc..14aea489 100644 --- a/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/text/impl/RandomColorWordRenderer.java +++ b/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/text/impl/RandomColorWordRenderer.java @@ -1,3 +1,20 @@ +/* + * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package com.google.code.kaptcha.text.impl; import java.awt.Color; diff --git a/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/realm/AbstractAuthenticationRealm.java b/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/realm/AbstractAuthenticationRealm.java index 368dd0d5..b4533fcc 100644 --- a/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/realm/AbstractAuthenticationRealm.java +++ b/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/realm/AbstractAuthenticationRealm.java @@ -26,10 +26,10 @@ import org.maxkey.authn.support.rememberme.AbstractRemeberMeService; import org.maxkey.entity.Groups; import org.maxkey.entity.HistoryLogin; import org.maxkey.entity.UserInfo; -import org.maxkey.persistence.db.LoginHistoryService; -import org.maxkey.persistence.db.PasswordPolicyValidator; +import org.maxkey.persistence.repository.LoginHistoryRepository; +import org.maxkey.persistence.repository.LoginRepository; +import org.maxkey.persistence.repository.PasswordPolicyValidator; import org.maxkey.persistence.service.UserInfoService; -import org.maxkey.persistence.db.LoginService; import org.maxkey.util.DateUtils; import org.maxkey.web.WebConstants; import org.maxkey.web.WebContext; @@ -52,9 +52,9 @@ public abstract class AbstractAuthenticationRealm { protected PasswordPolicyValidator passwordPolicyValidator; - protected LoginService loginService; + protected LoginRepository loginRepository; - protected LoginHistoryService loginHistoryService; + protected LoginHistoryRepository loginHistoryRepository; protected AbstractRemeberMeService remeberMeService; @@ -81,12 +81,12 @@ public abstract class AbstractAuthenticationRealm { return passwordPolicyValidator; } - public LoginService getUserInfoLoginService() { - return loginService; + public LoginRepository getLoginRepository() { + return loginRepository; } public UserInfo loadUserInfo(String username, String password) { - return loginService.find(username, password); + return loginRepository.find(username, password); } public abstract boolean passwordMatches(UserInfo userInfo, String password); @@ -102,7 +102,7 @@ public abstract class AbstractAuthenticationRealm { public List queryGroups(UserInfo userInfo) { - return loginService.queryGroups(userInfo); + return loginRepository.queryGroups(userInfo); } /** @@ -112,7 +112,7 @@ public abstract class AbstractAuthenticationRealm { * @return ArrayList */ public ArrayList grantAuthority(UserInfo userInfo) { - return loginService.grantAuthority(userInfo); + return loginRepository.grantAuthority(userInfo); } /** @@ -122,7 +122,7 @@ public abstract class AbstractAuthenticationRealm { * @return ArrayList */ public ArrayList queryAuthorizedApps(ArrayList grantedAuthoritys) { - return loginService.queryAuthorizedApps(grantedAuthoritys); + return loginRepository.queryAuthorizedApps(grantedAuthoritys); } /** @@ -161,9 +161,9 @@ public abstract class AbstractAuthenticationRealm { historyLogin.setDisplayName(userInfo.getDisplayName()); historyLogin.setInstId(userInfo.getInstId()); - loginHistoryService.login(historyLogin); + loginHistoryRepository.login(historyLogin); - loginService.updateLastLogin(userInfo); + loginRepository.updateLastLogin(userInfo); return true; } @@ -182,10 +182,10 @@ public abstract class AbstractAuthenticationRealm { if (sessionIdAttribute != null) { remeberMeService.removeRemeberMe(response); - loginHistoryService.logoff(userInfo.getLastLogoffTime(), sessionIdAttribute.toString()); + loginHistoryRepository.logoff(userInfo.getLastLogoffTime(), sessionIdAttribute.toString()); } - loginService.updateLastLogoff(userInfo); + loginRepository.updateLastLogoff(userInfo); _logger.debug("Session " + WebContext.getAttribute(WebConstants.CURRENT_USER_SESSION_ID) + ", user " + userInfo.getUsername() + " Logout, datetime " + userInfo.getLastLogoffTime() + " ."); diff --git a/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/realm/jdbc/JdbcAuthenticationRealm.java b/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/realm/jdbc/JdbcAuthenticationRealm.java index d8212252..23511887 100644 --- a/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/realm/jdbc/JdbcAuthenticationRealm.java +++ b/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/realm/jdbc/JdbcAuthenticationRealm.java @@ -20,10 +20,11 @@ package org.maxkey.authn.realm.jdbc; import org.maxkey.authn.realm.AbstractAuthenticationRealm; import org.maxkey.authn.support.rememberme.AbstractRemeberMeService; import org.maxkey.constants.ConstantsLoginType; +import org.maxkey.entity.PasswordPolicy; import org.maxkey.entity.UserInfo; -import org.maxkey.persistence.db.LoginHistoryService; -import org.maxkey.persistence.db.LoginService; -import org.maxkey.persistence.db.PasswordPolicyValidator; +import org.maxkey.persistence.repository.LoginHistoryRepository; +import org.maxkey.persistence.repository.LoginRepository; +import org.maxkey.persistence.repository.PasswordPolicyValidator; import org.maxkey.persistence.service.UserInfoService; import org.maxkey.web.WebConstants; import org.maxkey.web.WebContext; @@ -54,16 +55,16 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm { public JdbcAuthenticationRealm( PasswordEncoder passwordEncoder, PasswordPolicyValidator passwordPolicyValidator, - LoginService loginService, - LoginHistoryService loginHistoryService, + LoginRepository loginRepository, + LoginHistoryRepository loginHistoryRepository, AbstractRemeberMeService remeberMeService, UserInfoService userInfoService, JdbcTemplate jdbcTemplate) { this.passwordEncoder =passwordEncoder; this.passwordPolicyValidator=passwordPolicyValidator; - this.loginService = loginService; - this.loginHistoryService = loginHistoryService; + this.loginRepository = loginRepository; + this.loginHistoryRepository = loginHistoryRepository; this.remeberMeService = remeberMeService; this.userInfoService = userInfoService; this.jdbcTemplate = jdbcTemplate; @@ -73,8 +74,8 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm { public JdbcAuthenticationRealm( PasswordEncoder passwordEncoder, PasswordPolicyValidator passwordPolicyValidator, - LoginService loginService, - LoginHistoryService loginHistoryService, + LoginRepository loginRepository, + LoginHistoryRepository loginHistoryRepository, AbstractRemeberMeService remeberMeService, UserInfoService userInfoService, JdbcTemplate jdbcTemplate, @@ -84,8 +85,8 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm { this.passwordEncoder =passwordEncoder; this.passwordPolicyValidator=passwordPolicyValidator; - this.loginService = loginService; - this.loginHistoryService = loginHistoryService; + this.loginRepository = loginRepository; + this.loginHistoryRepository = loginHistoryRepository; this.remeberMeService = remeberMeService; this.jdbcTemplate = jdbcTemplate; this.ldapAuthenticationRealm = ldapAuthenticationRealm; @@ -121,14 +122,14 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm { if (!passwordMatches) { passwordPolicyValidator.plusBadPasswordCount(userInfo); insertLoginHistory(userInfo, ConstantsLoginType.LOCAL, "", "xe00000004", WebConstants.LOGIN_RESULT.PASSWORD_ERROE); - - if(userInfo.getBadPasswordCount()>=(passwordPolicyValidator.getPasswordPolicy().getAttempts()/2)) { + PasswordPolicy passwordPolicy = passwordPolicyValidator.getPasswordPolicyRepository().getPasswordPolicy(); + if(userInfo.getBadPasswordCount()>=(passwordPolicy.getAttempts()/2)) { throw new BadCredentialsException( WebContext.getI18nValue("login.error.password.attempts", new Object[]{ userInfo.getBadPasswordCount() + 1, - passwordPolicyValidator.getPasswordPolicy().getAttempts(), - passwordPolicyValidator.getPasswordPolicy().getDuration()})); + passwordPolicy.getAttempts(), + passwordPolicy.getDuration()})); }else { throw new BadCredentialsException(WebContext.getI18nValue("login.error.password")); } diff --git a/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/autoconfigure/AuthenticationAutoConfiguration.java b/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/autoconfigure/AuthenticationAutoConfiguration.java index ce7b66bc..6de2f37c 100644 --- a/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/autoconfigure/AuthenticationAutoConfiguration.java +++ b/maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/autoconfigure/AuthenticationAutoConfiguration.java @@ -27,8 +27,10 @@ import org.maxkey.authn.support.rememberme.AbstractRemeberMeService; import org.maxkey.authn.support.rememberme.RemeberMeServiceFactory; import org.maxkey.configuration.ApplicationConfig; import org.maxkey.password.onetimepwd.AbstractOtpAuthn; -import org.maxkey.persistence.db.PasswordPolicyValidator; import org.maxkey.persistence.redis.RedisConnectionFactory; +import org.maxkey.persistence.repository.LoginHistoryRepository; +import org.maxkey.persistence.repository.LoginRepository; +import org.maxkey.persistence.repository.PasswordPolicyValidator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; @@ -37,8 +39,6 @@ import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.core.JdbcTemplate; -import org.maxkey.persistence.db.LoginService; -import org.maxkey.persistence.db.LoginHistoryService; @Configuration @@ -80,13 +80,13 @@ public class AuthenticationAutoConfiguration implements InitializingBean { return new PasswordPolicyValidator(jdbcTemplate,messageSource); } - @Bean(name = "loginService") - public LoginService LoginService(JdbcTemplate jdbcTemplate) { - return new LoginService(jdbcTemplate); + @Bean(name = "loginRepository") + public LoginRepository loginRepository(JdbcTemplate jdbcTemplate) { + return new LoginRepository(jdbcTemplate); } - @Bean(name = "loginHistoryService") - public LoginHistoryService loginHistoryService(JdbcTemplate jdbcTemplate) { - return new LoginHistoryService(jdbcTemplate); + @Bean(name = "loginHistoryRepository") + public LoginHistoryRepository LoginHistoryRepository(JdbcTemplate jdbcTemplate) { + return new LoginHistoryRepository(jdbcTemplate); } /** diff --git a/maxkey-common/src/main/java/org/maxkey/util/ExcelUtils.java b/maxkey-common/src/main/java/org/maxkey/util/ExcelUtils.java index 85493018..7dd04902 100644 --- a/maxkey-common/src/main/java/org/maxkey/util/ExcelUtils.java +++ b/maxkey-common/src/main/java/org/maxkey/util/ExcelUtils.java @@ -1,3 +1,20 @@ +/* + * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package org.maxkey.util; import java.text.DecimalFormat; diff --git a/maxkey-common/src/test/java/org/maxkey/Copyright.java b/maxkey-common/src/test/java/org/maxkey/Copyright.java index 4d09056c..315678bf 100644 --- a/maxkey-common/src/test/java/org/maxkey/Copyright.java +++ b/maxkey-common/src/test/java/org/maxkey/Copyright.java @@ -31,7 +31,7 @@ import java.io.OutputStreamWriter; */ public class Copyright { // 存放java文件的文件夹,必须是文件夹 - private static String srcFolder = "C:\\IDES\\shimi\\eclipse-workspace\\MaxKey"; + private static String srcFolder = "D:\\MaxKey\\workspace\\workspace-maxkey\\MaxKey"; //已添加标识 private static String copyRightText = "http://www.apache.org/licenses/LICENSE-2.0"; //扫描目录 diff --git a/maxkey-common/src/test/java/org/maxkey/Integer2LongTest.java b/maxkey-common/src/test/java/org/maxkey/Integer2LongTest.java index 980825f4..530fbd32 100644 --- a/maxkey-common/src/test/java/org/maxkey/Integer2LongTest.java +++ b/maxkey-common/src/test/java/org/maxkey/Integer2LongTest.java @@ -1,3 +1,20 @@ +/* + * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package org.maxkey; public class Integer2LongTest { diff --git a/maxkey-common/src/test/java/org/maxkey/copyright.txt b/maxkey-common/src/test/java/org/maxkey/copyright.txt index 9759194f..70db8b51 100644 --- a/maxkey-common/src/test/java/org/maxkey/copyright.txt +++ b/maxkey-common/src/test/java/org/maxkey/copyright.txt @@ -1,5 +1,5 @@ /* - * Copyright [2021] [MaxKey of copyright http://www.maxkey.top] + * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/maxkey-common/src/test/java/org/maxkey/util/InstanceTest.java b/maxkey-common/src/test/java/org/maxkey/util/InstanceTest.java index e22320d0..32190bcf 100644 --- a/maxkey-common/src/test/java/org/maxkey/util/InstanceTest.java +++ b/maxkey-common/src/test/java/org/maxkey/util/InstanceTest.java @@ -1,3 +1,20 @@ +/* + * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package org.maxkey.util; import java.security.Provider; diff --git a/maxkey-common/src/test/java/org/maxkey/word/RunJavaEnvs.java b/maxkey-common/src/test/java/org/maxkey/word/RunJavaEnvs.java index 2d3f39eb..8646d50a 100644 --- a/maxkey-common/src/test/java/org/maxkey/word/RunJavaEnvs.java +++ b/maxkey-common/src/test/java/org/maxkey/word/RunJavaEnvs.java @@ -1,3 +1,20 @@ +/* + * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package org.maxkey.word; import java.util.Iterator; diff --git a/maxkey-core/src/main/java/org/maxkey/autoconfigure/ApplicationAutoConfiguration.java b/maxkey-core/src/main/java/org/maxkey/autoconfigure/ApplicationAutoConfiguration.java index 3ec7a6c5..f426c3eb 100644 --- a/maxkey-core/src/main/java/org/maxkey/autoconfigure/ApplicationAutoConfiguration.java +++ b/maxkey-core/src/main/java/org/maxkey/autoconfigure/ApplicationAutoConfiguration.java @@ -29,8 +29,8 @@ import org.maxkey.crypto.password.MessageDigestPasswordEncoder; import org.maxkey.crypto.password.PasswordReciprocal; import org.maxkey.crypto.password.SM3PasswordEncoder; import org.maxkey.crypto.password.StandardPasswordEncoder; -import org.maxkey.persistence.db.InstitutionService; -import org.maxkey.persistence.db.LocalizationService; +import org.maxkey.persistence.repository.InstitutionsRepository; +import org.maxkey.persistence.repository.LocalizationRepository; import org.maxkey.util.IdGenerator; import org.maxkey.util.SnowFlakeId; import org.maxkey.web.WebContext; @@ -65,14 +65,15 @@ public class ApplicationAutoConfiguration implements InitializingBean { return new DataSourceTransactionManager(dataSource); } - @Bean(name = "institutionService") - public InstitutionService institutionService(JdbcTemplate jdbcTemplate) { - return new InstitutionService(jdbcTemplate); + @Bean(name = "institutionsRepository") + public InstitutionsRepository InstitutionsRepository(JdbcTemplate jdbcTemplate) { + return new InstitutionsRepository(jdbcTemplate); } - @Bean(name = "localizationService") - public LocalizationService localizationService(JdbcTemplate jdbcTemplate,InstitutionService institutionService) { - return new LocalizationService(jdbcTemplate,institutionService); + @Bean(name = "localizationRepository") + public LocalizationRepository localizationRepository(JdbcTemplate jdbcTemplate, + InstitutionsRepository institutionsRepository) { + return new LocalizationRepository(jdbcTemplate,institutionsRepository); } /** diff --git a/maxkey-core/src/main/java/org/maxkey/autoconfigure/MvcAutoConfiguration.java b/maxkey-core/src/main/java/org/maxkey/autoconfigure/MvcAutoConfiguration.java index 575cff82..16d1dfd7 100644 --- a/maxkey-core/src/main/java/org/maxkey/autoconfigure/MvcAutoConfiguration.java +++ b/maxkey-core/src/main/java/org/maxkey/autoconfigure/MvcAutoConfiguration.java @@ -24,9 +24,9 @@ import javax.servlet.Filter; import org.maxkey.configuration.ApplicationConfig; import org.maxkey.constants.ConstantsTimeInterval; -import org.maxkey.persistence.db.InstitutionService; -import org.maxkey.persistence.db.LoginHistoryService; -import org.maxkey.persistence.db.LoginService; +import org.maxkey.persistence.repository.InstitutionsRepository; +import org.maxkey.persistence.repository.LoginHistoryRepository; +import org.maxkey.persistence.repository.LoginRepository; import org.maxkey.web.SessionListenerAdapter; import org.maxkey.web.WebXssRequestFilter; import org.maxkey.web.WebInstRequestFilter; @@ -284,11 +284,11 @@ public class MvcAutoConfiguration implements InitializingBean , WebMvcConfigurer @Bean public FilterRegistrationBean WebInstRequestFilter( - InstitutionService institutionService, + InstitutionsRepository institutionsRepository, ApplicationConfig applicationConfig) { _logger.debug("WebInstRequestFilter init for /* "); FilterRegistrationBean registrationBean = - new FilterRegistrationBean(new WebInstRequestFilter(institutionService,applicationConfig)); + new FilterRegistrationBean(new WebInstRequestFilter(institutionsRepository,applicationConfig)); registrationBean.addUrlPatterns("/*"); registrationBean.setName("webInstRequestFilter"); registrationBean.setOrder(3); @@ -297,11 +297,11 @@ public class MvcAutoConfiguration implements InitializingBean , WebMvcConfigurer @Bean(name = "sessionListenerAdapter") public SessionListenerAdapter sessionListenerAdapter( - LoginService loginService, - LoginHistoryService loginHistoryService + LoginRepository loginRepository, + LoginHistoryRepository loginHistoryRepository ) { SessionListenerAdapter sessionListenerAdapter = - new SessionListenerAdapter(loginService,loginHistoryService); + new SessionListenerAdapter(loginRepository,loginHistoryRepository); return sessionListenerAdapter; } diff --git a/maxkey-core/src/main/java/org/maxkey/entity/LdapContext.java b/maxkey-core/src/main/java/org/maxkey/entity/LdapContext.java new file mode 100644 index 00000000..01e7c0a0 --- /dev/null +++ b/maxkey-core/src/main/java/org/maxkey/entity/LdapContext.java @@ -0,0 +1,280 @@ +/* + * Copyright [2021] [MaxKey of copyright http://www.maxkey.top] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package org.maxkey.entity; + +import java.io.Serializable; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import org.apache.mybatis.jpa.persistence.JpaBaseEntity; + +@Entity +@Table(name = "MXK_LDAP_CONTEXT") +public class LdapContext extends JpaBaseEntity implements Serializable { + + + /** + * + */ + private static final long serialVersionUID = -4595539647817265938L; + @Id + @Column + @GeneratedValue(strategy = GenerationType.AUTO, generator = "snowflakeid") + String id; + @Column + String product; + @Column + String providerUrl; + @Column + String principal; + @Column + String credentials; + @Column + String filters; + @Column + String basedn; + @Column + String msadDomain; + @Column + String sslSwitch; + @Column + String trustStore; + @Column + String trustStorePassword; + @Column + String description; + @Column + String createdBy; + @Column + String createdDate; + @Column + String modifiedBy; + @Column + String modifiedDate; + @Column + int status; + + @Column + private String instId; + + private String instName; + + public LdapContext() { + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getProduct() { + return product; + } + + public void setProduct(String product) { + this.product = product; + } + + public String getProviderUrl() { + return providerUrl; + } + + public void setProviderUrl(String providerUrl) { + this.providerUrl = providerUrl; + } + + public String getPrincipal() { + return principal; + } + + public void setPrincipal(String principal) { + this.principal = principal; + } + + public String getCredentials() { + return credentials; + } + + public void setCredentials(String credentials) { + this.credentials = credentials; + } + + public String getFilters() { + return filters; + } + + public void setFilters(String filters) { + this.filters = filters; + } + + public String getBasedn() { + return basedn; + } + + public void setBasedn(String basedn) { + this.basedn = basedn; + } + + public String getMsadDomain() { + return msadDomain; + } + + public void setMsadDomain(String msadDomain) { + this.msadDomain = msadDomain; + } + + public String getSslSwitch() { + return sslSwitch; + } + + public void setSslSwitch(String sslSwitch) { + this.sslSwitch = sslSwitch; + } + + public String getTrustStore() { + return trustStore; + } + + public void setTrustStore(String trustStore) { + this.trustStore = trustStore; + } + + public String getTrustStorePassword() { + return trustStorePassword; + } + + public void setTrustStorePassword(String trustStorePassword) { + this.trustStorePassword = trustStorePassword; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public String getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(String createdDate) { + this.createdDate = createdDate; + } + + public String getModifiedBy() { + return modifiedBy; + } + + public void setModifiedBy(String modifiedBy) { + this.modifiedBy = modifiedBy; + } + + public String getModifiedDate() { + return modifiedDate; + } + + public void setModifiedDate(String modifiedDate) { + this.modifiedDate = modifiedDate; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public String getInstId() { + return instId; + } + + public void setInstId(String instId) { + this.instId = instId; + } + + public String getInstName() { + return instName; + } + + public void setInstName(String instName) { + this.instName = instName; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("LdapContext [id="); + builder.append(id); + builder.append(", product="); + builder.append(product); + builder.append(", providerUrl="); + builder.append(providerUrl); + builder.append(", principal="); + builder.append(principal); + builder.append(", credentials="); + builder.append(credentials); + builder.append(", filters="); + builder.append(filters); + builder.append(", basedn="); + builder.append(basedn); + builder.append(", msadDomain="); + builder.append(msadDomain); + builder.append(", sslSwitch="); + builder.append(sslSwitch); + builder.append(", trustStore="); + builder.append(trustStore); + builder.append(", trustStorePassword="); + builder.append(trustStorePassword); + builder.append(", description="); + builder.append(description); + builder.append(", createdBy="); + builder.append(createdBy); + builder.append(", createdDate="); + builder.append(createdDate); + builder.append(", modifiedBy="); + builder.append(modifiedBy); + builder.append(", modifiedDate="); + builder.append(modifiedDate); + builder.append(", status="); + builder.append(status); + builder.append(", instId="); + builder.append(instId); + builder.append(", instName="); + builder.append(instName); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/maxkey-core/src/main/java/org/maxkey/entity/Localization.java b/maxkey-core/src/main/java/org/maxkey/entity/Localization.java index f9903f5c..e77a39aa 100644 --- a/maxkey-core/src/main/java/org/maxkey/entity/Localization.java +++ b/maxkey-core/src/main/java/org/maxkey/entity/Localization.java @@ -1,3 +1,20 @@ +/* + * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package org.maxkey.entity; import java.io.Serializable; diff --git a/maxkey-core/src/main/java/org/maxkey/persistence/db/InstitutionService.java b/maxkey-core/src/main/java/org/maxkey/persistence/repository/InstitutionsRepository.java similarity index 95% rename from maxkey-core/src/main/java/org/maxkey/persistence/db/InstitutionService.java rename to maxkey-core/src/main/java/org/maxkey/persistence/repository/InstitutionsRepository.java index 0a6cc47a..a4d7ec20 100644 --- a/maxkey-core/src/main/java/org/maxkey/persistence/db/InstitutionService.java +++ b/maxkey-core/src/main/java/org/maxkey/persistence/repository/InstitutionsRepository.java @@ -15,7 +15,7 @@ */ -package org.maxkey.persistence.db; +package org.maxkey.persistence.repository; import java.sql.ResultSet; import java.sql.SQLException; @@ -34,8 +34,8 @@ import org.springframework.jdbc.core.RowMapper; import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; -public class InstitutionService { - private static Logger _logger = LoggerFactory.getLogger(InstitutionService.class); +public class InstitutionsRepository { + private static Logger _logger = LoggerFactory.getLogger(InstitutionsRepository.class); private static final String SELECT_STATEMENT = "select * from mxk_institutions where domain = ? and status = " + ConstantsStatus.ACTIVE; @@ -53,7 +53,7 @@ public class InstitutionService { protected JdbcTemplate jdbcTemplate; - public InstitutionService(JdbcTemplate jdbcTemplate) { + public InstitutionsRepository(JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; } diff --git a/maxkey-core/src/main/java/org/maxkey/persistence/db/LocalizationService.java b/maxkey-core/src/main/java/org/maxkey/persistence/repository/LocalizationRepository.java similarity index 93% rename from maxkey-core/src/main/java/org/maxkey/persistence/db/LocalizationService.java rename to maxkey-core/src/main/java/org/maxkey/persistence/repository/LocalizationRepository.java index 6dc488f5..c57cb809 100644 --- a/maxkey-core/src/main/java/org/maxkey/persistence/db/LocalizationService.java +++ b/maxkey-core/src/main/java/org/maxkey/persistence/repository/LocalizationRepository.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.maxkey.persistence.db; +package org.maxkey.persistence.repository; import java.sql.ResultSet; import java.sql.SQLException; @@ -33,8 +33,8 @@ import org.springframework.jdbc.core.RowMapper; import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; -public class LocalizationService { - private static Logger _logger = LoggerFactory.getLogger(LocalizationService.class); +public class LocalizationRepository { + private static Logger _logger = LoggerFactory.getLogger(LocalizationRepository.class); private static final String INSERT_STATEMENT ="insert into mxk_localization (id, property,langzh,langen,status,description,instid)values(?,?,?,?,?,?,?)"; private static final String UPDATE_STATEMENT ="update mxk_localization set langzh = ? , langen =? where id = ?"; private static final String DELETE_STATEMENT ="delete from mxk_localization where id = ?"; @@ -42,7 +42,7 @@ public class LocalizationService { private static final Pattern PATTERN_HTML = Pattern.compile("<[^>]+>", Pattern.CASE_INSENSITIVE); - protected InstitutionService institutionService; + protected InstitutionsRepository institutionService; JdbcTemplate jdbcTemplate; @@ -51,7 +51,7 @@ public class LocalizationService { .expireAfterWrite(ConstantsTimeInterval.ONE_HOUR, TimeUnit.SECONDS) .build(); - public LocalizationService() { + public LocalizationRepository() { } @@ -102,7 +102,7 @@ public class LocalizationService { return message; } - public void setInstitutionService(InstitutionService institutionService) { + public void setInstitutionService(InstitutionsRepository institutionService) { this.institutionService = institutionService; } @@ -133,7 +133,7 @@ public class LocalizationService { return (localizations==null || localizations.size()==0) ? null : localizations.get(0); } - public LocalizationService(JdbcTemplate jdbcTemplate,InstitutionService institutionService) { + public LocalizationRepository(JdbcTemplate jdbcTemplate,InstitutionsRepository institutionService) { super(); this.institutionService = institutionService; this.jdbcTemplate = jdbcTemplate; diff --git a/maxkey-core/src/main/java/org/maxkey/persistence/db/LoginHistoryService.java b/maxkey-core/src/main/java/org/maxkey/persistence/repository/LoginHistoryRepository.java similarity index 95% rename from maxkey-core/src/main/java/org/maxkey/persistence/db/LoginHistoryService.java rename to maxkey-core/src/main/java/org/maxkey/persistence/repository/LoginHistoryRepository.java index 25095634..0211513e 100644 --- a/maxkey-core/src/main/java/org/maxkey/persistence/db/LoginHistoryService.java +++ b/maxkey-core/src/main/java/org/maxkey/persistence/repository/LoginHistoryRepository.java @@ -15,7 +15,7 @@ */ -package org.maxkey.persistence.db; +package org.maxkey.persistence.repository; import java.sql.Types; @@ -25,8 +25,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.jdbc.core.JdbcTemplate; -public class LoginHistoryService { - private static Logger _logger = LoggerFactory.getLogger(LoginHistoryService.class); +public class LoginHistoryRepository { + private static Logger _logger = LoggerFactory.getLogger(LoginHistoryRepository.class); private static final String HISTORY_LOGIN_INSERT_STATEMENT = "insert into mxk_history_login (id , sessionid , userid , username , displayname , logintype , message , code , provider , sourceip , browser , platform , application , loginurl , sessionstatus ,instid)values( ? , ? , ? , ? , ? , ? , ?, ? , ? , ?, ? , ? , ?, ? , ? , ?)"; @@ -34,7 +34,7 @@ public class LoginHistoryService { protected JdbcTemplate jdbcTemplate; - public LoginHistoryService(JdbcTemplate jdbcTemplate) { + public LoginHistoryRepository(JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; } diff --git a/maxkey-core/src/main/java/org/maxkey/persistence/db/LoginService.java b/maxkey-core/src/main/java/org/maxkey/persistence/repository/LoginRepository.java similarity index 98% rename from maxkey-core/src/main/java/org/maxkey/persistence/db/LoginService.java rename to maxkey-core/src/main/java/org/maxkey/persistence/repository/LoginRepository.java index 9e8e1af7..38aa571d 100644 --- a/maxkey-core/src/main/java/org/maxkey/persistence/db/LoginService.java +++ b/maxkey-core/src/main/java/org/maxkey/persistence/repository/LoginRepository.java @@ -15,7 +15,7 @@ */ -package org.maxkey.persistence.db; +package org.maxkey.persistence.repository; import java.sql.ResultSet; import java.sql.SQLException; @@ -35,8 +35,8 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; -public class LoginService { - private static Logger _logger = LoggerFactory.getLogger(LoginService.class); +public class LoginRepository { + private static Logger _logger = LoggerFactory.getLogger(LoginRepository.class); private static final String LOCK_USER_UPDATE_STATEMENT = "update mxk_userinfo set islocked = ? , unlocktime = ? where id = ?"; @@ -69,11 +69,11 @@ public class LoginService { */ public static int LOGIN_ATTRIBUTE_TYPE = 2; - public LoginService(){ + public LoginRepository(){ } - public LoginService(JdbcTemplate jdbcTemplate){ + public LoginRepository(JdbcTemplate jdbcTemplate){ this.jdbcTemplate=jdbcTemplate; } diff --git a/maxkey-core/src/main/java/org/maxkey/persistence/db/PasswordPolicyMessageResolver.java b/maxkey-core/src/main/java/org/maxkey/persistence/repository/PasswordPolicyMessageResolver.java similarity index 98% rename from maxkey-core/src/main/java/org/maxkey/persistence/db/PasswordPolicyMessageResolver.java rename to maxkey-core/src/main/java/org/maxkey/persistence/repository/PasswordPolicyMessageResolver.java index 2f6f24e9..c5d92f04 100644 --- a/maxkey-core/src/main/java/org/maxkey/persistence/db/PasswordPolicyMessageResolver.java +++ b/maxkey-core/src/main/java/org/maxkey/persistence/repository/PasswordPolicyMessageResolver.java @@ -15,7 +15,7 @@ */ -package org.maxkey.persistence.db; +package org.maxkey.persistence.repository; import java.util.Locale; diff --git a/maxkey-core/src/main/java/org/maxkey/persistence/repository/PasswordPolicyRepository.java b/maxkey-core/src/main/java/org/maxkey/persistence/repository/PasswordPolicyRepository.java new file mode 100644 index 00000000..4e00afaa --- /dev/null +++ b/maxkey-core/src/main/java/org/maxkey/persistence/repository/PasswordPolicyRepository.java @@ -0,0 +1,185 @@ +/* + * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package org.maxkey.persistence.repository; + +import java.io.InputStreamReader; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.concurrent.TimeUnit; + +import org.maxkey.constants.ConstantsProperties; +import org.maxkey.entity.PasswordPolicy; +import org.passay.CharacterOccurrencesRule; +import org.passay.CharacterRule; +import org.passay.DictionaryRule; +import org.passay.EnglishCharacterData; +import org.passay.EnglishSequenceData; +import org.passay.IllegalSequenceRule; +import org.passay.LengthRule; +import org.passay.Rule; +import org.passay.UsernameRule; +import org.passay.WhitespaceRule; +import org.passay.dictionary.Dictionary; +import org.passay.dictionary.DictionaryBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.io.ClassPathResource; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; + +public class PasswordPolicyRepository { + private static Logger _logger = LoggerFactory.getLogger(PasswordPolicyRepository.class); + + //Dictionary topWeakPassword Source + public static final String topWeakPasswordPropertySource = + "classpath:/top_weak_password.txt"; + + //Cache PasswordPolicy in memory ONE_HOUR + protected static final Cache passwordPolicyStore = + Caffeine.newBuilder() + .expireAfterWrite(60, TimeUnit.MINUTES) + .build(); + + protected PasswordPolicy passwordPolicy; + + protected JdbcTemplate jdbcTemplate; + + ArrayList passwordPolicyRuleList; + + private static final String PASSWORD_POLICY_KEY = "PASSWORD_POLICY_KEY"; + + private static final String PASSWORD_POLICY_SELECT_STATEMENT = "select * from mxk_password_policy "; + + public PasswordPolicyRepository(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } + + /** + * init PasswordPolicy and load Rules + * @return + */ + public PasswordPolicy getPasswordPolicy() { + passwordPolicy = passwordPolicyStore.getIfPresent(PASSWORD_POLICY_KEY); + + if (passwordPolicy == null) { + passwordPolicy = jdbcTemplate.queryForObject(PASSWORD_POLICY_SELECT_STATEMENT, + new PasswordPolicyRowMapper()); + _logger.debug("query PasswordPolicy : " + passwordPolicy); + passwordPolicyStore.put(PASSWORD_POLICY_KEY,passwordPolicy); + + //RandomPasswordLength =(MaxLength +MinLength)/2 + passwordPolicy.setRandomPasswordLength( + Math.round( + ( + passwordPolicy.getMaxLength() + + passwordPolicy.getMinLength() + )/2 + ) + ); + + passwordPolicyRuleList = new ArrayList(); + passwordPolicyRuleList.add(new WhitespaceRule()); + passwordPolicyRuleList.add(new LengthRule(passwordPolicy.getMinLength(), passwordPolicy.getMaxLength())); + + if(passwordPolicy.getUpperCase()>0) { + passwordPolicyRuleList.add(new CharacterRule(EnglishCharacterData.UpperCase, passwordPolicy.getUpperCase())); + } + + if(passwordPolicy.getLowerCase()>0) { + passwordPolicyRuleList.add(new CharacterRule(EnglishCharacterData.LowerCase, passwordPolicy.getLowerCase())); + } + + if(passwordPolicy.getDigits()>0) { + passwordPolicyRuleList.add(new CharacterRule(EnglishCharacterData.Digit, passwordPolicy.getDigits())); + } + + if(passwordPolicy.getSpecialChar()>0) { + passwordPolicyRuleList.add(new CharacterRule(EnglishCharacterData.Special, passwordPolicy.getSpecialChar())); + } + + if(passwordPolicy.getUsername()>0) { + passwordPolicyRuleList.add(new UsernameRule()); + } + + if(passwordPolicy.getOccurances()>0) { + passwordPolicyRuleList.add(new CharacterOccurrencesRule(passwordPolicy.getOccurances())); + } + + if(passwordPolicy.getAlphabetical()>0) { + passwordPolicyRuleList.add(new IllegalSequenceRule(EnglishSequenceData.Alphabetical, 4, false)); + } + + if(passwordPolicy.getNumerical()>0) { + passwordPolicyRuleList.add(new IllegalSequenceRule(EnglishSequenceData.Numerical, 4, false)); + } + + if(passwordPolicy.getQwerty()>0) { + passwordPolicyRuleList.add(new IllegalSequenceRule(EnglishSequenceData.USQwerty, 4, false)); + } + + if(passwordPolicy.getDictionary()>0 ) { + try { + ClassPathResource dictFile= + new ClassPathResource( + ConstantsProperties.classPathResource(topWeakPasswordPropertySource)); + Dictionary dictionary =new DictionaryBuilder().addReader(new InputStreamReader(dictFile.getInputStream())).build(); + passwordPolicyRuleList.add(new DictionaryRule(dictionary)); + }catch(Exception e) { + e.printStackTrace(); + } + } + } + return passwordPolicy; + } + + + public ArrayList getPasswordPolicyRuleList() { + return passwordPolicyRuleList; + } + + +public class PasswordPolicyRowMapper implements RowMapper { + + @Override + public PasswordPolicy mapRow(ResultSet rs, int rowNum) throws SQLException { + PasswordPolicy passwordPolicy = new PasswordPolicy(); + passwordPolicy.setId(rs.getString("ID")); + passwordPolicy.setMinLength(rs.getInt("MINLENGTH")); + passwordPolicy.setMaxLength(rs.getInt("MAXLENGTH")); + passwordPolicy.setLowerCase(rs.getInt("LOWERCASE")); + passwordPolicy.setUpperCase(rs.getInt("UPPERCASE")); + passwordPolicy.setDigits(rs.getInt("DIGITS")); + passwordPolicy.setSpecialChar(rs.getInt("SPECIALCHAR")); + passwordPolicy.setAttempts(rs.getInt("ATTEMPTS")); + passwordPolicy.setDuration(rs.getInt("DURATION")); + passwordPolicy.setExpiration(rs.getInt("EXPIRATION")); + passwordPolicy.setUsername(rs.getInt("USERNAME")); + passwordPolicy.setHistory(rs.getInt("HISTORY")); + passwordPolicy.setDictionary(rs.getInt("DICTIONARY")); + passwordPolicy.setAlphabetical(rs.getInt("ALPHABETICAL")); + passwordPolicy.setNumerical(rs.getInt("NUMERICAL")); + passwordPolicy.setQwerty(rs.getInt("QWERTY")); + passwordPolicy.setOccurances(rs.getInt("OCCURANCES")); + return passwordPolicy; + } + + } +} diff --git a/maxkey-core/src/main/java/org/maxkey/persistence/db/PasswordPolicyValidator.java b/maxkey-core/src/main/java/org/maxkey/persistence/repository/PasswordPolicyValidator.java similarity index 63% rename from maxkey-core/src/main/java/org/maxkey/persistence/db/PasswordPolicyValidator.java rename to maxkey-core/src/main/java/org/maxkey/persistence/repository/PasswordPolicyValidator.java index 174e00b5..4d6bbd7a 100644 --- a/maxkey-core/src/main/java/org/maxkey/persistence/db/PasswordPolicyValidator.java +++ b/maxkey-core/src/main/java/org/maxkey/persistence/repository/PasswordPolicyValidator.java @@ -15,21 +15,14 @@ */ -package org.maxkey.persistence.db; +package org.maxkey.persistence.repository; -import java.io.InputStreamReader; -import java.sql.ResultSet; -import java.sql.SQLException; import java.sql.Types; -import java.util.ArrayList; import java.util.Date; -import java.util.concurrent.TimeUnit; - import org.joda.time.DateTime; import org.joda.time.Duration; import org.joda.time.format.DateTimeFormat; import org.maxkey.constants.ConstantsPasswordSetType; -import org.maxkey.constants.ConstantsProperties; import org.maxkey.constants.ConstantsStatus; import org.maxkey.crypto.password.PasswordGen; import org.maxkey.entity.PasswordPolicy; @@ -37,48 +30,19 @@ import org.maxkey.entity.UserInfo; import org.maxkey.util.StringUtils; import org.maxkey.web.WebConstants; import org.maxkey.web.WebContext; -import org.passay.CharacterOccurrencesRule; -import org.passay.CharacterRule; -import org.passay.DictionaryRule; -import org.passay.EnglishCharacterData; -import org.passay.EnglishSequenceData; -import org.passay.IllegalSequenceRule; -import org.passay.LengthRule; import org.passay.PasswordData; import org.passay.PasswordValidator; -import org.passay.Rule; import org.passay.RuleResult; -import org.passay.UsernameRule; -import org.passay.WhitespaceRule; -import org.passay.dictionary.Dictionary; -import org.passay.dictionary.DictionaryBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.MessageSource; -import org.springframework.core.io.ClassPathResource; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowMapper; import org.springframework.security.authentication.BadCredentialsException; -import com.github.benmanes.caffeine.cache.Cache; -import com.github.benmanes.caffeine.cache.Caffeine; - public class PasswordPolicyValidator { private static Logger _logger = LoggerFactory.getLogger(PasswordPolicyValidator.class); - //Dictionary topWeakPassword Source - public static final String topWeakPasswordPropertySource = - "classpath:/top_weak_password.txt"; - - //Cache PasswordPolicy in memory ONE_HOUR - protected static final Cache passwordPolicyStore = - Caffeine.newBuilder() - .expireAfterWrite(60, TimeUnit.MINUTES) - .build(); - - protected PasswordPolicy passwordPolicy; - - ArrayList passwordPolicyRuleList; + PasswordPolicyRepository passwordPolicyRepository; protected JdbcTemplate jdbcTemplate; @@ -86,12 +50,8 @@ public class PasswordPolicyValidator { public static final String PASSWORD_POLICY_VALIDATE_RESULT = "PASSWORD_POLICY_SESSION_VALIDATE_RESULT_KEY"; - private static final String PASSWORD_POLICY_KEY = "PASSWORD_POLICY_KEY"; - private static final String LOCK_USER_UPDATE_STATEMENT = "update mxk_userinfo set islocked = ? , unlocktime = ? where id = ?"; - private static final String PASSWORD_POLICY_SELECT_STATEMENT = "select * from mxk_password_policy "; - private static final String UNLOCK_USER_UPDATE_STATEMENT = "update mxk_userinfo set islocked = ? , unlocktime = ? where id = ?"; private static final String BADPASSWORDCOUNT_UPDATE_STATEMENT = "update mxk_userinfo set badpasswordcount = ? , badpasswordtime = ? where id = ?"; @@ -104,84 +64,8 @@ public class PasswordPolicyValidator { public PasswordPolicyValidator(JdbcTemplate jdbcTemplate,MessageSource messageSource) { this.messageSource=messageSource; this.jdbcTemplate = jdbcTemplate; - } - - /** - * init PasswordPolicy and load Rules - * @return - */ - public PasswordPolicy getPasswordPolicy() { - passwordPolicy = passwordPolicyStore.getIfPresent(PASSWORD_POLICY_KEY); - - if (passwordPolicy == null) { - passwordPolicy = jdbcTemplate.queryForObject(PASSWORD_POLICY_SELECT_STATEMENT, - new PasswordPolicyRowMapper()); - _logger.debug("query PasswordPolicy : " + passwordPolicy); - passwordPolicyStore.put(PASSWORD_POLICY_KEY,passwordPolicy); - - //RandomPasswordLength =(MaxLength +MinLength)/2 - passwordPolicy.setRandomPasswordLength( - Math.round( - ( - passwordPolicy.getMaxLength() + - passwordPolicy.getMinLength() - )/2 - ) - ); - - passwordPolicyRuleList = new ArrayList(); - passwordPolicyRuleList.add(new WhitespaceRule()); - passwordPolicyRuleList.add(new LengthRule(passwordPolicy.getMinLength(), passwordPolicy.getMaxLength())); - - if(passwordPolicy.getUpperCase()>0) { - passwordPolicyRuleList.add(new CharacterRule(EnglishCharacterData.UpperCase, passwordPolicy.getUpperCase())); - } - - if(passwordPolicy.getLowerCase()>0) { - passwordPolicyRuleList.add(new CharacterRule(EnglishCharacterData.LowerCase, passwordPolicy.getLowerCase())); - } - - if(passwordPolicy.getDigits()>0) { - passwordPolicyRuleList.add(new CharacterRule(EnglishCharacterData.Digit, passwordPolicy.getDigits())); - } - - if(passwordPolicy.getSpecialChar()>0) { - passwordPolicyRuleList.add(new CharacterRule(EnglishCharacterData.Special, passwordPolicy.getSpecialChar())); - } - - if(passwordPolicy.getUsername()>0) { - passwordPolicyRuleList.add(new UsernameRule()); - } - - if(passwordPolicy.getOccurances()>0) { - passwordPolicyRuleList.add(new CharacterOccurrencesRule(passwordPolicy.getOccurances())); - } - - if(passwordPolicy.getAlphabetical()>0) { - passwordPolicyRuleList.add(new IllegalSequenceRule(EnglishSequenceData.Alphabetical, 4, false)); - } - - if(passwordPolicy.getNumerical()>0) { - passwordPolicyRuleList.add(new IllegalSequenceRule(EnglishSequenceData.Numerical, 4, false)); - } - - if(passwordPolicy.getQwerty()>0) { - passwordPolicyRuleList.add(new IllegalSequenceRule(EnglishSequenceData.USQwerty, 4, false)); - } - - if(passwordPolicy.getDictionary()>0 ) { - try { - ClassPathResource dictFile= - new ClassPathResource( - ConstantsProperties.classPathResource(topWeakPasswordPropertySource)); - Dictionary dictionary =new DictionaryBuilder().addReader(new InputStreamReader(dictFile.getInputStream())).build(); - passwordPolicyRuleList.add(new DictionaryRule(dictionary)); - }catch(Exception e) { - e.printStackTrace(); - } - } - } - return passwordPolicy; + this.passwordPolicyRepository = new PasswordPolicyRepository(jdbcTemplate); + } /** @@ -200,10 +84,8 @@ public class PasswordPolicyValidator { return false; } - getPasswordPolicy(); - PasswordValidator validator = new PasswordValidator( - new PasswordPolicyMessageResolver(messageSource),passwordPolicyRuleList); + new PasswordPolicyMessageResolver(messageSource),passwordPolicyRepository.getPasswordPolicyRuleList()); RuleResult result = validator.validate(new PasswordData(username,password)); @@ -230,8 +112,8 @@ public class PasswordPolicyValidator { */ public boolean passwordPolicyValid(UserInfo userInfo) { - getPasswordPolicy(); - + PasswordPolicy passwordPolicy = passwordPolicyRepository.getPasswordPolicy(); + DateTime currentdateTime = new DateTime(); /* * check login attempts fail times @@ -285,7 +167,8 @@ public class PasswordPolicyValidator { } public void applyPasswordPolicy(UserInfo userInfo) { - getPasswordPolicy(); + PasswordPolicy passwordPolicy = passwordPolicyRepository.getPasswordPolicy(); + DateTime currentdateTime = new DateTime(); //initial password need change if(userInfo.getLoginCount()<=0) { @@ -417,7 +300,8 @@ public class PasswordPolicyValidator { } public String generateRandomPassword() { - getPasswordPolicy(); + PasswordPolicy passwordPolicy = passwordPolicyRepository.getPasswordPolicy(); + PasswordGen passwordGen = new PasswordGen( passwordPolicy.getRandomPasswordLength() ); @@ -428,36 +312,9 @@ public class PasswordPolicyValidator { passwordPolicy.getDigits(), passwordPolicy.getSpecialChar()); } - - public void setPasswordPolicy(PasswordPolicy passwordPolicy) { - this.passwordPolicy = passwordPolicy; - } - - public class PasswordPolicyRowMapper implements RowMapper { + public PasswordPolicyRepository getPasswordPolicyRepository() { + return passwordPolicyRepository; + } - @Override - public PasswordPolicy mapRow(ResultSet rs, int rowNum) throws SQLException { - PasswordPolicy passwordPolicy = new PasswordPolicy(); - passwordPolicy.setId(rs.getString("ID")); - passwordPolicy.setMinLength(rs.getInt("MINLENGTH")); - passwordPolicy.setMaxLength(rs.getInt("MAXLENGTH")); - passwordPolicy.setLowerCase(rs.getInt("LOWERCASE")); - passwordPolicy.setUpperCase(rs.getInt("UPPERCASE")); - passwordPolicy.setDigits(rs.getInt("DIGITS")); - passwordPolicy.setSpecialChar(rs.getInt("SPECIALCHAR")); - passwordPolicy.setAttempts(rs.getInt("ATTEMPTS")); - passwordPolicy.setDuration(rs.getInt("DURATION")); - passwordPolicy.setExpiration(rs.getInt("EXPIRATION")); - passwordPolicy.setUsername(rs.getInt("USERNAME")); - passwordPolicy.setHistory(rs.getInt("HISTORY")); - passwordPolicy.setDictionary(rs.getInt("DICTIONARY")); - passwordPolicy.setAlphabetical(rs.getInt("ALPHABETICAL")); - passwordPolicy.setNumerical(rs.getInt("NUMERICAL")); - passwordPolicy.setQwerty(rs.getInt("QWERTY")); - passwordPolicy.setOccurances(rs.getInt("OCCURANCES")); - return passwordPolicy; - } - - } } diff --git a/maxkey-core/src/main/java/org/maxkey/web/SessionListenerAdapter.java b/maxkey-core/src/main/java/org/maxkey/web/SessionListenerAdapter.java index 29a174a5..16679ed2 100644 --- a/maxkey-core/src/main/java/org/maxkey/web/SessionListenerAdapter.java +++ b/maxkey-core/src/main/java/org/maxkey/web/SessionListenerAdapter.java @@ -24,8 +24,8 @@ import javax.servlet.http.HttpSessionListener; import org.apache.mybatis.jpa.util.WebContext; import org.maxkey.entity.UserInfo; -import org.maxkey.persistence.db.LoginHistoryService; -import org.maxkey.persistence.db.LoginService; +import org.maxkey.persistence.repository.LoginHistoryRepository; +import org.maxkey.persistence.repository.LoginRepository; import org.maxkey.util.DateUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,26 +35,26 @@ public class SessionListenerAdapter implements HttpSessionListener { private static final Logger _logger = LoggerFactory.getLogger(SessionListenerAdapter.class); - LoginService loginService; + LoginRepository loginRepository; - LoginHistoryService loginHistoryService; + LoginHistoryRepository loginHistoryRepository; public SessionListenerAdapter() { super(); _logger.debug("SessionListenerAdapter inited . "); } - public SessionListenerAdapter(LoginService loginService, LoginHistoryService loginHistoryService) { + public SessionListenerAdapter(LoginRepository loginRepository, LoginHistoryRepository loginHistoryRepository) { super(); - this.loginService = loginService; - this.loginHistoryService = loginHistoryService; + this.loginRepository = loginRepository; + this.loginHistoryRepository = loginHistoryRepository; _logger.debug("SessionListenerAdapter inited . "); } public void init() { - if(loginService == null ) { - loginService = (LoginService)WebContext.getBean("loginService"); - loginHistoryService = (LoginHistoryService)WebContext.getBean("loginHistoryService"); + if(loginRepository == null ) { + loginRepository = (LoginRepository)WebContext.getBean("loginRepository"); + loginHistoryRepository = (LoginHistoryRepository)WebContext.getBean("loginHistoryRepository"); _logger.debug("SessionListenerAdapter function inited . "); } } @@ -78,8 +78,8 @@ public class SessionListenerAdapter implements HttpSessionListener { init(); UserInfo userInfo = (UserInfo)session.getAttribute(WebConstants.CURRENT_USER); userInfo.setLastLogoffTime(DateUtils.formatDateTime(new Date())); - loginService.updateLastLogoff(userInfo); - loginHistoryService.logoff(userInfo.getLastLogoffTime(), sessionIdAttribute.toString()); + loginRepository.updateLastLogoff(userInfo); + loginHistoryRepository.logoff(userInfo.getLastLogoffTime(), sessionIdAttribute.toString()); _logger.debug( "session {} Destroyed as {} userId : {} , username : {}" , @@ -91,12 +91,12 @@ public class SessionListenerAdapter implements HttpSessionListener { } - public void setLoginService(LoginService loginService) { - this.loginService = loginService; - } + public void setLoginRepository(LoginRepository loginRepository) { + this.loginRepository = loginRepository; + } - public void setLoginHistoryService(LoginHistoryService loginHistoryService) { - this.loginHistoryService = loginHistoryService; - } + public void setLoginHistoryRepository(LoginHistoryRepository loginHistoryRepository) { + this.loginHistoryRepository = loginHistoryRepository; + } } diff --git a/maxkey-core/src/main/java/org/maxkey/web/WebInstRequestFilter.java b/maxkey-core/src/main/java/org/maxkey/web/WebInstRequestFilter.java index 2f1a5ae9..9a29d2f6 100644 --- a/maxkey-core/src/main/java/org/maxkey/web/WebInstRequestFilter.java +++ b/maxkey-core/src/main/java/org/maxkey/web/WebInstRequestFilter.java @@ -29,7 +29,7 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils; import org.maxkey.configuration.ApplicationConfig; import org.maxkey.entity.Institutions; -import org.maxkey.persistence.db.InstitutionService; +import org.maxkey.persistence.repository.InstitutionsRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.filter.GenericFilterBean; @@ -39,7 +39,7 @@ public class WebInstRequestFilter extends GenericFilterBean { public final static String HEADER_HOST = "host"; - InstitutionService institutionService; + InstitutionsRepository institutionsRepository; ApplicationConfig applicationConfig; @@ -58,7 +58,7 @@ public class WebInstRequestFilter extends GenericFilterBean { if(host.indexOf(":")> -1 ) { host = host.split(":")[0]; } - Institutions institution =institutionService.findByDomain(host); + Institutions institution =institutionsRepository.findByDomain(host); _logger.trace("{}" ,institution); request.getSession().setAttribute(WebConstants.CURRENT_INST, institution); WebContext.setCookie((HttpServletResponse)servletResponse, host, WebConstants.INST_COOKIE_NAME, institution.getId()); @@ -66,9 +66,9 @@ public class WebInstRequestFilter extends GenericFilterBean { chain.doFilter(servletRequest, servletResponse); } - public WebInstRequestFilter(InstitutionService institutionService,ApplicationConfig applicationConfig) { + public WebInstRequestFilter(InstitutionsRepository institutionsRepository,ApplicationConfig applicationConfig) { super(); - this.institutionService = institutionService; + this.institutionsRepository = institutionsRepository; this.applicationConfig = applicationConfig; } diff --git a/maxkey-core/src/main/java/org/maxkey/web/tag/LocaleTagDirective.java b/maxkey-core/src/main/java/org/maxkey/web/tag/LocaleTagDirective.java index f255b0b1..e5dc9b3f 100644 --- a/maxkey-core/src/main/java/org/maxkey/web/tag/LocaleTagDirective.java +++ b/maxkey-core/src/main/java/org/maxkey/web/tag/LocaleTagDirective.java @@ -26,7 +26,7 @@ import java.io.IOException; import java.util.Map; import javax.servlet.http.HttpServletRequest; -import org.maxkey.persistence.db.LocalizationService; +import org.maxkey.persistence.repository.LocalizationRepository; import org.maxkey.web.WebContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,7 +51,7 @@ public class LocaleTagDirective implements TemplateDirectiveModel { private HttpServletRequest request; @Autowired - LocalizationService localizationService; + LocalizationRepository localizationService; @SuppressWarnings("rawtypes") @Override diff --git a/maxkey-gataway/src/main/java/org/gateway/GatewayApplication.java b/maxkey-gataway/src/main/java/org/gateway/GatewayApplication.java index 5dfa8c16..7a032a45 100644 --- a/maxkey-gataway/src/main/java/org/gateway/GatewayApplication.java +++ b/maxkey-gataway/src/main/java/org/gateway/GatewayApplication.java @@ -1,3 +1,20 @@ +/* + * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package org.gateway; import org.springframework.boot.SpringApplication; diff --git a/maxkey-gataway/src/main/java/org/gateway/controller/FallbackController.java b/maxkey-gataway/src/main/java/org/gateway/controller/FallbackController.java index f978f13e..f82e5567 100644 --- a/maxkey-gataway/src/main/java/org/gateway/controller/FallbackController.java +++ b/maxkey-gataway/src/main/java/org/gateway/controller/FallbackController.java @@ -1,3 +1,20 @@ +/* + * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package org.gateway.controller; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/maxkey-gataway/src/main/java/org/gateway/filter/AuthAndLogFilter.java b/maxkey-gataway/src/main/java/org/gateway/filter/AuthAndLogFilter.java index d2094bd2..92832acc 100644 --- a/maxkey-gataway/src/main/java/org/gateway/filter/AuthAndLogFilter.java +++ b/maxkey-gataway/src/main/java/org/gateway/filter/AuthAndLogFilter.java @@ -1,3 +1,20 @@ +/* + * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package org.gateway.filter; import org.slf4j.Logger; diff --git a/maxkey-gataway/src/main/java/org/gateway/route/NacosDynamicRouteService.java b/maxkey-gataway/src/main/java/org/gateway/route/NacosDynamicRouteService.java index 5b799d8c..a7e3a19a 100644 --- a/maxkey-gataway/src/main/java/org/gateway/route/NacosDynamicRouteService.java +++ b/maxkey-gataway/src/main/java/org/gateway/route/NacosDynamicRouteService.java @@ -1,3 +1,20 @@ +/* + * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + /* package org.gateway.route; diff --git a/maxkey-identitys/maxkey-identity-scim/src/main/java/org/maxkey/identity/scim/resources/ScimParameters.java b/maxkey-identitys/maxkey-identity-scim/src/main/java/org/maxkey/identity/scim/resources/ScimParameters.java index 9ec168f0..9657dcd3 100644 --- a/maxkey-identitys/maxkey-identity-scim/src/main/java/org/maxkey/identity/scim/resources/ScimParameters.java +++ b/maxkey-identitys/maxkey-identity-scim/src/main/java/org/maxkey/identity/scim/resources/ScimParameters.java @@ -1,3 +1,20 @@ +/* + * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package org.maxkey.identity.scim.resources; import org.maxkey.identity.scim.controller.ScimServiceProviderConfigController; diff --git a/maxkey-persistence/src/main/java/org/maxkey/persistence/service/UserInfoService.java b/maxkey-persistence/src/main/java/org/maxkey/persistence/service/UserInfoService.java index 5722390f..4df65e1c 100644 --- a/maxkey-persistence/src/main/java/org/maxkey/persistence/service/UserInfoService.java +++ b/maxkey-persistence/src/main/java/org/maxkey/persistence/service/UserInfoService.java @@ -24,11 +24,11 @@ import org.maxkey.crypto.password.PasswordReciprocal; import org.maxkey.entity.Accounts; import org.maxkey.entity.ChangePassword; import org.maxkey.entity.UserInfo; -import org.maxkey.persistence.db.PasswordPolicyValidator; import org.maxkey.persistence.kafka.KafkaIdentityAction; import org.maxkey.persistence.kafka.KafkaIdentityTopic; import org.maxkey.persistence.kafka.KafkaPersistService; import org.maxkey.persistence.mapper.UserInfoMapper; +import org.maxkey.persistence.repository.PasswordPolicyValidator; import org.maxkey.util.DateUtils; import org.maxkey.util.StringUtils; import org.maxkey.web.WebContext; diff --git a/maxkey-protocols/maxkey-protocol-oauth-2.0/src/main/java/org/maxkey/authz/oauth2/provider/OAuth2UserDetailsService.java b/maxkey-protocols/maxkey-protocol-oauth-2.0/src/main/java/org/maxkey/authz/oauth2/provider/OAuth2UserDetailsService.java index b3472b2f..1bc417bb 100644 --- a/maxkey-protocols/maxkey-protocol-oauth-2.0/src/main/java/org/maxkey/authz/oauth2/provider/OAuth2UserDetailsService.java +++ b/maxkey-protocols/maxkey-protocol-oauth-2.0/src/main/java/org/maxkey/authz/oauth2/provider/OAuth2UserDetailsService.java @@ -18,7 +18,7 @@ import org.maxkey.authn.AbstractAuthenticationProvider; import org.maxkey.authn.SigninPrincipal; import org.maxkey.authn.online.OnlineTicket; import org.maxkey.entity.UserInfo; -import org.maxkey.persistence.db.LoginService; +import org.maxkey.persistence.repository.LoginRepository; import org.maxkey.web.WebConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,18 +35,12 @@ public class OAuth2UserDetailsService implements UserDetailsService { private static final Logger _logger = LoggerFactory.getLogger(OAuth2UserDetailsService.class); - LoginService loginService; + LoginRepository loginRepository; - - public void setLoginService(LoginService loginService) { - this.loginService = loginService; - } - - public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { UserInfo userInfo; try { - userInfo = loginService.find(username, ""); + userInfo = loginRepository.find(username, ""); } catch (NoSuchClientException e) { throw new UsernameNotFoundException(e.getMessage(), e); } @@ -58,7 +52,7 @@ public class OAuth2UserDetailsService implements UserDetailsService { //set OnlineTicket signinPrincipal.setOnlineTicket(onlineTicket); - ArrayList grantedAuthoritys = loginService.grantAuthority(userInfo); + ArrayList grantedAuthoritys = loginRepository.grantAuthority(userInfo); signinPrincipal.setAuthenticated(true); for(GrantedAuthority administratorsAuthority : AbstractAuthenticationProvider.grantedAdministratorsAuthoritys) { @@ -74,4 +68,9 @@ public class OAuth2UserDetailsService implements UserDetailsService { return signinPrincipal; } + public void setLoginRepository(LoginRepository loginRepository) { + this.loginRepository = loginRepository; + } + + } diff --git a/maxkey-protocols/maxkey-protocol-oauth-2.0/src/main/java/org/maxkey/autoconfigure/Oauth20AutoConfiguration.java b/maxkey-protocols/maxkey-protocol-oauth-2.0/src/main/java/org/maxkey/autoconfigure/Oauth20AutoConfiguration.java index 139888b5..15e64a6c 100644 --- a/maxkey-protocols/maxkey-protocol-oauth-2.0/src/main/java/org/maxkey/autoconfigure/Oauth20AutoConfiguration.java +++ b/maxkey-protocols/maxkey-protocol-oauth-2.0/src/main/java/org/maxkey/autoconfigure/Oauth20AutoConfiguration.java @@ -43,8 +43,8 @@ import org.maxkey.configuration.oidc.OIDCProviderMetadataDetails; import org.maxkey.crypto.jose.keystore.JWKSetKeyStore; import org.maxkey.crypto.jwt.encryption.service.impl.DefaultJwtEncryptionAndDecryptionService; import org.maxkey.crypto.jwt.signer.service.impl.DefaultJwtSigningAndValidationService; -import org.maxkey.persistence.db.LoginService; import org.maxkey.persistence.redis.RedisConnectionFactory; +import org.maxkey.persistence.repository.LoginRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; @@ -303,11 +303,11 @@ public class Oauth20AutoConfiguration implements InitializingBean { @Bean(name = "oauth20UserAuthenticationManager") public ProviderManager oauth20UserAuthenticationManager( PasswordEncoder passwordEncoder, - LoginService loginService + LoginRepository loginRepository ) { OAuth2UserDetailsService userDetailsService =new OAuth2UserDetailsService(); - userDetailsService.setLoginService(loginService); + userDetailsService.setLoginRepository(loginRepository); DaoAuthenticationProvider daoAuthenticationProvider= new DaoAuthenticationProvider(); daoAuthenticationProvider.setPasswordEncoder(passwordEncoder); diff --git a/maxkey-webs/maxkey-boot-monitor/src/main/java/org/maxkey/boot/monitor/MaxKeyBootMonitor.java b/maxkey-webs/maxkey-boot-monitor/src/main/java/org/maxkey/boot/monitor/MaxKeyBootMonitor.java index dfe0e515..4f6443e2 100644 --- a/maxkey-webs/maxkey-boot-monitor/src/main/java/org/maxkey/boot/monitor/MaxKeyBootMonitor.java +++ b/maxkey-webs/maxkey-boot-monitor/src/main/java/org/maxkey/boot/monitor/MaxKeyBootMonitor.java @@ -1,3 +1,20 @@ +/* + * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package org.maxkey.boot.monitor; import org.slf4j.Logger; diff --git a/maxkey-webs/maxkey-boot-monitor/src/main/java/org/maxkey/boot/monitor/MonitorSecurityConfigurer.java b/maxkey-webs/maxkey-boot-monitor/src/main/java/org/maxkey/boot/monitor/MonitorSecurityConfigurer.java index bb7ebeac..98d57bae 100644 --- a/maxkey-webs/maxkey-boot-monitor/src/main/java/org/maxkey/boot/monitor/MonitorSecurityConfigurer.java +++ b/maxkey-webs/maxkey-boot-monitor/src/main/java/org/maxkey/boot/monitor/MonitorSecurityConfigurer.java @@ -1,3 +1,20 @@ +/* + * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package org.maxkey.boot.monitor; import org.springframework.context.annotation.Configuration; diff --git a/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/MaxKeyConfig.java b/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/MaxKeyConfig.java index bb61a3a3..616d4b89 100644 --- a/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/MaxKeyConfig.java +++ b/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/MaxKeyConfig.java @@ -45,12 +45,12 @@ import org.maxkey.password.onetimepwd.impl.sms.SmsOtpAuthnAliyun; import org.maxkey.password.onetimepwd.impl.sms.SmsOtpAuthnTencentCloud; import org.maxkey.password.onetimepwd.impl.sms.SmsOtpAuthnYunxin; import org.maxkey.password.onetimepwd.token.RedisOtpTokenStore; -import org.maxkey.persistence.db.LoginHistoryService; -import org.maxkey.persistence.db.LoginService; -import org.maxkey.persistence.db.PasswordPolicyValidator; import org.maxkey.persistence.ldap.ActiveDirectoryUtils; import org.maxkey.persistence.ldap.LdapUtils; import org.maxkey.persistence.redis.RedisConnectionFactory; +import org.maxkey.persistence.repository.LoginHistoryRepository; +import org.maxkey.persistence.repository.LoginRepository; +import org.maxkey.persistence.repository.PasswordPolicyValidator; import org.maxkey.persistence.service.UserInfoService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -152,8 +152,8 @@ public class MaxKeyConfig implements InitializingBean { public JdbcAuthenticationRealm authenticationRealm( PasswordEncoder passwordEncoder, PasswordPolicyValidator passwordPolicyValidator, - LoginService loginService, - LoginHistoryService loginHistoryService, + LoginRepository loginService, + LoginHistoryRepository loginHistoryService, AbstractRemeberMeService remeberMeService, UserInfoService userInfoService, JdbcTemplate jdbcTemplate, diff --git a/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/ForgotPasswordContorller.java b/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/ForgotPasswordContorller.java index b18dc447..ba00b8f8 100644 --- a/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/ForgotPasswordContorller.java +++ b/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/ForgotPasswordContorller.java @@ -22,7 +22,7 @@ import java.util.regex.Pattern; import org.maxkey.configuration.EmailConfig; import org.maxkey.entity.UserInfo; import org.maxkey.password.onetimepwd.AbstractOtpAuthn; -import org.maxkey.persistence.db.PasswordPolicyValidator; +import org.maxkey.persistence.repository.PasswordPolicyValidator; import org.maxkey.persistence.service.UserInfoService; import org.maxkey.web.WebConstants; import org.maxkey.web.WebContext; diff --git a/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/SafeController.java b/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/SafeController.java index 95221aa8..9134fb89 100644 --- a/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/SafeController.java +++ b/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/SafeController.java @@ -25,7 +25,7 @@ import org.maxkey.constants.ConstantsPasswordSetType; import org.maxkey.constants.ConstantsTimeInterval; import org.maxkey.crypto.password.PasswordReciprocal; import org.maxkey.entity.UserInfo; -import org.maxkey.persistence.db.PasswordPolicyValidator; +import org.maxkey.persistence.repository.PasswordPolicyValidator; import org.maxkey.persistence.service.UserInfoService; import org.maxkey.util.StringUtils; import org.maxkey.web.WebConstants; diff --git a/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/historys/contorller/LoginSessionController.java b/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/historys/contorller/LoginSessionController.java index d317ccff..1e97643f 100644 --- a/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/historys/contorller/LoginSessionController.java +++ b/maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/historys/contorller/LoginSessionController.java @@ -24,8 +24,8 @@ import org.maxkey.authn.online.OnlineTicketServices; import org.maxkey.constants.ConstantsOperateMessage; import org.maxkey.entity.HistoryLogin; import org.maxkey.entity.UserInfo; -import org.maxkey.persistence.db.LoginHistoryService; -import org.maxkey.persistence.db.LoginService; +import org.maxkey.persistence.repository.LoginHistoryRepository; +import org.maxkey.persistence.repository.LoginRepository; import org.maxkey.persistence.service.HistoryLoginService; import org.maxkey.util.DateUtils; import org.maxkey.util.StringUtils; @@ -60,10 +60,10 @@ public class LoginSessionController { @Autowired HistoryLoginService historyLoginService; @Autowired - LoginService loginService; + LoginRepository loginRepository; @Autowired - LoginHistoryService loginHistoryService; + LoginHistoryRepository loginHistoryRepository; @Autowired OnlineTicketServices onlineTicketServices; @@ -108,8 +108,8 @@ public class LoginSessionController { } UserInfo userInfo = WebContext.getUserInfo(); String lastLogoffTime = DateUtils.formatDateTime(new Date()); - loginService.updateLastLogoff(userInfo); - loginHistoryService.logoff(lastLogoffTime, sessionId); + loginRepository.updateLastLogoff(userInfo); + loginHistoryRepository.logoff(lastLogoffTime, sessionId); onlineTicketServices.remove("OT-" + sessionId); } isTerminated = true; diff --git a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/MaxKeyMgtConfig.java b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/MaxKeyMgtConfig.java index 635e1a9c..df3deaa5 100644 --- a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/MaxKeyMgtConfig.java +++ b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/MaxKeyMgtConfig.java @@ -19,9 +19,9 @@ package org.maxkey; import org.maxkey.password.onetimepwd.AbstractOtpAuthn; import org.maxkey.password.onetimepwd.impl.TimeBasedOtpAuthn; -import org.maxkey.persistence.db.LoginHistoryService; -import org.maxkey.persistence.db.LoginService; -import org.maxkey.persistence.db.PasswordPolicyValidator; +import org.maxkey.persistence.repository.LoginHistoryRepository; +import org.maxkey.persistence.repository.LoginRepository; +import org.maxkey.persistence.repository.PasswordPolicyValidator; import org.maxkey.persistence.service.UserInfoService; import org.maxkey.authn.realm.jdbc.JdbcAuthenticationRealm; import org.maxkey.authn.support.rememberme.AbstractRemeberMeService; @@ -42,8 +42,8 @@ public class MaxKeyMgtConfig implements InitializingBean { public JdbcAuthenticationRealm authenticationRealm( PasswordEncoder passwordEncoder, PasswordPolicyValidator passwordPolicyValidator, - LoginService loginService, - LoginHistoryService loginHistoryService, + LoginRepository loginRepository, + LoginHistoryRepository loginHistoryRepository, AbstractRemeberMeService remeberMeService, UserInfoService userInfoService, JdbcTemplate jdbcTemplate) { @@ -51,8 +51,8 @@ public class MaxKeyMgtConfig implements InitializingBean { JdbcAuthenticationRealm authenticationRealm = new JdbcAuthenticationRealm( passwordEncoder, passwordPolicyValidator, - loginService, - loginHistoryService, + loginRepository, + loginHistoryRepository, remeberMeService, userInfoService, jdbcTemplate); diff --git a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/contorller/LocalizationController.java b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/contorller/LocalizationController.java index a07fc2cf..270cca6d 100644 --- a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/contorller/LocalizationController.java +++ b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/contorller/LocalizationController.java @@ -20,7 +20,7 @@ package org.maxkey.web.contorller; import org.apache.commons.lang3.StringUtils; import org.maxkey.constants.ConstantsOperateMessage; import org.maxkey.entity.Localization; -import org.maxkey.persistence.db.LocalizationService; +import org.maxkey.persistence.repository.LocalizationRepository; import org.maxkey.web.WebContext; import org.maxkey.web.message.Message; import org.maxkey.web.message.MessageType; @@ -43,7 +43,7 @@ public class LocalizationController { final static Logger _logger = LoggerFactory.getLogger(LocalizationController.class); @Autowired - private LocalizationService localizationService; + private LocalizationRepository localizationRepository; /** * 读取 @@ -51,7 +51,7 @@ public class LocalizationController { */ @RequestMapping(value={"/forward/{property}"}) public ModelAndView forward(@PathVariable("property") String property){ - Localization localization = localizationService.get(property,WebContext.getUserInfo().getInstId()); + Localization localization = localizationRepository.get(property,WebContext.getUserInfo().getInstId()); if(localization == null )localization = new Localization(); localization.setProperty(property); localization.setInstId(WebContext.getUserInfo().getInstId()); @@ -70,13 +70,13 @@ public class LocalizationController { localization.setInstId(WebContext.getUserInfo().getInstId()); if(StringUtils.isBlank(localization.getId())){ localization.setId(localization.generateId()); - if(localizationService.insert(localization)) { + if(localizationRepository.insert(localization)) { return new Message(WebContext.getI18nValue(ConstantsOperateMessage.UPDATE_SUCCESS),MessageType.success); } else { return new Message(WebContext.getI18nValue(ConstantsOperateMessage.UPDATE_ERROR),MessageType.error); } }else { - if(localizationService.update(localization)) { + if(localizationRepository.update(localization)) { return new Message(WebContext.getI18nValue(ConstantsOperateMessage.UPDATE_SUCCESS),MessageType.success); } else { return new Message(WebContext.getI18nValue(ConstantsOperateMessage.UPDATE_ERROR),MessageType.error); diff --git a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/historys/contorller/LoginSessionController.java b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/historys/contorller/LoginSessionController.java index bd45f745..e06b9e29 100644 --- a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/historys/contorller/LoginSessionController.java +++ b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/historys/contorller/LoginSessionController.java @@ -24,8 +24,8 @@ import org.maxkey.authn.online.OnlineTicketServices; import org.maxkey.constants.ConstantsOperateMessage; import org.maxkey.entity.HistoryLogin; import org.maxkey.entity.UserInfo; -import org.maxkey.persistence.db.LoginHistoryService; -import org.maxkey.persistence.db.LoginService; +import org.maxkey.persistence.repository.LoginHistoryRepository; +import org.maxkey.persistence.repository.LoginRepository; import org.maxkey.persistence.service.HistoryLoginService; import org.maxkey.util.DateUtils; import org.maxkey.util.StringUtils; @@ -60,10 +60,10 @@ public class LoginSessionController { @Autowired HistoryLoginService historyLoginService; @Autowired - LoginService loginService; + LoginRepository loginRepository; @Autowired - LoginHistoryService loginHistoryService; + LoginHistoryRepository loginHistoryRepository; @Autowired OnlineTicketServices onlineTicketServices; @@ -106,8 +106,8 @@ public class LoginSessionController { } UserInfo userInfo = WebContext.getUserInfo(); String lastLogoffTime = DateUtils.formatDateTime(new Date()); - loginService.updateLastLogoff(userInfo); - loginHistoryService.logoff(lastLogoffTime, sessionId); + loginRepository.updateLastLogoff(userInfo); + loginHistoryRepository.logoff(lastLogoffTime, sessionId); onlineTicketServices.remove("OT-" + sessionId); } isTerminated = true; -- GitLab