如何获得自定义的AuthenticationProvider中获得的HttpServletRequest中获得的HttpServletRequest。我曾尝试这样做获取自定义的AuthenticationProvider
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
String username = (String) httpReq.getAttribute("j_username");
OR
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
HttpServletRequest httpReq = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest();
String username = (String) httpReq.getAttribute("j_username");
我得到的用户名空
但RequestContextHolder.getRequestAttributes();返回null。
我想引用的RequestContext,通过它,或有春天做它的魔力,所以我可以引用它。
我也给RequestContextListener在我的web.xml
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
我已经搜查了安全论坛,但仍然还没有发现任何东西。
在此先感谢。
不宜这些证书被包含在认证对象之内? http://static.springsource.org/spring-security/site/docs/3.0.x/apidocs/org/springframework/security/authentication/AuthenticationProvider.html – dardo 2012-07-05 18:09:10
DARDO是正确的。我想你应该看一些基本的样本并阅读一些文档,然后更详细地解释你想要实现的目标,因为我想不出以这种方式访问用户名的正当理由。 – 2012-07-08 14:26:34
凭证确实在认证对象中。不过,我也在寻找解决方案。我也需要访问请求,但另一个原因。在我的应用程序中,URL在认证中扮演了角色。关于如何在课堂上获得它的任何想法? – Wouter 2014-04-20 08:27:09