User Last Login Date and No.of Logins of user

sailaxmanr83887

28-08-2019

Hi All,

I have a requirement where we need to get the user last login on AEM server i.e. User last access date & time. We are going with AEM-SAML integration for user authentication not a custom login approach. Could you let me know is there any way through which we can get above details i.e last login & no.of logins of user. Let me know if do we need to follow any approach for getting above details.

Thank you.

Sailaxman

Accepted Solutions (1)

Accepted Solutions (1)

Himanshu_Singhal

MVP

29-08-2019

It won't impact the existing AEM default login functionality. All you need to do is extends the AuthenticationHandler and override the method extractCredentials and write the logic the persist the login count for user.

For rest of the method, just return the standard as it's their OOTB. E.g. acs-aem-samples/SampleLoginHookAuthenticationHandler.java at master · Adobe-Consulting-Services/acs-...

@Reference(target = "(service.pid=com.day.crx.security.token.impl.impl.TokenAuthenticationHandler)")

private AuthenticationHandler wrappedAuthHandler;

Get the OOTB authentication handler and then use the reference to return logic as its return in OOTB authentication handler.

return wrappedAuthHandler
.extractCredentials(httpServletRequest, deferredRedirectResponse);

This way you won't impact OOTB login and you'd be able to persist login count.


Answers (4)

Answers (4)

Himanshu_Singhal

MVP

29-08-2019

There's a OOTB report to generate Users report but it doesn't have information related to login or number of times login in options.

And, I don't think there's such option available OOTB to get the such details.


For that, you can write custom code (a servlet) to get last login (date/time) for user. It's stored under path /home/users/<user>/.tokens/<last login node>


<last login node> - node name is the last login date and time. However, it's just last login information. You still won't find number of times user logged in information. For that, you can write custom authentication handler and once a user log-in, you can save the count in user profile and then generates the report.

Hope it helps.

sailaxmanr83887

29-08-2019

Ok, does this custom authentication handler will impact my existing aem default login functionality behavior if yes then what care needs to be taken ?