Add userinfo attributes to $currentSession - Mendix Forum

Add userinfo attributes to $currentSession

7

In order to have more control over (anonymous) users, the question arises to have some more userinfo. It would be nice to extend the session object to contain also:


The advantage is that in a microflow, these attributes are available via the $currentSession variable.

This enables for example to write audit logs with IP, collect statistics about user agents and distinguish multiple domain names.

asked
5 answers

I have implemented the java action that Johan Flikweert created. But, while running my application locally, it returns the IP Address 127.0.0.1 which is the loopback address (also known as localhost).It’s different from my IPv4 Address. I used IPConfig to get my IP, & it was completely different.

 

Any ideas if I’m missing something?!

Created

I built the Http Commons Module as an easy way to access all these new fields in Java.

Created

Yes, I've built a Java Action to retrieve the client's IP address (having input parameter: ISession):

// BEGIN USER CODE
IContext ctx = SessionParameter1.getContext();
Optional<IMxRuntimeRequest> orr = ctx.getRuntimeRequest();
String realIP = null;
if (orr.isPresent()) {
    IMxRuntimeRequest rr = orr.get();
    realIP = rr.getHeader("X-Real-IP");
    if( realIP == null )
        realIP = rr.getHeader("X-Forwarded-For");
    if( realIP == null )
        realIP = rr.getRemoteAddr();
}
return realIP;
// END USER CODE

 

Created

Has anyone built this Java action already and can share it?

Created

I would like to add extra fields to that list detectable from the browser

  • Local Date/Time from the browser (useful for setting user account time-zone, so it is no longer required to set the "default" timezone)
  • Language / User Language (useful for setting user language, because currently anonymous users get the default system language)
  • Javascript enabled/disabled
  • Cookies enabled/disabled


For styling purposes:

  • Screen Dimensions
  • Browser Dimensions
  • Operating system
  • Images enabled/disabled
     
Created