Get IP Address From Successful Login?

I would like to record in the database each time there is a successful login. Information I would like to record is user, IP address, and maybe browser or other info to help identify how/where the user logged in.

I see the examples of how to get the authentication details from InteractiveAuthenticationSuccessEvent, but the ClientDetails object does not have much info and does not have the IP address.

User user = (User) event.getAuthentication().getPrincipal();

ClientDetails details = (ClientDetails) event.getAuthentication().getDetails();

Should I be retrieving the request information somewhere else?

Hello,

It is possible to get get some information from HttpServletRequest. Example:

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
...
var request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
request.getRemoteAddr(); // client or last proxy IP
request.getHeader("user-agent"); // browser info

Thanks. I was able to get that to work. I found more examples of how to pull the IP address from the headers in case of forwarding from proxy, load balancer, etc.