use of com.haulmont.cuba.security.global.UserSession 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.security.global.UserSession in project cuba by cuba-platform.
the class BaseIdpSessionFilter method getWebAppUrl.
protected String getWebAppUrl() {
if (webAppUrl == null) {
synchronized (this) {
if (webAppUrl == null) {
UserSession systemSession;
try {
systemSession = trustedClientService.getSystemSession(webAuthConfig.getTrustedClientPassword());
} catch (LoginException e) {
throw new RuntimeException("Unable to get systemSession", e);
}
// webAppUrl can be overridden in DB, thus we need SecurityContext to obtain it from middleware
withSecurityContext(new SecurityContext(systemSession), () -> {
String webAppUrl = globalConfig.getWebAppUrl();
if (!webAppUrl.endsWith("/")) {
webAppUrl += "/";
}
this.webAppUrl = webAppUrl;
});
}
}
}
return this.webAppUrl;
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class WebUserSessionSource method getUserSessionFromMiddleware.
protected UserSession getUserSessionFromMiddleware(UUID sessionId) {
UserSession userSession = null;
HttpServletRequest request = null;
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes instanceof ServletRequestAttributes) {
request = ((ServletRequestAttributes) requestAttributes).getRequest();
}
if (request != null) {
userSession = (UserSession) request.getAttribute(REQUEST_ATTR);
}
if (userSession != null) {
return userSession;
}
userSession = userSessionService.getUserSession(sessionId);
if (request != null) {
request.setAttribute(REQUEST_ATTR, userSession);
}
return userSession;
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class UserSwitchLinkHandlerProcessor method handle.
@Override
public void handle(ExternalLinkContext linkContext) {
UUID userId = getUUID(linkContext.getRequestParams().get("user"));
assert userId != null;
UserSession userSession = App.getInstance().getConnection().getSession();
if (userSession == null) {
log.warn("No user session");
return;
}
if (!userSession.getCurrentOrSubstitutedUser().getId().equals(userId)) {
substituteUserAndOpenWindow(linkContext, userId);
} else {
screenHandler.handle(linkContext);
}
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class MainTabSheetActionHandler method getActions.
@Override
public Action[] getActions(Object target, Object sender) {
if (!initialized) {
Messages messages = AppBeans.get(Messages.NAME);
closeAllTabs = new com.vaadin.event.Action(messages.getMainMessage("actions.closeAllTabs"));
closeOtherTabs = new com.vaadin.event.Action(messages.getMainMessage("actions.closeOtherTabs"));
closeCurrentTab = new com.vaadin.event.Action(messages.getMainMessage("actions.closeCurrentTab"));
showInfo = new com.vaadin.event.Action(messages.getMainMessage("actions.showInfo"));
analyzeLayout = new com.vaadin.event.Action(messages.getMainMessage("actions.analyzeLayout"));
saveSettings = new com.vaadin.event.Action(messages.getMainMessage("actions.saveSettings"));
restoreToDefaults = new com.vaadin.event.Action(messages.getMainMessage("actions.restoreToDefaults"));
initialized = true;
}
List<Action> actions = new ArrayList<>(5);
actions.add(closeCurrentTab);
actions.add(closeOtherTabs);
actions.add(closeAllTabs);
if (target != null) {
Configuration configuration = AppBeans.get(Configuration.NAME);
ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
if (clientConfig.getManualScreenSettingsSaving()) {
actions.add(saveSettings);
actions.add(restoreToDefaults);
}
UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
UserSession userSession = sessionSource.getUserSession();
if (userSession.isSpecificPermitted(ShowInfoAction.ACTION_PERMISSION) && findEditor((Layout) target) != null) {
actions.add(showInfo);
}
if (clientConfig.getLayoutAnalyzerEnabled()) {
actions.add(analyzeLayout);
}
}
return actions.toArray(new com.vaadin.event.Action[actions.size()]);
}
Aggregations