优化登录接口

This commit is contained in:
OPGame
2019-09-11 08:37:19 +08:00
parent 5e10d08a7e
commit 3e00dd7985
4 changed files with 13 additions and 28 deletions

View File

@@ -41,20 +41,7 @@ public class AdminAuthenticationProvider extends AbstractUserDetailsAuthenticati
@Override
protected UserDetails retrieveUser(String username, Authentication authentication) throws BaseYamiAuth2Exception {
UserDetails user;
try {
user = yamiUserDetailsService.loadUserByUsername(username);
} catch (UsernameNotFoundExceptionBase var6) {
throw new UsernameNotFoundExceptionBase("账号或密码不正确");
}
if (!user.isEnabled()) {
throw new UsernameNotFoundExceptionBase("账号已被锁定,请联系管理员");
}
return user;
}
@Override
protected void additionalAuthenticationChecks(UserDetails sysUser, Authentication authentication) throws BaseYamiAuth2Exception {
AdminAuthenticationToken adminAuthenticationToken = (AdminAuthenticationToken) authentication;
String kaptchaKey = SecurityConstants.SPRING_SECURITY_RESTFUL_IMAGE_CODE + adminAuthenticationToken.getSessionUUID();
@@ -67,17 +54,28 @@ public class AdminAuthenticationProvider extends AbstractUserDetailsAuthenticati
throw new ImageCodeNotMatchExceptionBase("验证码有误");
}
UserDetails user;
try {
user = yamiUserDetailsService.loadUserByUsername(username);
} catch (UsernameNotFoundExceptionBase var6) {
throw new UsernameNotFoundExceptionBase("账号或密码不正确");
}
String encodedPassword = sysUser.getPassword();
String encodedPassword = user.getPassword();
String rawPassword = authentication.getCredentials().toString();
// 密码不正确
if (!passwordEncoder.matches(rawPassword,encodedPassword)){
throw new BadCredentialsExceptionBase("账号或密码不正确");
}
if (!user.isEnabled()) {
throw new UsernameNotFoundExceptionBase("账号已被锁定,请联系管理员");
}
return user;
}
@Override
protected Authentication createSuccessAuthentication(Authentication authentication, UserDetails user) {
AdminAuthenticationToken result = new AdminAuthenticationToken(user, authentication.getCredentials());

View File

@@ -41,11 +41,6 @@ public class MiniAppAuthenticationProvider extends AbstractUserDetailsAuthentica
private final WxMaService wxMaService;
@Override
protected void additionalAuthenticationChecks(UserDetails var1, Authentication authentication) throws AuthenticationException {
}
@Override
protected Authentication createSuccessAuthentication(Authentication authentication, UserDetails user) {
MiniAppAuthenticationToken result = new MiniAppAuthenticationToken(user, authentication.getCredentials());

View File

@@ -28,8 +28,6 @@ public abstract class AbstractUserDetailsAuthenticationProvider implements Authe
protected abstract void additionalAuthenticationChecks(UserDetails var1, Authentication var2) throws AuthenticationException;
@Override
public final void afterPropertiesSet() {
}
@@ -47,8 +45,6 @@ public abstract class AbstractUserDetailsAuthenticationProvider implements Authe
throw var6;
}
this.additionalAuthenticationChecks(user, authentication);
return this.createSuccessAuthentication(authentication, user);
}

View File

@@ -45,10 +45,6 @@ public class MpAuthenticationProvider extends AbstractUserDetailsAuthenticationP
private final WxMpService wxMpService;
@Override
protected void additionalAuthenticationChecks(UserDetails var1, Authentication authentication) throws AuthenticationException {
}
@Override
protected Authentication createSuccessAuthentication(Authentication authentication, UserDetails user) {