登录整合优化

This commit is contained in:
shimingxy
2024-12-19 09:27:31 +08:00
parent 7844fc25bf
commit 0d18f5d7df
21 changed files with 160 additions and 84 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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,

View File

@@ -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;
}

View File

@@ -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)) {

View File

@@ -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);
}
}