Search in sources :

Example 1 with AuthenticationDetails

use of com.haulmont.cuba.security.auth.AuthenticationDetails in project cuba by cuba-platform.

the class IdpServiceBean method login.

@Nonnull
@Override
public IdpLoginResult login(String login, String password, Locale locale, @Nullable Map<String, Object> parameters) throws LoginException {
    log.debug("Authenticating CUBA user for IDP");
    LoginPasswordCredentials credentials = new LoginPasswordCredentials(login, password, locale, parameters);
    AuthenticationDetails sessionDetails = authenticationManager.authenticate(credentials);
    User user = sessionDetails.getSession().getUser();
    IdpSession session = new IdpSession(createIdpSessionId());
    session.setLogin(user.getLogin());
    session.setEmail(user.getEmail());
    Locale userLocale = locale;
    if (user.getLanguage() != null && !globalConfig.getLocaleSelectVisible()) {
        userLocale = LocaleUtils.toLocale(user.getLanguage());
    }
    session.setLocale(userLocale.toLanguageTag());
    String serviceProviderTicket = sessionStore.putSession(session);
    return new IdpLoginResult(session.getId(), serviceProviderTicket);
}
Also used : User(com.haulmont.cuba.security.entity.User) LoginPasswordCredentials(com.haulmont.cuba.security.auth.LoginPasswordCredentials) IdpSession(com.haulmont.cuba.security.global.IdpSession) AuthenticationDetails(com.haulmont.cuba.security.auth.AuthenticationDetails) Nonnull(javax.annotation.Nonnull)

Example 2 with AuthenticationDetails

use of com.haulmont.cuba.security.auth.AuthenticationDetails in project cuba by cuba-platform.

the class ConnectionImpl method loginInternal.

protected AuthenticationDetails loginInternal(Credentials credentials) throws LoginException {
    Class<? extends Credentials> credentialsClass = credentials.getClass();
    AuthenticationDetails details = null;
    try {
        publishBeforeLoginEvent(credentials);
        List<LoginProvider> providers = getProviders();
        for (LoginProvider provider : providers) {
            if (!provider.supports(credentialsClass)) {
                continue;
            }
            log.trace("Login attempt using {}", provider.getClass().getName());
            try {
                details = provider.login(credentials);
                if (details != null) {
                    log.trace("Login successful for {}", credentials);
                    // publish login success
                    publishUserSessionStartedEvent(credentials, details);
                    return details;
                }
            } catch (LoginException e) {
                // publish auth fail
                publishLoginFailed(credentials, provider, e);
                throw e;
            } catch (RuntimeException re) {
                InternalAuthenticationException ie = new InternalAuthenticationException("Exception is thrown by login provider", re);
                // publish auth fail
                publishLoginFailed(credentials, provider, ie);
                throw ie;
            }
        }
    } finally {
        publishAfterLoginEvent(credentials, details);
    }
    throw new UnsupportedCredentialsException("Unable to find login provider that supports credentials class " + credentialsClass.getName());
}
Also used : AuthenticationDetails(com.haulmont.cuba.security.auth.AuthenticationDetails)

Example 3 with AuthenticationDetails

use of com.haulmont.cuba.security.auth.AuthenticationDetails in project cuba by cuba-platform.

the class ConnectionImpl method login.

@Override
public void login(Credentials credentials) throws LoginException {
    backgroundWorker.checkUIAccess();
    preprocessCredentials(credentials);
    AuthenticationDetails authenticationDetails = loginInternal(credentials);
    ClientUserSession clientUserSession = createSession(authenticationDetails.getSession());
    if (credentials instanceof AnonymousUserCredentials) {
        clientUserSession.setAuthenticated(false);
    } else {
        clientUserSession.setAuthenticated(true);
    }
    UserSession previousSession = getSession();
    setSessionInternal(clientUserSession);
    publishUserConnectedEvent(credentials);
    fireStateChangeListeners(previousSession, clientUserSession);
}
Also used : ClientUserSession(com.haulmont.cuba.client.ClientUserSession) ClientUserSession(com.haulmont.cuba.client.ClientUserSession) AuthenticationDetails(com.haulmont.cuba.security.auth.AuthenticationDetails)

Aggregations

AuthenticationDetails (com.haulmont.cuba.security.auth.AuthenticationDetails)3 ClientUserSession (com.haulmont.cuba.client.ClientUserSession)1 LoginPasswordCredentials (com.haulmont.cuba.security.auth.LoginPasswordCredentials)1 User (com.haulmont.cuba.security.entity.User)1 IdpSession (com.haulmont.cuba.security.global.IdpSession)1 Nonnull (javax.annotation.Nonnull)1