@Test public void strategiesAreRebuildInCaseOfReset() { when(configuration.getFailureStrategies()).thenReturn(new String[] { "strategy1" }); when(configuration.getMaxAuthorizedAttempts()).thenReturn(1); this.defaultAuthenticationFailureManager.recordAuthenticationFailure("foo"); verify(configuration, times(3)).getFailureStrategies(); verify(strategy1, times(1)).notify("foo"); verify(strategy2, never()).notify(any()); when(configuration.getFailureStrategies()).thenReturn(new String[] { "strategy2" }); this.defaultAuthenticationFailureManager.recordAuthenticationFailure("foo"); verify(configuration, times(6)).getFailureStrategies(); verify(strategy1, times(1)).notify("foo"); verify(strategy2, times(1)).notify(any()); }
@Override public boolean recordAuthenticationFailure(String username) { observationManager.notify(AUTHENTICATION_FAILURE_EVENT, username); if (!isAuthenticationSecurityEnabled()) { this.authFailures.clear(); return false; } if (authFailures.containsKey(username)) { authFailures.get(username).incrementAttemptOrReset(); } else { authFailures.put(username, new AuthFailureRecord()); DocumentReference userReference = findUser(username); if (userReference != null) { userAndAssociatedUsernames.put(userReference, username); } } boolean isThresholdReached = authFailures.get(username).isThresholdReached(); if (isThresholdReached) { for (AuthenticationFailureStrategy authenticationFailureStrategy : getFailureStrategyList()) { authenticationFailureStrategy.notify(username); } observationManager.notify(AUTHENTICATION_FAILURE_LIMIT_REACHED_EVENT, username); } return isThresholdReached; }
DefaultAuthenticationFailureManager implements AuthenticationFailureManager { @Override public boolean recordAuthenticationFailure(String username) { observationManager.notify(AUTHENTICATION_FAILURE_EVENT, username); if (!isAuthenticationSecurityEnabled()) { this.authFailures.clear(); return false; } if (authFailures.containsKey(username)) { authFailures.get(username).incrementAttemptOrReset(); } else { authFailures.put(username, new AuthFailureRecord()); DocumentReference userReference = findUser(username); if (userReference != null) { userAndAssociatedUsernames.put(userReference, username); } } boolean isThresholdReached = authFailures.get(username).isThresholdReached(); if (isThresholdReached) { for (AuthenticationFailureStrategy authenticationFailureStrategy : getFailureStrategyList()) { authenticationFailureStrategy.notify(username); } observationManager.notify(AUTHENTICATION_FAILURE_LIMIT_REACHED_EVENT, username); } return isThresholdReached; } }
DefaultAuthenticationFailureManager implements AuthenticationFailureManager { @Override public boolean recordAuthenticationFailure(String username) { observationManager.notify(AUTHENTICATION_FAILURE_EVENT, username); if (!isAuthenticationSecurityEnabled()) { this.authFailures.clear(); return false; } if (authFailures.containsKey(username)) { authFailures.get(username).incrementAttemptOrReset(); } else { authFailures.put(username, new AuthFailureRecord()); DocumentReference userReference = findUser(username); if (userReference != null) { userAndAssociatedUsernames.put(userReference, username); } } boolean isThresholdReached = authFailures.get(username).isThresholdReached(); if (isThresholdReached) { for (AuthenticationFailureStrategy authenticationFailureStrategy : getFailureStrategyList()) { authenticationFailureStrategy.notify(username); } observationManager.notify(AUTHENTICATION_FAILURE_LIMIT_REACHED_EVENT, username); } return isThresholdReached; } DefaultAuthenticationFailureManager(); }
DefaultAuthenticationFailureManager implements AuthenticationFailureManager { @Override public boolean recordAuthenticationFailure(String username) { observationManager.notify(AUTHENTICATION_FAILURE_EVENT, username); if (!isAuthenticationSecurityEnabled()) { this.authFailures.clear(); return false; } if (authFailures.containsKey(username)) { authFailures.get(username).incrementAttemptOrReset(); } else { authFailures.put(username, new AuthFailureRecord()); DocumentReference userReference = findUser(username); if (userReference != null) { userAndAssociatedUsernames.put(userReference, username); } } boolean isThresholdReached = authFailures.get(username).isThresholdReached(); if (isThresholdReached) { for (AuthenticationFailureStrategy authenticationFailureStrategy : getFailureStrategyList()) { authenticationFailureStrategy.notify(username); } observationManager.notify(AUTHENTICATION_FAILURE_LIMIT_REACHED_EVENT, username); } return isThresholdReached; } DefaultAuthenticationFailureManager(); @Override boolean recordAuthenticationFailure(String username); @Override void resetAuthenticationFailureCounter(DocumentReference user); @Override void resetAuthenticationFailureCounter(String username); @Override String getForm(String username); @Override boolean validateForm(String username, SecurityRequestWrapper request); @Override String getErrorMessage(String username); @Override DocumentReference findUser(String username); }
DefaultAuthenticationFailureManager implements AuthenticationFailureManager { @Override public boolean recordAuthenticationFailure(String username) { observationManager.notify(AUTHENTICATION_FAILURE_EVENT, username); if (!isAuthenticationSecurityEnabled()) { this.authFailures.clear(); return false; } if (authFailures.containsKey(username)) { authFailures.get(username).incrementAttemptOrReset(); } else { authFailures.put(username, new AuthFailureRecord()); DocumentReference userReference = findUser(username); if (userReference != null) { userAndAssociatedUsernames.put(userReference, username); } } boolean isThresholdReached = authFailures.get(username).isThresholdReached(); if (isThresholdReached) { for (AuthenticationFailureStrategy authenticationFailureStrategy : getFailureStrategyList()) { authenticationFailureStrategy.notify(username); } observationManager.notify(AUTHENTICATION_FAILURE_LIMIT_REACHED_EVENT, username); } return isThresholdReached; } DefaultAuthenticationFailureManager(); @Override boolean recordAuthenticationFailure(String username); @Override void resetAuthenticationFailureCounter(DocumentReference user); @Override void resetAuthenticationFailureCounter(String username); @Override String getForm(String username); @Override boolean validateForm(String username, SecurityRequestWrapper request); @Override String getErrorMessage(String username); @Override DocumentReference findUser(String username);  }