Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I access the users IP Address (or other web-request data) in a UserDetailsService?

0
Posted

How do I access the users IP Address (or other web-request data) in a UserDetailsService?

0

Obviously you can’t (without resorting to something like thread-local variables) since the only information supplied to the interface is the username. Instead of implementing UserDetailsService, you should implement AuthenticationProvider directly and extract the information from the supplied Authentication token. In a standard web setup, the getDetails() method on the Authentication object will return an instance of WebAuthenticationDetails. If you need additional information, you can inject a custom AuthenticationDetailsSource into the authentication filter you are using. If you are using the namespace, for example with the element, then you should remove this element and replace it with a declaration pointing to an explicitly configured UsernamePasswordAuthenticationFilter.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123