Search in sources :

Example 1 with SimpleAuthenticationDetails

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

the class AnonymousAuthenticationProvider method authenticate.

@Override
public AuthenticationDetails authenticate(Credentials credentials) throws LoginException {
    AnonymousUserCredentials anonymous = (AnonymousUserCredentials) credentials;
    String login = serverConfig.getAnonymousLogin();
    Locale credentialsLocale = anonymous.getLocale() == null ? messages.getTools().trimLocale(messages.getTools().getDefaultLocale()) : anonymous.getLocale();
    User user = loadUser(login);
    if (user == null) {
        throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale));
    }
    Locale userLocale = getUserLocale(anonymous, user);
    UUID anonymousSessionId = globalConfig.getAnonymousSessionId();
    UserSession session = createSession(anonymous, user, userLocale, anonymousSessionId);
    session.setClientInfo("System anonymous session");
    return new SimpleAuthenticationDetails(session);
}
Also used : Locale(java.util.Locale) User(com.haulmont.cuba.security.entity.User) UserSession(com.haulmont.cuba.security.global.UserSession) SimpleAuthenticationDetails(com.haulmont.cuba.security.auth.SimpleAuthenticationDetails) LoginException(com.haulmont.cuba.security.global.LoginException) UUID(java.util.UUID) AnonymousUserCredentials(com.haulmont.cuba.security.auth.AnonymousUserCredentials)

Example 2 with SimpleAuthenticationDetails

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

the class SystemAuthenticationProvider method authenticate.

@Override
public AuthenticationDetails authenticate(Credentials credentials) throws LoginException {
    SystemUserCredentials systemLogin = (SystemUserCredentials) credentials;
    String login = systemLogin.getLogin();
    Locale credentialsLocale = systemLogin.getLocale() == null ? messages.getTools().getDefaultLocale() : systemLogin.getLocale();
    User user = loadUser(login);
    if (user == null) {
        throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale));
    }
    Locale userLocale = getUserLocale(systemLogin, user);
    UserSession session = userSessionManager.createSession(user, userLocale, true);
    return new SimpleAuthenticationDetails(session);
}
Also used : Locale(java.util.Locale) User(com.haulmont.cuba.security.entity.User) SystemUserCredentials(com.haulmont.cuba.security.auth.SystemUserCredentials) UserSession(com.haulmont.cuba.security.global.UserSession) SimpleAuthenticationDetails(com.haulmont.cuba.security.auth.SimpleAuthenticationDetails) LoginException(com.haulmont.cuba.security.global.LoginException)

Example 3 with SimpleAuthenticationDetails

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

the class AnonymousLoginProvider method login.

@SuppressWarnings("RedundantThrows")
@Nullable
@Override
public AuthenticationDetails login(Credentials credentials) throws LoginException {
    if (!(credentials instanceof AnonymousUserCredentials)) {
        throw new ClassCastException("Credentials cannot be cast to AnonymousUserCredentials");
    }
    AnonymousUserCredentials anonymousCredentials = (AnonymousUserCredentials) credentials;
    UserSession anonymousSession = anonymousSessionHolder.getAnonymousSession();
    Locale credentialsLocale = anonymousCredentials.getLocale();
    if (credentialsLocale != null) {
        anonymousSession.setLocale(credentialsLocale);
    }
    if (anonymousCredentials.getTimeZone() != null && Boolean.TRUE.equals(anonymousSession.getUser().getTimeZoneAuto())) {
        anonymousSession.setTimeZone(anonymousCredentials.getTimeZone());
    }
    anonymousSession.setAddress(anonymousCredentials.getIpAddress());
    anonymousSession.setClientInfo(anonymousCredentials.getClientInfo());
    if (anonymousCredentials.getSessionAttributes() != null) {
        for (Map.Entry<String, Serializable> attribute : anonymousCredentials.getSessionAttributes().entrySet()) {
            anonymousSession.setAttribute(attribute.getKey(), attribute.getValue());
        }
    }
    return new SimpleAuthenticationDetails(anonymousSession);
}
Also used : Locale(java.util.Locale) Serializable(java.io.Serializable) UserSession(com.haulmont.cuba.security.global.UserSession) SimpleAuthenticationDetails(com.haulmont.cuba.security.auth.SimpleAuthenticationDetails) Map(java.util.Map) AnonymousUserCredentials(com.haulmont.cuba.web.security.AnonymousUserCredentials) Nullable(javax.annotation.Nullable)

Aggregations

SimpleAuthenticationDetails (com.haulmont.cuba.security.auth.SimpleAuthenticationDetails)3 UserSession (com.haulmont.cuba.security.global.UserSession)3 Locale (java.util.Locale)3 User (com.haulmont.cuba.security.entity.User)2 LoginException (com.haulmont.cuba.security.global.LoginException)2 AnonymousUserCredentials (com.haulmont.cuba.security.auth.AnonymousUserCredentials)1 SystemUserCredentials (com.haulmont.cuba.security.auth.SystemUserCredentials)1 AnonymousUserCredentials (com.haulmont.cuba.web.security.AnonymousUserCredentials)1 Serializable (java.io.Serializable)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Nullable (javax.annotation.Nullable)1