Audting the Login Failure in liferay

In Liferay we can audit login failure for the user just by writing the hook.

We have property which we need to add in portal.properties file as.

       auth.failure = com.sample.events.hook.LoginFailureAudit.


Then create a class and extend with the AuthFailure

public class LoginFailureAudit implements AuthFailure {

     public void onFailureByEmailAddress(long companyId, String emailAddress,
Map<String, String[]> headerMap, Map<String, String[]> parameterMap) throws AuthException {

long userId = UserLocalServiceUtil.getUserByScreenName(companyId, emailAddress).getUserId();

User user = UserLocalServiceUtil.getUser(userId);
System.out.println("login failure attempts are"+user.getFailedLoginAttempts());


}

public void onFailureByScreenName(long companyId, String screenName, Map<String, String[]> headerMap,
Map<String, String[]> parameterMap) throws AuthException {

long userId = UserLocalServiceUtil.getUserByScreenName(companyId, screenName).getUserId();
User user = UserLocalServiceUtil.getUser(userId);
System.out.println("login failure attempts are"+user.getFailedLoginAttempts());

}


public void onFailureByUserId(long companyId, long userId, Map<String, String[]> headerMap,
Map<String, String[]> parameterMap) throws AuthException {


User user = UserLocalServiceUtil.getUser(userId);
System.out.println("login failure attempts are"+user.getFailedLoginAttempts());
}


}


Based on the AuthenticationType write the logic in the appropriate methods. "user.getFailedLoginAttempts()" gets number of login failures of the user.


Comments

Popular posts from this blog

Theme display in javascript

How to know which liferay version we are using

Viewing the SQL Query in liferay : debugging the SQL Query in Hibernate