mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-08 01:48:33 +08:00
提交短信认证后端逻辑判断
This commit is contained in:
parent
756993053b
commit
0bd384b76a
@ -49,7 +49,7 @@ public class LoginCredential implements Authentication {
|
||||
ArrayList<GrantedAuthority> grantedAuthority;
|
||||
boolean authenticated;
|
||||
boolean roleAdministrators;
|
||||
|
||||
String mobile;
|
||||
/**
|
||||
* BasicAuthentication.
|
||||
*/
|
||||
@ -66,14 +66,14 @@ public class LoginCredential implements Authentication {
|
||||
}
|
||||
|
||||
public String getCongress() {
|
||||
return congress;
|
||||
}
|
||||
return congress;
|
||||
}
|
||||
|
||||
public void setCongress(String congress) {
|
||||
this.congress = congress;
|
||||
}
|
||||
public void setCongress(String congress) {
|
||||
this.congress = congress;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Login Credential";
|
||||
}
|
||||
@ -127,14 +127,14 @@ public class LoginCredential implements Authentication {
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getCaptcha() {
|
||||
public String getCaptcha() {
|
||||
return captcha;
|
||||
}
|
||||
|
||||
@ -223,51 +223,62 @@ public class LoginCredential implements Authentication {
|
||||
}
|
||||
|
||||
public String getInstId() {
|
||||
return instId;
|
||||
}
|
||||
return instId;
|
||||
}
|
||||
|
||||
public void setInstId(String instId) {
|
||||
this.instId = instId;
|
||||
}
|
||||
public void setInstId(String instId) {
|
||||
this.instId = instId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("LoginCredential [congress=");
|
||||
builder.append(congress);
|
||||
builder.append(", username=");
|
||||
builder.append(username);
|
||||
builder.append(", password=");
|
||||
builder.append(password);
|
||||
builder.append(", state=");
|
||||
builder.append(state);
|
||||
builder.append(", captcha=");
|
||||
builder.append(captcha);
|
||||
builder.append(", otpCaptcha=");
|
||||
builder.append(otpCaptcha);
|
||||
builder.append(", remeberMe=");
|
||||
builder.append(remeberMe);
|
||||
builder.append(", authType=");
|
||||
builder.append(authType);
|
||||
builder.append(", jwtToken=");
|
||||
builder.append(jwtToken);
|
||||
builder.append(", onlineTicket=");
|
||||
builder.append(onlineTicket);
|
||||
builder.append(", provider=");
|
||||
builder.append(provider);
|
||||
builder.append(", code=");
|
||||
builder.append(code);
|
||||
builder.append(", message=");
|
||||
builder.append(message);
|
||||
builder.append(", instId=");
|
||||
builder.append(instId);
|
||||
builder.append(", grantedAuthority=");
|
||||
builder.append(grantedAuthority);
|
||||
builder.append(", authenticated=");
|
||||
builder.append(authenticated);
|
||||
builder.append(", roleAdministrators=");
|
||||
builder.append(roleAdministrators);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
public String getMobile() {
|
||||
return mobile;
|
||||
}
|
||||
|
||||
public void setMobile(String mobile) {
|
||||
this.mobile = mobile;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("LoginCredential [congress=");
|
||||
builder.append(congress);
|
||||
builder.append(", username=");
|
||||
builder.append(username);
|
||||
builder.append(", password=");
|
||||
builder.append(password);
|
||||
builder.append(", state=");
|
||||
builder.append(state);
|
||||
builder.append(", mobile=");
|
||||
builder.append(mobile);
|
||||
builder.append(", captcha=");
|
||||
builder.append(captcha);
|
||||
builder.append(", otpCaptcha=");
|
||||
builder.append(otpCaptcha);
|
||||
builder.append(", remeberMe=");
|
||||
builder.append(remeberMe);
|
||||
builder.append(", authType=");
|
||||
builder.append(authType);
|
||||
builder.append(", jwtToken=");
|
||||
builder.append(jwtToken);
|
||||
builder.append(", onlineTicket=");
|
||||
builder.append(onlineTicket);
|
||||
builder.append(", provider=");
|
||||
builder.append(provider);
|
||||
builder.append(", code=");
|
||||
builder.append(code);
|
||||
builder.append(", message=");
|
||||
builder.append(message);
|
||||
builder.append(", instId=");
|
||||
builder.append(instId);
|
||||
builder.append(", grantedAuthority=");
|
||||
builder.append(grantedAuthority);
|
||||
builder.append(", authenticated=");
|
||||
builder.append(authenticated);
|
||||
builder.append(", roleAdministrators=");
|
||||
builder.append(roleAdministrators);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
@ -52,66 +52,71 @@ public class MobileAuthenticationProvider extends AbstractAuthenticationProvider
|
||||
|
||||
|
||||
public MobileAuthenticationProvider() {
|
||||
super();
|
||||
}
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public MobileAuthenticationProvider(
|
||||
AbstractAuthenticationRealm authenticationRealm,
|
||||
ApplicationConfig applicationConfig,
|
||||
OtpAuthnService otpAuthnService,
|
||||
SessionManager sessionManager) {
|
||||
this.authenticationRealm = authenticationRealm;
|
||||
this.applicationConfig = applicationConfig;
|
||||
this.otpAuthnService = otpAuthnService;
|
||||
this.sessionManager = sessionManager;
|
||||
}
|
||||
AbstractAuthenticationRealm authenticationRealm,
|
||||
ApplicationConfig applicationConfig,
|
||||
OtpAuthnService otpAuthnService,
|
||||
SessionManager sessionManager) {
|
||||
this.authenticationRealm = authenticationRealm;
|
||||
this.applicationConfig = applicationConfig;
|
||||
this.otpAuthnService = otpAuthnService;
|
||||
this.sessionManager = sessionManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Authentication doAuthenticate(LoginCredential loginCredential) {
|
||||
UsernamePasswordAuthenticationToken authenticationToken = null;
|
||||
_logger.debug("Trying to authenticate user '{}' via {}",
|
||||
public Authentication doAuthenticate(LoginCredential loginCredential) {
|
||||
UsernamePasswordAuthenticationToken authenticationToken = null;
|
||||
_logger.debug("Trying to authenticate user '{}' via {}",
|
||||
loginCredential.getPrincipal(), getProviderName());
|
||||
try {
|
||||
|
||||
_logger.debug("authentication " + loginCredential);
|
||||
//如果是验证码登录,设置mobile为username
|
||||
loginCredential.setUsername(loginCredential.getMobile());
|
||||
//设置密码为验证码
|
||||
loginCredential.setPassword(loginCredential.getOtpCaptcha());
|
||||
|
||||
emptyPasswordValid(loginCredential.getPassword());
|
||||
_logger.debug("authentication " + loginCredential);
|
||||
|
||||
emptyUsernameValid(loginCredential.getUsername());
|
||||
emptyPasswordValid(loginCredential.getPassword());
|
||||
|
||||
UserInfo userInfo = loadUserInfo(loginCredential.getUsername(),loginCredential.getPassword());
|
||||
emptyUsernameValid(loginCredential.getUsername());
|
||||
|
||||
statusValid(loginCredential , userInfo);
|
||||
UserInfo userInfo = loadUserInfo(loginCredential.getUsername(),loginCredential.getPassword());
|
||||
|
||||
//Validate PasswordPolicy
|
||||
authenticationRealm.getPasswordPolicyValidator().passwordPolicyValid(userInfo);
|
||||
statusValid(loginCredential , userInfo);
|
||||
|
||||
mobileCaptchaValid(loginCredential.getPassword(),userInfo);
|
||||
//Validate PasswordPolicy 取消密码策略验证
|
||||
//authenticationRealm.getPasswordPolicyValidator().passwordPolicyValid(userInfo);
|
||||
|
||||
//apply PasswordSetType and resetBadPasswordCount
|
||||
authenticationRealm.getPasswordPolicyValidator().applyPasswordPolicy(userInfo);
|
||||
mobileCaptchaValid(loginCredential.getPassword(),userInfo);
|
||||
|
||||
authenticationToken = createOnlineTicket(loginCredential,userInfo);
|
||||
// user authenticated
|
||||
_logger.debug("'{}' authenticated successfully by {}.",
|
||||
loginCredential.getPrincipal(), getProviderName());
|
||||
//apply PasswordSetType and resetBadPasswordCount
|
||||
authenticationRealm.getPasswordPolicyValidator().applyPasswordPolicy(userInfo);
|
||||
|
||||
authenticationRealm.insertLoginHistory(userInfo,
|
||||
ConstsLoginType.LOCAL,
|
||||
"",
|
||||
"xe00000004",
|
||||
WebConstants.LOGIN_RESULT.SUCCESS);
|
||||
authenticationToken = createOnlineTicket(loginCredential,userInfo);
|
||||
// user authenticated
|
||||
_logger.debug("'{}' authenticated successfully by {}.",
|
||||
loginCredential.getPrincipal(), getProviderName());
|
||||
|
||||
authenticationRealm.insertLoginHistory(userInfo,
|
||||
ConstsLoginType.LOCAL,
|
||||
"",
|
||||
"xe00000004",
|
||||
WebConstants.LOGIN_RESULT.SUCCESS);
|
||||
} catch (AuthenticationException e) {
|
||||
_logger.error("Failed to authenticate user {} via {}: {}",
|
||||
new Object[] { loginCredential.getPrincipal(),
|
||||
getProviderName(),
|
||||
e.getMessage() });
|
||||
getProviderName(),
|
||||
e.getMessage() });
|
||||
WebContext.setAttribute(
|
||||
WebConstants.LOGIN_ERROR_SESSION_MESSAGE, e.getMessage());
|
||||
} catch (Exception e) {
|
||||
_logger.error("Login error Unexpected exception in {} authentication:\n{}" ,
|
||||
getProviderName(), e.getMessage());
|
||||
getProviderName(), e.getMessage());
|
||||
}
|
||||
|
||||
return authenticationToken;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user