mirror of
https://gitee.com/dromara/MaxKey.git
synced 2026-05-14 20:50:14 +08:00
mv to repository
This commit is contained in:
@@ -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<Groups> queryGroups(UserInfo userInfo) {
|
||||
return loginService.queryGroups(userInfo);
|
||||
return loginRepository.queryGroups(userInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +112,7 @@ public abstract class AbstractAuthenticationRealm {
|
||||
* @return ArrayList<GrantedAuthority>
|
||||
*/
|
||||
public ArrayList<GrantedAuthority> grantAuthority(UserInfo userInfo) {
|
||||
return loginService.grantAuthority(userInfo);
|
||||
return loginRepository.grantAuthority(userInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +122,7 @@ public abstract class AbstractAuthenticationRealm {
|
||||
* @return ArrayList<GrantedAuthority Apps>
|
||||
*/
|
||||
public ArrayList<GrantedAuthority> queryAuthorizedApps(ArrayList<GrantedAuthority> 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() + " .");
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user