use of com.haulmont.cuba.security.auth.Credentials in project cuba by cuba-platform.
the class BruteForceUserCredentialsChecker method onAuthenticationFailure.
@Order(Events.HIGHEST_PLATFORM_PRECEDENCE + 10)
@EventListener
protected void onAuthenticationFailure(AuthenticationFailureEvent event) throws LoginException {
if (bruteForceProtectionAPI.isBruteForceProtectionEnabled()) {
Credentials credentials = event.getCredentials();
if (credentials instanceof AbstractClientCredentials) {
AbstractClientCredentials clientCredentials = (AbstractClientCredentials) credentials;
if (clientCredentials.isCheckClientPermissions()) {
int loginAttemptsLeft = bruteForceProtectionAPI.registerUnsuccessfulLogin(clientCredentials.getUserIdentifier(), clientCredentials.getIpAddress());
String message;
if (loginAttemptsLeft > 0) {
message = messages.formatMessage(MSG_PACK, "LoginException.loginFailedAttemptsLeft", loginAttemptsLeft);
} else {
message = messages.formatMessage(MSG_PACK, "LoginException.loginAttemptsNumberExceeded", bruteForceProtectionAPI.getBruteForceBlockIntervalSec());
}
throw new LoginException(message);
}
}
}
}
Aggregations