BeforeLoginEvent - get httprequest

Hi there, I was wondering if it were possibile to get the ip address in the beforeloginevent ? Is there any mechanism to get the httprequest object ?


  1. Anywhere in the code of the web or portal modules you can make use of the standard Spring class holding the original ServletHttpRequest object - RequestContextHolder.currentRequestAttributes()

see java - How to extract IP Address in Spring MVC Controller get call? - Stack Overflow

see how it is used in the platform code:

Another wrapper class holding the same information is com.haulmont.cuba.web.sys.RequestContext#getRequest, can be used in web module.

  1. If you mean BeforeLoginEvent of the core module - then you should cast beforeLoginEvent.getCredentials() to AbstractClientCredentials and take ipAddress from AbstractClientCredentials#ipAddress.

See usage example in the class:

        if (credentials instanceof AbstractClientCredentials) {
            AbstractClientCredentials clientCredentials = (AbstractClientCredentials) credentials;
                String ipAddress = clientCredentials.getIpAddress();

Thanks, perfect.