Expand my Community achievements bar.

SOLVED

User Last Login Date and No.of Logins of user

Avatar

Level 5

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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.


View solution in original post

5 Replies

Avatar

Community Advisor

Could you please describe where you want to use the last login and number of times user logs in details?

Avatar

Level 5

Will not use those, will take report of Users with above details to pull & validate.

Avatar

Community Advisor

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.

Avatar

Level 5

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

Avatar

Correct answer by
Community Advisor

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.