我有自定义的AuthenticationProvider,可以检查手动的用户名和密码,final UserDetails principal = new User(username, password, grantedAuths);
在我开始使用MyUserDetails类final UserDetails principal =new MyUserDetails(username, password, grantedAuths);
时仍然可以正常工作,但是如果用户isisAccountNonLocked为false,即使允许成功登录,甚至MyUserDetails都可以与Custom UserDetailsService一起使用,请帮帮我...
public class MyUserDetails implements UserDetails {
private String username;
private String password;
private List<GrantedAuthority> authorities;
public MyUserDetails() {
}
public MyUserDetails(String username, String password, List<GrantedAuthority> authorities) {
this.username = username;
this.password = password;
this.authorities = authorities;
}
// another setter getter
}
@Component
public class MyAuthenticationProvider implements AuthenticationProvider {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
final String username = authentication.getName();
final String password = authentication.getCredentials().toString();
if (username.equals("sagir") && password.equals("password")) {
final List<GrantedAuthority> grantedAuths = new ArrayList<>();
grantedAuths.add(new SimpleGrantedAuthority("USER"));
//final UserDetails principal = new User(username, password, grantedAuths); working fine with them
final UserDetails principal =new MyUserDetails(username, password, grantedAuths);
// MyUserDetails not working in case isAccountNonExpired,isAccountNonLocked,isCredentialsNonExpired is false still I am able to login, they only checks username&pwd
final Authentication auth = new UsernamePasswordAuthenticationToken(principal, password, grantedAuths);
return auth;
} else {
return null;
}
}
@Override
public boolean supports(Class<?> authentication) {
return authentication.equals(UsernamePasswordAuthenticationToken.class);
}
}
}
// WebConfig
// WebConfig
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder()); working fine with userDetailsService
auth.authenticationProvider(authenticationProvider);