Search in sources :

Example 1 with InternalAuthenticationException

use of com.haulmont.cuba.security.global.InternalAuthenticationException in project cuba by cuba-platform.

the class AuthenticationServiceBean method login.

@Nonnull
@Override
public AuthenticationDetails login(Credentials credentials) throws LoginException {
    try {
        preprocessCredentials(credentials);
        // noinspection UnnecessaryLocalVariable
        AuthenticationDetails details = authenticationManager.login(credentials);
        Map<String, Object> logParams = emptyMap();
        if (credentials instanceof AbstractClientCredentials) {
            ClientType clientType = ((AbstractClientCredentials) credentials).getClientType();
            if (clientType != null) {
                logParams = ParamsMap.of(ClientType.class.getName(), clientType.name());
            }
        }
        userSessionLog.createSessionLogRecord(details.getSession(), SessionAction.LOGIN, logParams);
        return details;
    } catch (InternalAuthenticationException ie) {
        log.error("Login error", ie);
        throw ie;
    } catch (LoginException e) {
        log.info("Login failed: {}", e.toString());
        throw e;
    } catch (Throwable e) {
        log.error("Login error", e);
        throw wrapInLoginException(e);
    }
}
Also used : ClientType(com.haulmont.cuba.core.global.ClientType) LoginException(com.haulmont.cuba.security.global.LoginException) InternalAuthenticationException(com.haulmont.cuba.security.global.InternalAuthenticationException) Nonnull(javax.annotation.Nonnull)

Example 2 with InternalAuthenticationException

use of com.haulmont.cuba.security.global.InternalAuthenticationException in project cuba by cuba-platform.

the class AppLoginWindow method doLogin.

protected void doLogin() {
    String login = loginField.getValue();
    String password = passwordField.getValue() != null ? passwordField.getValue() : "";
    if (StringUtils.isEmpty(login) || StringUtils.isEmpty(password)) {
        showNotification(messages.getMainMessage("loginWindow.emptyLoginOrPassword"), NotificationType.WARNING);
        return;
    }
    try {
        Locale selectedLocale = localesSelect.getValue();
        app.setLocale(selectedLocale);
        if (loginByRememberMe && webConfig.getRememberMeEnabled()) {
            doLogin(new RememberMeCredentials(login, password, selectedLocale));
        } else {
            doLogin(new LoginPasswordCredentials(login, password, selectedLocale));
        }
        // locale could be set on the server
        if (connection.getSession() != null) {
            Locale loggedInLocale = connection.getSession().getLocale();
            if (globalConfig.getLocaleSelectVisible()) {
                app.addCookie(App.COOKIE_LOCALE, loggedInLocale.toLanguageTag());
            }
        }
    } catch (InternalAuthenticationException e) {
        log.error("Internal error during login", e);
        showUnhandledExceptionOnLogin(e);
    } catch (LoginException e) {
        log.info("Login failed: {}", e.toString());
        String message = StringUtils.abbreviate(e.getMessage(), 1000);
        showLoginException(message);
    } catch (Exception e) {
        log.warn("Unable to login", e);
        showUnhandledExceptionOnLogin(e);
    }
}
Also used : Locale(java.util.Locale) RememberMeCredentials(com.haulmont.cuba.security.auth.RememberMeCredentials) LoginPasswordCredentials(com.haulmont.cuba.security.auth.LoginPasswordCredentials) LoginException(com.haulmont.cuba.security.global.LoginException) InternalAuthenticationException(com.haulmont.cuba.security.global.InternalAuthenticationException) InternalAuthenticationException(com.haulmont.cuba.security.global.InternalAuthenticationException) LoginException(com.haulmont.cuba.security.global.LoginException)

Aggregations

InternalAuthenticationException (com.haulmont.cuba.security.global.InternalAuthenticationException)2 LoginException (com.haulmont.cuba.security.global.LoginException)2 ClientType (com.haulmont.cuba.core.global.ClientType)1 LoginPasswordCredentials (com.haulmont.cuba.security.auth.LoginPasswordCredentials)1 RememberMeCredentials (com.haulmont.cuba.security.auth.RememberMeCredentials)1 Locale (java.util.Locale)1 Nonnull (javax.annotation.Nonnull)1