How do I get access to HttpServletRequest within a custom AuthenticationProvider. I have tried doing this
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");
i am getting username null
but RequestContextHolder.getRequestAttributes();
returns null
.
I want to reference the requestcontext, pass it in, or have Spring do its Magic so I can reference it.
I am also giving the RequestContextListener in my web.xml
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
I have searched the security forum but still havent found anything yet.
Thanks in advance.
I just added the listener to my web.xml and RequestContextHolder.getRequestAttributes() returns the RequestAttributes instead of null.
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
If you want to customize you login form, why you don't extend this filter: org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With