我有一个customAuthenticationProvider,我想用3个参数验证用户:用户名,密码和tokenPin。 但目前我对这个提供商有一点问题:
@Component
public class CustomAuthenticationProvider implements AuthenticationProvider {
@Autowired
private UserService userService;
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String username = authentication.getName();
String password = authentication.getCredentials().toString();
String pin = ????
Authentication auth = null;
User user = userService.findByUsernameAndPassword(username, password);
if (user != null) {
List<GrantedAuthority> grantedAuths = new ArrayList<>();
grantedAuths.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
auth = new UsernamePasswordAuthenticationToken(username, password, grantedAuths);
}
return auth;
}
@Override
public boolean supports(Class<?> authentication) {
return authentication.equals(UsernamePasswordAuthenticationToken.class);
}
}