refactor: 临时密码登录功能
This commit is contained in:
parent
5e9857ee99
commit
1e3dc72d55
@ -29,12 +29,19 @@ public class LoginTemporaryAuthFilter extends AbstractAuthenticationProcessingFi
|
|||||||
@Override
|
@Override
|
||||||
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
|
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
|
||||||
String phone = request.getParameter("username").trim();
|
String phone = request.getParameter("username").trim();
|
||||||
String password = loginTemporaryService.getPassword();
|
String password = request.getParameter("password").trim();
|
||||||
if (StringUtils.isBlank(phone)) {
|
if (StringUtils.isBlank(phone)) {
|
||||||
throw new UserAuthenticationException("手机号不能为空");
|
throw new UserAuthenticationException("手机号不能为空");
|
||||||
}
|
}
|
||||||
if (StringUtils.isBlank(password)) {
|
if (StringUtils.isBlank(password)) {
|
||||||
throw new UserAuthenticationException("密码已过期,请重新获取");
|
throw new UserAuthenticationException("密码不能为空");
|
||||||
|
}
|
||||||
|
String temporaryPassword = loginTemporaryService.getPassword();
|
||||||
|
if (StringUtils.isBlank(temporaryPassword)) {
|
||||||
|
throw new UserAuthenticationException("临时密码已过期,请重新获取");
|
||||||
|
}
|
||||||
|
if (!StringUtils.equals(password, temporaryPassword)) {
|
||||||
|
throw new UserAuthenticationException("密码不正确");
|
||||||
}
|
}
|
||||||
LoginPhoneAuthToken loginTemporaryAuthToken = new LoginPhoneAuthToken(phone, null);
|
LoginPhoneAuthToken loginTemporaryAuthToken = new LoginPhoneAuthToken(phone, null);
|
||||||
loginTemporaryAuthToken.setDetails(authenticationDetailsSource.buildDetails(request));
|
loginTemporaryAuthToken.setDetails(authenticationDetailsSource.buildDetails(request));
|
||||||
|
@ -19,14 +19,14 @@ public class LoginTemporaryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
return password;
|
return this.password;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(fixedRate = 10 * 1000)
|
@Scheduled(fixedRate = 10 * 1000)
|
||||||
public void autoClearPassword() {
|
public void autoClearPassword() {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
if(now - lastUpdateTime > 180 * 1000) {
|
if(now - lastUpdateTime > 60 * 1000) {
|
||||||
password = "";
|
this.password = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user