I'm having trouble with my security configuration and I need to create a list of the Ip's that are accessing my application.
My problem is to get the Ip in a dynamic way for all my application requests. But I don't want to add a HttpServletRequest for all the requests of my application, what I want is a method that is called before every request, even before SecurityConfig events.
What I've tried to do is to use AuthenticationProvider to get the request HttpServletRequest and then get the Ip of my client. The problem is that I can't find a way to create a single class and it connects to all my requests. This is my code:
public abstract class IPAddressBasedAuthenticationProvider implements AuthenticationProvider {
/**
* Context http request
*/
@Autowired
private HttpServletRequest request;
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String ipAddress = request.getRemoteAddr();
System.out.println(ipAddress);
return authentication;
}
}
What I was thinking was that my requests where going to pass in this code and then show my client Ip.
I tried autowiring it in my controller classes but my application doesn't execute then. What can I do to make this work?