Search in sources :

Example 1 with Credentials

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);
            }
        }
    }
}
Also used : AbstractClientCredentials(com.haulmont.cuba.security.auth.AbstractClientCredentials) LoginException(com.haulmont.cuba.security.global.LoginException) Credentials(com.haulmont.cuba.security.auth.Credentials) AbstractClientCredentials(com.haulmont.cuba.security.auth.AbstractClientCredentials) Order(org.springframework.core.annotation.Order) EventListener(org.springframework.context.event.EventListener)

Aggregations

AbstractClientCredentials (com.haulmont.cuba.security.auth.AbstractClientCredentials)1 Credentials (com.haulmont.cuba.security.auth.Credentials)1 LoginException (com.haulmont.cuba.security.global.LoginException)1 EventListener (org.springframework.context.event.EventListener)1 Order (org.springframework.core.annotation.Order)1