Skip to content

Commit

Permalink
#23915 : Implementing more SonarQube feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcastro-dotcms committed Feb 7, 2023
1 parent c88d3ad commit e762eb5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class LoginFactory {
public static final String PRE_AUTHENTICATOR = PropsUtil.get("auth.pipeline.pre");

/*Custom Code*/
public static final boolean useCASLoginFilter = Config.getBooleanProperty("FRONTEND_CAS_FILTER_ON", false);
public static final boolean USE_CAS_LOGIN_FILTER = Config.getBooleanProperty("FRONTEND_CAS_FILTER_ON", false);
/*End of Custom Code*/

private static final String LOCK_PREFIX = "UserIdLogin:";
Expand Down Expand Up @@ -138,7 +138,7 @@ public static boolean doLogin(String userName, String password, boolean remember
if ((PRE_AUTHENTICATOR != null) &&
(0 < PRE_AUTHENTICATOR.length()) &&
PRE_AUTHENTICATOR.equals(Config.getStringProperty("LDAP_FRONTEND_AUTH_IMPLEMENTATION")) &&
!useCASLoginFilter) {
!USE_CAS_LOGIN_FILTER) {

int auth = 0;

Expand Down Expand Up @@ -200,7 +200,7 @@ public static boolean doLogin(String userName, String password, boolean remember

} else {
/*Custom code*/
if(useCASLoginFilter){
if(USE_CAS_LOGIN_FILTER){

String userIdFromCAS = (String)request.getSession(false).getAttribute("edu.yale.its.tp.cas.client.filter.user");

Expand Down
33 changes: 23 additions & 10 deletions dotCMS/src/main/java/com/liferay/portal/ejb/UserManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -569,16 +569,7 @@ private int authenticate(final String companyId, String login, final String pass
}
}
if (authResult == Authenticator.FAILURE) {
Logger.debug(this, String.format("Authentication for user '%s' has failed.", login));
try {
this.runCustomOnFailureHandlers(companyId, login, byEmailAddress);
this.handleFailedLoginAttempt(user, login, companyId, byEmailAddress);
} catch (final Exception e) {
final String errorMsg = String.format("An error occurred when handling failed login for User '%s': " +
"%s", login, e.getMessage());
Logger.debug(this, errorMsg, e);
Logger.error(this, errorMsg, e);
}
this.processFailedLogin(user, login, companyId, byEmailAddress);
}
return authResult;
}
Expand Down Expand Up @@ -698,6 +689,28 @@ private void checkUserStatus(final User user) throws UserActiveException {
}
}

/**
* Executes the optional custom on-failure handlers and updates the User information after a failed login attempt.
*
* @param user The {@link User} that failed to log in.
* @param login The user's email or ID.
* @param companyId The current Company ID.
* @param byEmailAddress If the current authentication method is via email, set this to {@code true}. If it's
* done via User ID, set to {@code false}.
*/
private void processFailedLogin(final User user, final String login, final String companyId,
final boolean byEmailAddress) {
Logger.debug(this, String.format("Authentication for user '%s' has failed.", login));
try {
this.runCustomOnFailureHandlers(companyId, login, byEmailAddress);
this.handleFailedLoginAttempt(user, login, companyId, byEmailAddress);
} catch (final Exception e) {
final String errorMsg = String.format("An error occurred when handling failed login for User '%s': " +
"%s", login, e.getMessage());
Logger.error(this, errorMsg, e);
}
}

/**
* Executes the list of custom failure handlers. They can be executed after a given User has failed to authenticate.
* It can be specified via the following property: {@link PropsUtil#AUTH_FAILURE}.
Expand Down

0 comments on commit e762eb5

Please sign in to comment.