Browse Source

登录整合优化

shimingxy 6 months ago
parent
commit
0d18f5d7df
21 changed files with 160 additions and 84 deletions
  1. 1 1
      maxkey-authentications/maxkey-authentication-provider-mgt/src/main/java/org/dromara/maxkey/authn/provider/impl/MobileAuthenticationProvider.java
  2. 2 2
      maxkey-authentications/maxkey-authentication-provider-mgt/src/main/java/org/dromara/maxkey/authn/provider/impl/NormalAuthenticationProvider.java
  3. 2 2
      maxkey-authentications/maxkey-authentication-provider-mgt/src/main/java/org/dromara/maxkey/authn/provider/impl/TrustedAuthenticationProvider.java
  4. 9 9
      maxkey-authentications/maxkey-authentication-provider-mgt/src/main/java/org/dromara/maxkey/authn/realm/AbstractAuthenticationRealm.java
  5. 6 6
      maxkey-authentications/maxkey-authentication-provider-mgt/src/main/java/org/dromara/maxkey/authn/realm/jdbc/JdbcAuthenticationRealm.java
  6. 0 8
      maxkey-authentications/maxkey-authentication-provider-mgt/src/main/java/org/dromara/maxkey/autoconfigure/AuthnProviderAutoConfiguration.java
  7. 2 2
      maxkey-authentications/maxkey-authentication-provider/src/main/java/org/dromara/maxkey/authn/provider/impl/AppAuthenticationProvider.java
  8. 2 2
      maxkey-authentications/maxkey-authentication-provider/src/main/java/org/dromara/maxkey/authn/provider/impl/MfaAuthenticationProvider.java
  9. 1 1
      maxkey-authentications/maxkey-authentication-provider/src/main/java/org/dromara/maxkey/authn/provider/impl/MobileAuthenticationProvider.java
  10. 2 2
      maxkey-authentications/maxkey-authentication-provider/src/main/java/org/dromara/maxkey/authn/provider/impl/NormalAuthenticationProvider.java
  11. 2 2
      maxkey-authentications/maxkey-authentication-provider/src/main/java/org/dromara/maxkey/authn/provider/impl/TrustedAuthenticationProvider.java
  12. 9 9
      maxkey-authentications/maxkey-authentication-provider/src/main/java/org/dromara/maxkey/authn/realm/AbstractAuthenticationRealm.java
  13. 6 6
      maxkey-authentications/maxkey-authentication-provider/src/main/java/org/dromara/maxkey/authn/realm/jdbc/JdbcAuthenticationRealm.java
  14. 1 6
      maxkey-authentications/maxkey-authentication-provider/src/main/java/org/dromara/maxkey/autoconfigure/AuthnProviderAutoConfiguration.java
  15. 89 0
      maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/LoginService.java
  16. 13 13
      maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/LoginServiceImpl.java
  17. 3 3
      maxkey-protocols/maxkey-protocol-oauth-2.0/src/main/java/org/dromara/maxkey/authz/oauth2/provider/OAuth2UserDetailsService.java
  18. 2 2
      maxkey-protocols/maxkey-protocol-oauth-2.0/src/main/java/org/dromara/maxkey/autoconfigure/Oauth20AutoConfiguration.java
  19. 2 2
      maxkey-webs/maxkey-web-maxkey/src/main/java/org/dromara/maxkey/autoconfigure/MaxKeyConfig.java
  20. 3 3
      maxkey-webs/maxkey-web-mgt/src/main/java/org/dromara/maxkey/autoconfigure/MaxKeyMgtConfig.java
  21. 3 3
      maxkey-webs/maxkey-web-openapi/src/main/java/org/dromara/maxkey/autoconfigure/MaxKeyOpenApiConfig.java

+ 1 - 1
maxkey-authentications/maxkey-authentication-provider-mgt/src/main/java/org/dromara/maxkey/authn/provider/impl/MobileAuthenticationProvider.java

@@ -97,7 +97,7 @@ public class MobileAuthenticationProvider extends AbstractAuthenticationProvider
             mobileCaptchaValid(loginCredential.getPassword(),userInfo);
 
             //apply PasswordSetType and resetBadPasswordCount
-            authenticationRealm.getLoginRepository().applyPasswordPolicy(userInfo);
+            authenticationRealm.getLoginService().applyPasswordPolicy(userInfo);
 
             authenticationToken = createOnlineTicket(loginCredential,userInfo);
             // user authenticated

+ 2 - 2
maxkey-authentications/maxkey-authentication-provider-mgt/src/main/java/org/dromara/maxkey/authn/provider/impl/NormalAuthenticationProvider.java

@@ -87,7 +87,7 @@ public class NormalAuthenticationProvider extends AbstractAuthenticationProvider
 	        isUserExist(loginCredential , userInfo);
 	        
 	        //Validate PasswordPolicy
-	        authenticationRealm.getLoginRepository().passwordPolicyValid(userInfo);
+	        authenticationRealm.getLoginService().passwordPolicyValid(userInfo);
 	        
 	        statusValid(loginCredential , userInfo);
 	        
@@ -95,7 +95,7 @@ public class NormalAuthenticationProvider extends AbstractAuthenticationProvider
 	        authenticationRealm.passwordMatches(userInfo, loginCredential.getPassword());
 
 	        //apply PasswordSetType and resetBadPasswordCount
-	        authenticationRealm.getLoginRepository().applyPasswordPolicy(userInfo);
+	        authenticationRealm.getLoginService().applyPasswordPolicy(userInfo);
 	        
 	        authenticationToken = createOnlineTicket(loginCredential,userInfo);
 	        // user authenticated

+ 2 - 2
maxkey-authentications/maxkey-authentication-provider-mgt/src/main/java/org/dromara/maxkey/authn/provider/impl/TrustedAuthenticationProvider.java

@@ -61,9 +61,9 @@ public class TrustedAuthenticationProvider extends AbstractAuthenticationProvide
         statusValid(loginCredential , loadeduserInfo);
         if (loadeduserInfo != null) {
             //Validate PasswordPolicy
-            authenticationRealm.getLoginRepository().passwordPolicyValid(loadeduserInfo);
+            authenticationRealm.getLoginService().passwordPolicyValid(loadeduserInfo);
             //apply PasswordSetType and resetBadPasswordCount
-            authenticationRealm.getLoginRepository().applyPasswordPolicy(loadeduserInfo);
+            authenticationRealm.getLoginService().applyPasswordPolicy(loadeduserInfo);
             Authentication authentication = createOnlineTicket(loginCredential,loadeduserInfo);
             
             authenticationRealm.insertLoginHistory( loadeduserInfo, 

+ 9 - 9
maxkey-authentications/maxkey-authentication-provider-mgt/src/main/java/org/dromara/maxkey/authn/realm/AbstractAuthenticationRealm.java

@@ -28,8 +28,8 @@ import org.dromara.maxkey.entity.idm.Groups;
 import org.dromara.maxkey.entity.idm.UserInfo;
 import org.dromara.maxkey.ip2location.IpLocationParser;
 import org.dromara.maxkey.ip2location.Region;
-import org.dromara.maxkey.persistence.repository.LoginRepository;
 import org.dromara.maxkey.persistence.service.HistoryLoginService;
+import org.dromara.maxkey.persistence.service.LoginService;
 import org.dromara.maxkey.persistence.service.PasswordPolicyValidatorService;
 import org.dromara.maxkey.persistence.service.UserInfoService;
 import org.dromara.maxkey.web.WebConstants;
@@ -52,7 +52,7 @@ public abstract class AbstractAuthenticationRealm {
     
     protected PasswordPolicyValidatorService passwordPolicyValidatorService;
     
-    protected LoginRepository loginRepository;
+    protected LoginService loginService;
 
     protected HistoryLoginService historyLoginService;
     
@@ -78,18 +78,18 @@ public abstract class AbstractAuthenticationRealm {
         return passwordPolicyValidatorService;
     }
 
-    public LoginRepository getLoginRepository() {
-        return loginRepository;
+    public LoginService getLoginService() {
+        return loginService;
     }
 
     public UserInfo loadUserInfo(String username, String password) {
-        return loginRepository.find(username, password);
+        return loginService.find(username, password);
     }
 
     public abstract boolean passwordMatches(UserInfo userInfo, String password);
     
     public List<Groups> queryGroups(UserInfo userInfo) {
-       return loginRepository.queryGroups(userInfo);
+       return loginService.queryGroups(userInfo);
     }
 
     /**
@@ -99,7 +99,7 @@ public abstract class AbstractAuthenticationRealm {
      * @return ArrayList<GrantedAuthority>
      */
     public List<GrantedAuthority> grantAuthority(UserInfo userInfo) {
-        return loginRepository.grantAuthority(userInfo);
+        return loginService.grantAuthority(userInfo);
     }
     
     /**
@@ -109,7 +109,7 @@ public abstract class AbstractAuthenticationRealm {
      * @return ArrayList<GrantedAuthority Apps>
      */
     public List<GrantedAuthority> queryAuthorizedApps(List<GrantedAuthority> grantedAuthoritys) {
-        return loginRepository.queryAuthorizedApps(grantedAuthoritys);
+        return loginService.queryAuthorizedApps(grantedAuthoritys);
     }
 
     /**
@@ -160,7 +160,7 @@ public abstract class AbstractAuthenticationRealm {
         }
         historyLoginService.login(historyLogin);
         
-        loginRepository.updateLastLogin(userInfo);
+        loginService.updateLastLogin(userInfo);
 
         return true;
     }

+ 6 - 6
maxkey-authentications/maxkey-authentication-provider-mgt/src/main/java/org/dromara/maxkey/authn/realm/jdbc/JdbcAuthenticationRealm.java

@@ -26,8 +26,8 @@ import org.dromara.maxkey.entity.ChangePassword;
 import org.dromara.maxkey.entity.cnf.CnfPasswordPolicy;
 import org.dromara.maxkey.entity.idm.UserInfo;
 import org.dromara.maxkey.ip2location.IpLocationParser;
-import org.dromara.maxkey.persistence.repository.LoginRepository;
 import org.dromara.maxkey.persistence.service.HistoryLoginService;
+import org.dromara.maxkey.persistence.service.LoginService;
 import org.dromara.maxkey.persistence.service.PasswordPolicyValidatorService;
 import org.dromara.maxkey.persistence.service.UserInfoService;
 import org.dromara.maxkey.web.WebConstants;
@@ -59,7 +59,7 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
     public JdbcAuthenticationRealm(
     		PasswordEncoder passwordEncoder,
     		PasswordPolicyValidatorService passwordPolicyValidatorService,
-    		LoginRepository loginRepository,
+    		LoginService loginService,
     		HistoryLoginService historyLoginService,
     		UserInfoService userInfoService,
     		IpLocationParser ipLocationParser,
@@ -67,7 +67,7 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
     	
     	this.passwordEncoder =passwordEncoder;
     	this.passwordPolicyValidatorService=passwordPolicyValidatorService;
-    	this.loginRepository = loginRepository;
+    	this.loginService = loginService;
     	this.historyLoginService = historyLoginService;
     	this.userInfoService = userInfoService;
     	this.ipLocationParser = ipLocationParser;
@@ -77,7 +77,7 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
     public JdbcAuthenticationRealm(
     		PasswordEncoder passwordEncoder,
     		PasswordPolicyValidatorService passwordPolicyValidatorService,
-    		LoginRepository loginRepository,
+    		LoginService loginService,
     		HistoryLoginService historyLoginService,
     		UserInfoService userInfoService,
     		IpLocationParser ipLocationParser,
@@ -85,7 +85,7 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
     	    LdapAuthenticationRealmService ldapAuthenticationRealmService) {
 		this.passwordEncoder = passwordEncoder;
 		this.passwordPolicyValidatorService = passwordPolicyValidatorService;
-		this.loginRepository = loginRepository;
+		this.loginService = loginService;
 		this.historyLoginService = historyLoginService;
 		this.userInfoService = userInfoService;
 		this.ipLocationParser = ipLocationParser;
@@ -126,7 +126,7 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
         }
         _logger.debug("passwordvalid : {}" , passwordMatches);
         if (!passwordMatches) {
-        	loginRepository.plusBadPasswordCount(userInfo);
+        	loginService.plusBadPasswordCount(userInfo);
             insertLoginHistory(userInfo, ConstsLoginType.LOCAL, "", "xe00000004", WebConstants.LOGIN_RESULT.PASSWORD_ERROE);
             CnfPasswordPolicy passwordPolicy = passwordPolicyValidatorService.getPasswordPolicy();
             if(userInfo.getBadPasswordCount()>=(passwordPolicy.getAttempts()/2)) {

+ 0 - 8
maxkey-authentications/maxkey-authentication-provider-mgt/src/main/java/org/dromara/maxkey/autoconfigure/AuthnProviderAutoConfiguration.java

@@ -25,17 +25,14 @@ import org.dromara.maxkey.authn.realm.AbstractAuthenticationRealm;
 import org.dromara.maxkey.authn.session.SessionManager;
 import org.dromara.maxkey.configuration.ApplicationConfig;
 import org.dromara.maxkey.password.sms.SmsOtpAuthnService;
-import org.dromara.maxkey.persistence.repository.LoginRepository;
 import org.dromara.maxkey.persistence.service.CnfPasswordPolicyService;
 import org.dromara.maxkey.persistence.service.PasswordPolicyValidatorService;
-import org.dromara.maxkey.persistence.service.UserInfoService;
 import org.dromara.maxkey.persistence.service.impl.PasswordPolicyValidatorServiceImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.boot.autoconfigure.AutoConfiguration;
 import org.springframework.context.MessageSource;
 import org.springframework.context.annotation.Bean;
-import org.springframework.jdbc.core.JdbcTemplate;
 
 
 @AutoConfiguration
@@ -108,9 +105,4 @@ public class AuthnProviderAutoConfiguration {
         return new PasswordPolicyValidatorServiceImpl(cnfPasswordPolicyService,messageSource);
     }
 
-    @Bean
-    LoginRepository loginRepository(UserInfoService userInfoService,CnfPasswordPolicyService cnfPasswordPolicyService,JdbcTemplate jdbcTemplate) {
-        return new LoginRepository(userInfoService,cnfPasswordPolicyService,jdbcTemplate);
-    }
-
 }

+ 2 - 2
maxkey-authentications/maxkey-authentication-provider/src/main/java/org/dromara/maxkey/authn/provider/impl/AppAuthenticationProvider.java

@@ -84,7 +84,7 @@ public class AppAuthenticationProvider extends AbstractAuthenticationProvider {
             UserInfo userInfo = loadUserInfo(loginCredential.getUsername(), loginCredential.getPassword());
 
             //Validate PasswordPolicy
-            authenticationRealm.getLoginRepository().passwordPolicyValid(userInfo);
+            authenticationRealm.getLoginService().passwordPolicyValid(userInfo);
 
             statusValid(loginCredential, userInfo);
 
@@ -92,7 +92,7 @@ public class AppAuthenticationProvider extends AbstractAuthenticationProvider {
             authenticationRealm.passwordMatches(userInfo, loginCredential.getPassword());
 
             //apply PasswordSetType and resetBadPasswordCount
-            authenticationRealm.getLoginRepository().applyPasswordPolicy(userInfo);
+            authenticationRealm.getLoginService().applyPasswordPolicy(userInfo);
 
             authenticationToken = createOnlineTicket(loginCredential, userInfo);
             // user authenticated

+ 2 - 2
maxkey-authentications/maxkey-authentication-provider/src/main/java/org/dromara/maxkey/authn/provider/impl/MfaAuthenticationProvider.java

@@ -89,13 +89,13 @@ public class MfaAuthenticationProvider extends AbstractAuthenticationProvider {
 	        mfacaptchaValid(loginCredential.getOtpCaptcha(),userInfo);
 	        
 	        //Validate PasswordPolicy
-	        authenticationRealm.getLoginRepository().passwordPolicyValid(userInfo);
+	        authenticationRealm.getLoginService().passwordPolicyValid(userInfo);
 	             
 	        //Match password 
 	        authenticationRealm.passwordMatches(userInfo, loginCredential.getPassword());
 
 	        //apply PasswordSetType and resetBadPasswordCount
-	        authenticationRealm.getLoginRepository().applyPasswordPolicy(userInfo);
+	        authenticationRealm.getLoginService().applyPasswordPolicy(userInfo);
 	        
 	        authenticationToken = createOnlineTicket(loginCredential,userInfo);
 	        // user authenticated

+ 1 - 1
maxkey-authentications/maxkey-authentication-provider/src/main/java/org/dromara/maxkey/authn/provider/impl/MobileAuthenticationProvider.java

@@ -97,7 +97,7 @@ public class MobileAuthenticationProvider extends AbstractAuthenticationProvider
             mobileCaptchaValid(loginCredential.getPassword(),userInfo);
 
             //apply PasswordSetType and resetBadPasswordCount
-            authenticationRealm.getLoginRepository().applyPasswordPolicy(userInfo);
+            authenticationRealm.getLoginService().applyPasswordPolicy(userInfo);
 
             authenticationToken = createOnlineTicket(loginCredential,userInfo);
             // user authenticated

+ 2 - 2
maxkey-authentications/maxkey-authentication-provider/src/main/java/org/dromara/maxkey/authn/provider/impl/NormalAuthenticationProvider.java

@@ -87,7 +87,7 @@ public class NormalAuthenticationProvider extends AbstractAuthenticationProvider
 	        isUserExist(loginCredential , userInfo);
 	        
 	        //Validate PasswordPolicy
-	        authenticationRealm.getLoginRepository().passwordPolicyValid(userInfo);
+	        authenticationRealm.getLoginService().passwordPolicyValid(userInfo);
 	        
 	        statusValid(loginCredential , userInfo);
 	        
@@ -95,7 +95,7 @@ public class NormalAuthenticationProvider extends AbstractAuthenticationProvider
 	        authenticationRealm.passwordMatches(userInfo, loginCredential.getPassword());
 
 	        //apply PasswordSetType and resetBadPasswordCount
-	        authenticationRealm.getLoginRepository().applyPasswordPolicy(userInfo);
+	        authenticationRealm.getLoginService().applyPasswordPolicy(userInfo);
 	        
 	        authenticationToken = createOnlineTicket(loginCredential,userInfo);
 	        // user authenticated

+ 2 - 2
maxkey-authentications/maxkey-authentication-provider/src/main/java/org/dromara/maxkey/authn/provider/impl/TrustedAuthenticationProvider.java

@@ -61,9 +61,9 @@ public class TrustedAuthenticationProvider extends AbstractAuthenticationProvide
         statusValid(loginCredential , loadeduserInfo);
         if (loadeduserInfo != null) {
             //Validate PasswordPolicy
-            authenticationRealm.getLoginRepository().passwordPolicyValid(loadeduserInfo);
+            authenticationRealm.getLoginService().passwordPolicyValid(loadeduserInfo);
             //apply PasswordSetType and resetBadPasswordCount
-            authenticationRealm.getLoginRepository().applyPasswordPolicy(loadeduserInfo);
+            authenticationRealm.getLoginService().applyPasswordPolicy(loadeduserInfo);
             Authentication authentication = createOnlineTicket(loginCredential,loadeduserInfo);
             
             authenticationRealm.insertLoginHistory( loadeduserInfo, 

+ 9 - 9
maxkey-authentications/maxkey-authentication-provider/src/main/java/org/dromara/maxkey/authn/realm/AbstractAuthenticationRealm.java

@@ -28,8 +28,8 @@ import org.dromara.maxkey.entity.idm.Groups;
 import org.dromara.maxkey.entity.idm.UserInfo;
 import org.dromara.maxkey.ip2location.IpLocationParser;
 import org.dromara.maxkey.ip2location.Region;
-import org.dromara.maxkey.persistence.repository.LoginRepository;
 import org.dromara.maxkey.persistence.service.HistoryLoginService;
+import org.dromara.maxkey.persistence.service.LoginService;
 import org.dromara.maxkey.persistence.service.PasswordPolicyValidatorService;
 import org.dromara.maxkey.persistence.service.UserInfoService;
 import org.dromara.maxkey.web.WebConstants;
@@ -52,7 +52,7 @@ public abstract class AbstractAuthenticationRealm {
     
     protected PasswordPolicyValidatorService passwordPolicyValidatorService;
     
-    protected LoginRepository loginRepository;
+    protected LoginService loginService;
 
     protected HistoryLoginService historyLoginService;
     
@@ -78,18 +78,18 @@ public abstract class AbstractAuthenticationRealm {
         return passwordPolicyValidatorService;
     }
 
-    public LoginRepository getLoginRepository() {
-        return loginRepository;
+    public LoginService getLoginService() {
+        return loginService;
     }
 
     public UserInfo loadUserInfo(String username, String password) {
-        return loginRepository.find(username, password);
+        return loginService.find(username, password);
     }
 
     public abstract boolean passwordMatches(UserInfo userInfo, String password);
     
     public List<Groups> queryGroups(UserInfo userInfo) {
-       return loginRepository.queryGroups(userInfo);
+       return loginService.queryGroups(userInfo);
     }
 
     /**
@@ -99,7 +99,7 @@ public abstract class AbstractAuthenticationRealm {
      * @return ArrayList<GrantedAuthority>
      */
     public List<GrantedAuthority> grantAuthority(UserInfo userInfo) {
-        return loginRepository.grantAuthority(userInfo);
+        return loginService.grantAuthority(userInfo);
     }
     
     /**
@@ -109,7 +109,7 @@ public abstract class AbstractAuthenticationRealm {
      * @return ArrayList<GrantedAuthority Apps>
      */
     public List<GrantedAuthority> queryAuthorizedApps(List<GrantedAuthority> grantedAuthoritys) {
-        return loginRepository.queryAuthorizedApps(grantedAuthoritys);
+        return loginService.queryAuthorizedApps(grantedAuthoritys);
     }
 
     /**
@@ -160,7 +160,7 @@ public abstract class AbstractAuthenticationRealm {
         }
         historyLoginService.login(historyLogin);
         
-        loginRepository.updateLastLogin(userInfo);
+        loginService.updateLastLogin(userInfo);
 
         return true;
     }

+ 6 - 6
maxkey-authentications/maxkey-authentication-provider/src/main/java/org/dromara/maxkey/authn/realm/jdbc/JdbcAuthenticationRealm.java

@@ -26,8 +26,8 @@ import org.dromara.maxkey.entity.ChangePassword;
 import org.dromara.maxkey.entity.cnf.CnfPasswordPolicy;
 import org.dromara.maxkey.entity.idm.UserInfo;
 import org.dromara.maxkey.ip2location.IpLocationParser;
-import org.dromara.maxkey.persistence.repository.LoginRepository;
 import org.dromara.maxkey.persistence.service.HistoryLoginService;
+import org.dromara.maxkey.persistence.service.LoginService;
 import org.dromara.maxkey.persistence.service.PasswordPolicyValidatorService;
 import org.dromara.maxkey.persistence.service.UserInfoService;
 import org.dromara.maxkey.web.WebConstants;
@@ -59,7 +59,7 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
     public JdbcAuthenticationRealm(
     		PasswordEncoder passwordEncoder,
     		PasswordPolicyValidatorService passwordPolicyValidatorService,
-    		LoginRepository loginRepository,
+    		LoginService loginService,
     		HistoryLoginService historyLoginService,
     		UserInfoService userInfoService,
     		IpLocationParser ipLocationParser,
@@ -67,7 +67,7 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
     	
     	this.passwordEncoder =passwordEncoder;
     	this.passwordPolicyValidatorService=passwordPolicyValidatorService;
-    	this.loginRepository = loginRepository;
+    	this.loginService = loginService;
     	this.historyLoginService = historyLoginService;
     	this.userInfoService = userInfoService;
     	this.ipLocationParser = ipLocationParser;
@@ -77,7 +77,7 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
     public JdbcAuthenticationRealm(
     		PasswordEncoder passwordEncoder,
     		PasswordPolicyValidatorService passwordPolicyValidatorService,
-    		LoginRepository loginRepository,
+    		LoginService loginService,
     		HistoryLoginService historyLoginService,
     		UserInfoService userInfoService,
     		IpLocationParser ipLocationParser,
@@ -85,7 +85,7 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
     	    LdapAuthenticationRealmService ldapAuthenticationRealmService) {
 		this.passwordEncoder = passwordEncoder;
 		this.passwordPolicyValidatorService = passwordPolicyValidatorService;
-		this.loginRepository = loginRepository;
+		this.loginService = loginService;
 		this.historyLoginService = historyLoginService;
 		this.userInfoService = userInfoService;
 		this.ipLocationParser = ipLocationParser;
@@ -126,7 +126,7 @@ public class JdbcAuthenticationRealm extends AbstractAuthenticationRealm {
         }
         _logger.debug("passwordvalid : {}" , passwordMatches);
         if (!passwordMatches) {
-        	loginRepository.plusBadPasswordCount(userInfo);
+        	loginService.plusBadPasswordCount(userInfo);
             insertLoginHistory(userInfo, ConstsLoginType.LOCAL, "", "xe00000004", WebConstants.LOGIN_RESULT.PASSWORD_ERROE);
             CnfPasswordPolicy passwordPolicy = passwordPolicyValidatorService.getPasswordPolicy();
             if(userInfo.getBadPasswordCount()>=(passwordPolicy.getAttempts()/2)) {

+ 1 - 6
maxkey-authentications/maxkey-authentication-provider/src/main/java/org/dromara/maxkey/autoconfigure/AuthnProviderAutoConfiguration.java

@@ -27,8 +27,8 @@ import org.dromara.maxkey.authn.support.rememberme.AbstractRemeberMeManager;
 import org.dromara.maxkey.authn.support.rememberme.JdbcRemeberMeManager;
 import org.dromara.maxkey.configuration.ApplicationConfig;
 import org.dromara.maxkey.password.sms.SmsOtpAuthnService;
-import org.dromara.maxkey.persistence.repository.LoginRepository;
 import org.dromara.maxkey.persistence.service.CnfPasswordPolicyService;
+import org.dromara.maxkey.persistence.service.LoginService;
 import org.dromara.maxkey.persistence.service.PasswordPolicyValidatorService;
 import org.dromara.maxkey.persistence.service.UserInfoService;
 import org.dromara.maxkey.persistence.service.impl.PasswordPolicyValidatorServiceImpl;
@@ -142,11 +142,6 @@ public class AuthnProviderAutoConfiguration {
         return new PasswordPolicyValidatorServiceImpl(cnfPasswordPolicyService,messageSource);
     }
 
-    @Bean
-    LoginRepository loginRepository(UserInfoService userInfoService,CnfPasswordPolicyService cnfPasswordPolicyService,JdbcTemplate jdbcTemplate) {
-        return new LoginRepository(userInfoService,cnfPasswordPolicyService,jdbcTemplate);
-    }
-
     /**
      * remeberMeService .
      * @return

+ 89 - 0
maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/LoginService.java

@@ -0,0 +1,89 @@
+/*
+ * Copyright [2024] [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.dromara.maxkey.persistence.service;
+
+import java.util.List;
+
+import org.dromara.maxkey.entity.idm.Groups;
+import org.dromara.maxkey.entity.idm.UserInfo;
+import org.springframework.security.core.GrantedAuthority;
+
+public interface LoginService {
+    
+    public UserInfo find(String username, String password);
+
+    public List<UserInfo> findByUsername(String username, String password);
+
+    public List<UserInfo> findByUsernameOrMobile(String username, String password);
+
+    public List<UserInfo> findByUsernameOrMobileOrEmail(String username, String password);
+
+
+    
+    /**
+     * dynamic passwordPolicy Valid for user login.
+     * @param userInfo
+     * @return boolean
+     */
+    public boolean passwordPolicyValid(UserInfo userInfo) ;
+    
+    public void applyPasswordPolicy(UserInfo userInfo) ;
+    
+    /**
+     * lockUser
+     * 
+     * @param userInfo
+     */
+    public void lockUser(UserInfo userInfo) ;
+    
+
+    /**
+     * unlockUser
+     * 
+     * @param userInfo
+     */
+    public void unlockUser(UserInfo userInfo);
+
+    /**
+    * reset BadPasswordCount And Lockout
+     * 
+     * @param userInfo
+     */
+    public void resetAttempts(UserInfo userInfo);
+
+    public void plusBadPasswordCount(UserInfo userInfo) ;
+    
+    public void resetBadPasswordCount(UserInfo userInfo);
+
+    public List<GrantedAuthority> queryAuthorizedApps(List<GrantedAuthority> grantedAuthoritys);
+
+    public List<Groups> queryGroups(UserInfo userInfo) ;
+
+    /**
+     * grant Authority by userinfo
+     *
+     * @param userInfo
+     * @return ArrayList<GrantedAuthority>
+     */
+    public List<GrantedAuthority> grantAuthority(UserInfo userInfo) ;
+
+
+    public void updateLastLogin(UserInfo userInfo) ;
+}
+
+

+ 13 - 13
maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/repository/LoginRepository.java → maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/impl/LoginServiceImpl.java

@@ -1,5 +1,5 @@
 /*
- * Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
+ * Copyright [2024] [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.
@@ -15,13 +15,12 @@
  */
 
 
-package org.dromara.maxkey.persistence.repository;
+package org.dromara.maxkey.persistence.service.impl;
 
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Types;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
 import org.apache.commons.collections4.CollectionUtils;
@@ -33,6 +32,7 @@ import org.dromara.maxkey.entity.cnf.CnfPasswordPolicy;
 import org.dromara.maxkey.entity.idm.Groups;
 import org.dromara.maxkey.entity.idm.UserInfo;
 import org.dromara.maxkey.persistence.service.CnfPasswordPolicyService;
+import org.dromara.maxkey.persistence.service.LoginService;
 import org.dromara.maxkey.persistence.service.UserInfoService;
 import org.dromara.maxkey.web.WebConstants;
 import org.dromara.maxkey.web.WebContext;
@@ -40,14 +40,17 @@ import org.joda.time.DateTime;
 import org.joda.time.Duration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.security.authentication.BadCredentialsException;
 import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.authority.SimpleGrantedAuthority;
+import org.springframework.stereotype.Repository;
 
-public class LoginRepository {
-    private static final Logger _logger = LoggerFactory.getLogger(LoginRepository.class);
+@Repository
+public class LoginServiceImpl  implements LoginService{
+    private static final Logger _logger = LoggerFactory.getLogger(LoginServiceImpl.class);
 
     private static final String LOGIN_USERINFO_UPDATE_STATEMENT = "update mxk_userinfo set lastlogintime = ?  , lastloginip = ? , logincount = ?, online = "
             + UserInfo.ONLINE.ONLINE + "  where id = ?";
@@ -62,10 +65,13 @@ public class LoginRepository {
 
     private static final String DEFAULT_MYAPPS_SELECT_STATEMENT = "select distinct app.id,app.appname from mxk_apps app,mxk_access gp,mxk_groups g  where app.id=gp.appid and app.status = 1 and gp.groupid=g.id and g.id in(%s)";
 
-    protected JdbcTemplate jdbcTemplate;
+    @Autowired
+    JdbcTemplate jdbcTemplate;
     
+    @Autowired
     UserInfoService userInfoService;
     
+    @Autowired
     CnfPasswordPolicyService cnfPasswordPolicyService;
 
     /**
@@ -73,16 +79,10 @@ public class LoginRepository {
      */
     public  static  int LOGIN_ATTRIBUTE_TYPE = 2;
 
-    public LoginRepository(){
+    public LoginServiceImpl(){
 
     }
 
-    public LoginRepository(UserInfoService userInfoService,CnfPasswordPolicyService cnfPasswordPolicyService,JdbcTemplate jdbcTemplate){
-        this.jdbcTemplate=jdbcTemplate;
-        this.userInfoService = userInfoService;
-        this.cnfPasswordPolicyService = cnfPasswordPolicyService;
-    }
-
     public UserInfo find(String username, String password) {
         List<UserInfo> listUserInfo = null ;
         if( LOGIN_ATTRIBUTE_TYPE == 1) {

+ 3 - 3
maxkey-protocols/maxkey-protocol-oauth-2.0/src/main/java/org/dromara/maxkey/authz/oauth2/provider/OAuth2UserDetailsService.java

@@ -18,7 +18,7 @@ import org.dromara.maxkey.authn.SignPrincipal;
 import org.dromara.maxkey.authn.provider.AbstractAuthenticationProvider;
 import org.dromara.maxkey.authn.session.Session;
 import org.dromara.maxkey.entity.idm.UserInfo;
-import org.dromara.maxkey.persistence.repository.LoginRepository;
+import org.dromara.maxkey.persistence.service.LoginService;
 import org.dromara.maxkey.web.WebConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -35,7 +35,7 @@ public class OAuth2UserDetailsService implements UserDetailsService {
 	 private static final Logger _logger = 
 	            LoggerFactory.getLogger(OAuth2UserDetailsService.class);
 	
-    LoginRepository loginRepository;
+    LoginService loginRepository;
 	
     public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
 		UserInfo userInfo;
@@ -68,7 +68,7 @@ public class OAuth2UserDetailsService implements UserDetailsService {
 		return principal;
 	}
 
-	public void setLoginRepository(LoginRepository loginRepository) {
+	public void setLoginRepository(LoginService loginRepository) {
 		this.loginRepository = loginRepository;
 	}
 

+ 2 - 2
maxkey-protocols/maxkey-protocol-oauth-2.0/src/main/java/org/dromara/maxkey/autoconfigure/Oauth20AutoConfiguration.java

@@ -48,8 +48,8 @@ import org.dromara.maxkey.crypto.jose.keystore.JWKSetKeyStore;
 import org.dromara.maxkey.crypto.jwt.encryption.service.impl.DefaultJwtEncryptionAndDecryptionService;
 import org.dromara.maxkey.crypto.jwt.signer.service.impl.DefaultJwtSigningAndValidationService;
 import org.dromara.maxkey.persistence.redis.RedisConnectionFactory;
-import org.dromara.maxkey.persistence.repository.LoginRepository;
 import org.dromara.maxkey.persistence.service.AppsService;
+import org.dromara.maxkey.persistence.service.LoginService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.InitializingBean;
@@ -329,7 +329,7 @@ public class Oauth20AutoConfiguration implements InitializingBean {
     ProviderManager oauth20UserAuthenticationManager(
             @Qualifier("passwordEncoder")
             PasswordEncoder passwordEncoder,
-            LoginRepository loginRepository
+            LoginService loginRepository
     ) {
         
         OAuth2UserDetailsService userDetailsService =new OAuth2UserDetailsService();

+ 2 - 2
maxkey-webs/maxkey-web-maxkey/src/main/java/org/dromara/maxkey/autoconfigure/MaxKeyConfig.java

@@ -42,9 +42,9 @@ import org.dromara.maxkey.password.onetimepwd.impl.MailOtpAuthn;
 import org.dromara.maxkey.password.onetimepwd.impl.TimeBasedOtpAuthn;
 import org.dromara.maxkey.password.onetimepwd.token.RedisOtpTokenStore;
 import org.dromara.maxkey.persistence.redis.RedisConnectionFactory;
-import org.dromara.maxkey.persistence.repository.LoginRepository;
 import org.dromara.maxkey.persistence.service.CnfLdapContextService;
 import org.dromara.maxkey.persistence.service.HistoryLoginService;
+import org.dromara.maxkey.persistence.service.LoginService;
 import org.dromara.maxkey.persistence.service.PasswordPolicyValidatorService;
 import org.dromara.maxkey.persistence.service.UserInfoService;
 import org.dromara.maxkey.schedule.ScheduleAdapterBuilder;
@@ -89,7 +89,7 @@ public class MaxKeyConfig  {
     JdbcAuthenticationRealm authenticationRealm(
                 @Qualifier("passwordEncoder") PasswordEncoder passwordEncoder,
                 PasswordPolicyValidatorService passwordPolicyValidatorService,
-                LoginRepository loginService,
+                LoginService loginService,
                 HistoryLoginService historyLoginService,
                 UserInfoService userInfoService,
                 IpLocationParser  ipLocationParser,

+ 3 - 3
maxkey-webs/maxkey-web-mgt/src/main/java/org/dromara/maxkey/autoconfigure/MaxKeyMgtConfig.java

@@ -21,8 +21,8 @@ import org.dromara.maxkey.authn.realm.jdbc.JdbcAuthenticationRealm;
 import org.dromara.maxkey.ip2location.IpLocationParser;
 import org.dromara.maxkey.password.onetimepwd.AbstractOtpAuthn;
 import org.dromara.maxkey.password.onetimepwd.impl.TimeBasedOtpAuthn;
-import org.dromara.maxkey.persistence.repository.LoginRepository;
 import org.dromara.maxkey.persistence.service.HistoryLoginService;
+import org.dromara.maxkey.persistence.service.LoginService;
 import org.dromara.maxkey.persistence.service.PasswordPolicyValidatorService;
 import org.dromara.maxkey.persistence.service.UserInfoService;
 import org.slf4j.Logger;
@@ -43,7 +43,7 @@ public class MaxKeyMgtConfig  {
                 @Qualifier("passwordEncoder")
                 PasswordEncoder passwordEncoder,
                 PasswordPolicyValidatorService passwordPolicyValidatorService,
-                LoginRepository loginRepository,
+                LoginService loginService,
                 HistoryLoginService historyLoginService,
                 UserInfoService userInfoService,
                 IpLocationParser  ipLocationParser,
@@ -52,7 +52,7 @@ public class MaxKeyMgtConfig  {
         JdbcAuthenticationRealm authenticationRealm = new JdbcAuthenticationRealm(
         		passwordEncoder,
         		passwordPolicyValidatorService,
-        		loginRepository,
+        		loginService,
         		historyLoginService,
         		userInfoService,
         		ipLocationParser,

+ 3 - 3
maxkey-webs/maxkey-web-openapi/src/main/java/org/dromara/maxkey/autoconfigure/MaxKeyOpenApiConfig.java

@@ -21,8 +21,8 @@ import org.dromara.maxkey.authn.realm.jdbc.JdbcAuthenticationRealm;
 import org.dromara.maxkey.ip2location.IpLocationParser;
 import org.dromara.maxkey.password.onetimepwd.AbstractOtpAuthn;
 import org.dromara.maxkey.password.onetimepwd.impl.TimeBasedOtpAuthn;
-import org.dromara.maxkey.persistence.repository.LoginRepository;
 import org.dromara.maxkey.persistence.service.HistoryLoginService;
+import org.dromara.maxkey.persistence.service.LoginService;
 import org.dromara.maxkey.persistence.service.PasswordPolicyValidatorService;
 import org.dromara.maxkey.persistence.service.UserInfoService;
 import org.slf4j.Logger;
@@ -43,7 +43,7 @@ public class MaxKeyOpenApiConfig{
                 @Qualifier("passwordEncoder")
                 PasswordEncoder passwordEncoder,
                 PasswordPolicyValidatorService passwordPolicyValidatorService,
-                LoginRepository loginRepository,
+                LoginService loginService,
                 HistoryLoginService historyLoginService,
                 UserInfoService userInfoService,
                 IpLocationParser  ipLocationParser,
@@ -52,7 +52,7 @@ public class MaxKeyOpenApiConfig{
         JdbcAuthenticationRealm authenticationRealm = new JdbcAuthenticationRealm(
         		passwordEncoder,
         		passwordPolicyValidatorService,
-        		loginRepository,
+        		loginService,
         		historyLoginService,
         		userInfoService,
         		ipLocationParser,