isUserExist

This commit is contained in:
MaxKey 2024-03-27 21:33:50 +08:00
parent e56b239693
commit 1cc41d1d23
4 changed files with 31 additions and 25 deletions

View File

@ -209,10 +209,10 @@ public abstract class AbstractAuthenticationProvider {
return true; return true;
} }
protected boolean statusValid(LoginCredential loginCredential , UserInfo userInfo) { protected boolean isUserExist(LoginCredential loginCredential , UserInfo userInfo) {
if (null == userInfo) { if (null == userInfo) {
String i18nMessage = WebContext.getI18nValue("login.error.username"); String i18nMessage = WebContext.getI18nValue("login.error.username");
_logger.debug("login user " + loginCredential.getUsername() + " not in this System ." + i18nMessage); _logger.debug("login user {} not in this System , message {} ." ,loginCredential.getUsername(), i18nMessage);
UserInfo loginUser = new UserInfo(loginCredential.getUsername()); UserInfo loginUser = new UserInfo(loginCredential.getUsername());
loginUser.setId(loginUser.generateId()); loginUser.setId(loginUser.generateId());
loginUser.setUsername(loginCredential.getUsername()); loginUser.setUsername(loginCredential.getUsername());
@ -225,26 +225,29 @@ public abstract class AbstractAuthenticationProvider {
i18nMessage, i18nMessage,
WebConstants.LOGIN_RESULT.USER_NOT_EXIST); WebConstants.LOGIN_RESULT.USER_NOT_EXIST);
throw new BadCredentialsException(i18nMessage); throw new BadCredentialsException(i18nMessage);
}else {
if(userInfo.getIsLocked()==ConstsStatus.LOCK) {
authenticationRealm.insertLoginHistory(
userInfo,
loginCredential.getAuthType(),
loginCredential.getProvider(),
loginCredential.getCode(),
WebConstants.LOGIN_RESULT.USER_LOCKED
);
}else if(userInfo.getStatus()!=ConstsStatus.ACTIVE) {
authenticationRealm.insertLoginHistory(
userInfo,
loginCredential.getAuthType(),
loginCredential.getProvider(),
loginCredential.getCode(),
WebConstants.LOGIN_RESULT.USER_INACTIVE
);
}
} }
return true; return true;
} }
protected boolean statusValid(LoginCredential loginCredential , UserInfo userInfo) {
if(userInfo.getIsLocked()==ConstsStatus.LOCK) {
authenticationRealm.insertLoginHistory(
userInfo,
loginCredential.getAuthType(),
loginCredential.getProvider(),
loginCredential.getCode(),
WebConstants.LOGIN_RESULT.USER_LOCKED
);
}else if(userInfo.getStatus()!=ConstsStatus.ACTIVE) {
authenticationRealm.insertLoginHistory(
userInfo,
loginCredential.getAuthType(),
loginCredential.getProvider(),
loginCredential.getCode(),
WebConstants.LOGIN_RESULT.USER_INACTIVE
);
}
return true;
}
} }

View File

@ -84,6 +84,8 @@ public class MfaAuthenticationProvider extends AbstractAuthenticationProvider {
userInfo = loadUserInfo(loginCredential.getUsername(),loginCredential.getPassword()); userInfo = loadUserInfo(loginCredential.getUsername(),loginCredential.getPassword());
isUserExist(loginCredential , userInfo);
statusValid(loginCredential , userInfo); statusValid(loginCredential , userInfo);
//mfa //mfa
mfacaptchaValid(loginCredential.getOtpCaptcha(),userInfo); mfacaptchaValid(loginCredential.getOtpCaptcha(),userInfo);

View File

@ -90,11 +90,10 @@ public class MobileAuthenticationProvider extends AbstractAuthenticationProvider
UserInfo userInfo = loadUserInfo(loginCredential.getUsername(),loginCredential.getPassword()); UserInfo userInfo = loadUserInfo(loginCredential.getUsername(),loginCredential.getPassword());
isUserExist(loginCredential , userInfo);
statusValid(loginCredential , userInfo); statusValid(loginCredential , userInfo);
//Validate PasswordPolicy 取消密码策略验证
//authenticationRealm.getPasswordPolicyValidator().passwordPolicyValid(userInfo);
mobileCaptchaValid(loginCredential.getPassword(),userInfo); mobileCaptchaValid(loginCredential.getPassword(),userInfo);
//apply PasswordSetType and resetBadPasswordCount //apply PasswordSetType and resetBadPasswordCount

View File

@ -91,11 +91,13 @@ public class NormalAuthenticationProvider extends AbstractAuthenticationProvider
UserInfo userInfo = loadUserInfo(loginCredential.getUsername(),loginCredential.getPassword()); UserInfo userInfo = loadUserInfo(loginCredential.getUsername(),loginCredential.getPassword());
statusValid(loginCredential , userInfo); isUserExist(loginCredential , userInfo);
//Validate PasswordPolicy //Validate PasswordPolicy
authenticationRealm.getPasswordPolicyValidator().passwordPolicyValid(userInfo); authenticationRealm.getPasswordPolicyValidator().passwordPolicyValid(userInfo);
statusValid(loginCredential , userInfo);
//Match password //Match password
authenticationRealm.passwordMatches(userInfo, loginCredential.getPassword()); authenticationRealm.passwordMatches(userInfo, loginCredential.getPassword());