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);
}
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);
}
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);
}
Aggregations