Java 具有额外登录字段的自定义AuthenticationProvider

Java 具有额外登录字段的自定义AuthenticationProvider,java,spring,spring-security,Java,Spring,Spring Security,我有一个customAuthenticationProvider,我想用3个参数对用户进行身份验证:用户名、密码和令牌PIN。 但目前我对该供应商有一个小问题: @Component public class CustomAuthenticationProvider implements AuthenticationProvider { @Autowired private UserService userService; @Override public Authentication

我有一个customAuthenticationProvider,我想用3个参数对用户进行身份验证:用户名、密码和令牌PIN。 但目前我对该供应商有一个小问题:

@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);
}
@组件
公共类CustomAuthenticationProvider实现AuthenticationProvider{
@自动连线
私人用户服务;
@凌驾
公共身份验证(身份验证)引发AuthenticationException{
字符串username=authentication.getName();
字符串密码=authentication.getCredentials().toString();
字符串引脚=????
身份验证auth=null;
User User=userService.findByUsernameAndPassword(用户名、密码);
如果(用户!=null){
List grantedAuths=new ArrayList();
grantedAuths.add(新的SimpleGrantedAuthority(“角色管理”);
auth=新用户名PasswordAuthenticationToken(用户名、密码、授权认证);
}
返回auth;
}
@凌驾
公共布尔支持(类身份验证){
返回authentication.equals(UsernamePasswordAuthenticationToken.class);
}

}

使用您自己的
身份验证
对象不要滥用
用户名密码身份验证令牌
。您还需要一个自定义筛选器来填充该自定义
身份验证
对象。您可能正在查找