有没有办法将URL参数传递给Spring Security 3中的身份验证提供程序?
我们的登录页面需要接收电子邮件令牌作为身份验证系统在设置用户状态时需要注意的参数。具体来说,它将让用户具有正确的令牌登录,否则将无法登录。
我有一个自定义类扩展DaoAuthenticationProvider类。我的身份验证逻辑在该类的authenticate方法中。
我希望有一些方法可以将这些数据传递给authenticate方法。
您可以在身份验证提供程序类上注入HttpServletRequest对象:
private @Autowired HttpServletRequest request;
现在,您应该能够使用request.getParameterValues(paramName)
等API访问请求参数
您需要覆盖UsernamePasswordAuthenticationFilter.setDetails()
并通过details
的UsernamePasswordAuthenticationToken
属性将额外信息传递给您的自定义身份验证提供程序。