use of com.haulmont.cuba.web.security.AnonymousUserCredentials in project cuba by cuba-platform.
the class DefaultApp method connectionStateChanged.
@Override
public void connectionStateChanged(StateChangeEvent event) {
Connection connection = event.getSource();
log.debug("connectionStateChanged connected: {}, authenticated: {}", connection.isConnected(), connection.isAuthenticated());
cleanupBackgroundTasks();
closeAllWindows();
clearSettingsCache();
if (connection.isConnected()) {
UserSession userSession = connection.getSessionNN();
setLocale(userSession.getLocale());
// substitution listeners are cleared by connection on logout
connection.addUserSubstitutionListener(this);
preventSessionFixation(connection, userSession);
initExceptionHandlers(true);
initializeUi();
if (linkHandler != null && linkHandler.canHandleLink()) {
linkHandler.handle();
linkHandler = null;
}
afterLoggedIn();
publishAppLoggedInEvent();
} else {
initExceptionHandlers(false);
VaadinRequest currentRequest = VaadinService.getCurrentRequest();
if (currentRequest != null) {
Locale requestLocale = currentRequest.getLocale();
setLocale(resolveLocale(requestLocale));
}
try {
connection.login(new AnonymousUserCredentials(getLocale()));
} catch (LoginException e) {
throw new RuntimeException("Unable to login as anonymous!");
}
publishAppLoggedOutEvent(event.getPreviousSession());
}
}
use of com.haulmont.cuba.web.security.AnonymousUserCredentials 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