Search in sources :

Example 1 with AnonymousUserCredentials

use of com.haulmont.cuba.security.auth.AnonymousUserCredentials 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)

Aggregations

AnonymousUserCredentials (com.haulmont.cuba.security.auth.AnonymousUserCredentials)1 SimpleAuthenticationDetails (com.haulmont.cuba.security.auth.SimpleAuthenticationDetails)1 User (com.haulmont.cuba.security.entity.User)1 LoginException (com.haulmont.cuba.security.global.LoginException)1 UserSession (com.haulmont.cuba.security.global.UserSession)1 Locale (java.util.Locale)1 UUID (java.util.UUID)1