Search in sources :

Example 1 with ClientType

use of com.haulmont.cuba.core.global.ClientType in project cuba by cuba-platform.

the class ClientTypeUserAccessChecker method check.

@Override
public void check(Credentials credentials, AuthenticationDetails authenticationDetails) throws LoginException {
    if (credentials instanceof AbstractClientCredentials) {
        AbstractClientCredentials clientCredentials = (AbstractClientCredentials) credentials;
        if (clientCredentials.isCheckClientPermissions()) {
            ClientType clientType = clientCredentials.getClientType();
            if (ClientType.DESKTOP == clientType || ClientType.WEB == clientType) {
                if (!authenticationDetails.getSession().isSpecificPermitted("cuba.gui.loginToClient")) {
                    log.warn("Attempt of login to {} for user '{}' without cuba.gui.loginToClient permission", clientType, clientCredentials);
                    Locale userLocale;
                    if (clientCredentials.getLocale() != null) {
                        userLocale = clientCredentials.getLocale();
                    } else {
                        userLocale = messages.getTools().getDefaultLocale();
                    }
                    throw new LoginException(getInvalidCredentialsMessage(clientCredentials.getUserIdentifier(), userLocale));
                }
            }
        }
    }
}
Also used : Locale(java.util.Locale) ClientType(com.haulmont.cuba.core.global.ClientType) AbstractClientCredentials(com.haulmont.cuba.security.auth.AbstractClientCredentials) LoginException(com.haulmont.cuba.security.global.LoginException)

Example 2 with ClientType

use of com.haulmont.cuba.core.global.ClientType 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)

Aggregations

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