List of usage examples for com.vaadin.server VaadinService getCurrentRequest
public static VaadinRequest getCurrentRequest()
From source file:com.haulmont.cuba.web.DefaultApp.java
License:Apache License
@Override public void connectionStateChanged(StateChangeEvent event) { Connection connection = event.getSource(); log.debug("connectionStateChanged connected: {}, authenticated: {}", connection.isConnected(), connection.isAuthenticated()); cleanupBackgroundTasks();//from w ww . j a v a2 s. c o m 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()); } }
From source file:com.haulmont.cuba.web.DefaultApp.java
License:Apache License
protected void preventSessionFixation(Connection connection, UserSession userSession) { if (connection.isAuthenticated() && !isLoggedInWithExternalAuth(userSession) && webConfig.getUseSessionFixationProtection() && VaadinService.getCurrentRequest() != null) { VaadinService.reinitializeSession(VaadinService.getCurrentRequest()); WrappedSession session = VaadinSession.getCurrent().getSession(); int timeout = webConfig.getHttpSessionExpirationTimeoutSec(); session.setMaxInactiveInterval(timeout); HttpSession httpSession = session instanceof WrappedHttpSession ? ((WrappedHttpSession) session).getHttpSession() : null;//from ww w .j a v a2 s. c o m log.debug("Session reinitialized: HttpSession={}, timeout={}sec, UserSession={}", httpSession, timeout, connection.getSession()); } }
From source file:com.haulmont.cuba.web.security.ConnectionImpl.java
License:Apache License
@Nullable protected String getUserRemoteAddress() { VaadinRequest currentRequest = VaadinService.getCurrentRequest(); String userRemoteAddress = null; if (currentRequest != null) { String xForwardedFor = currentRequest.getHeader("X_FORWARDED_FOR"); if (StringUtils.isNotBlank(xForwardedFor)) { String[] strings = xForwardedFor.split(","); String userAddressFromHeader = StringUtils.trimToEmpty(strings[strings.length - 1]); if (StringUtils.isNotEmpty(userAddressFromHeader)) { userRemoteAddress = userAddressFromHeader; } else { userRemoteAddress = currentRequest.getRemoteAddr(); }/* ww w . j a va 2s . c o m*/ } else { userRemoteAddress = currentRequest.getRemoteAddr(); } } return userRemoteAddress; }
From source file:com.haulmont.cuba.web.security.ConnectionImpl.java
License:Apache License
protected WebBrowser getWebBrowserDetails() { // timezone info is passed only on VaadinSession creation WebBrowser webBrowser = VaadinSession.getCurrent().getBrowser(); VaadinRequest currentRequest = VaadinService.getCurrentRequest(); // update web browser instance if current request is not null // it can be null in case of background/async processing of login request if (currentRequest != null) { webBrowser.updateRequestDetails(currentRequest); }/*from w ww . j a v a 2 s .co m*/ return webBrowser; }
From source file:com.haulmont.cuba.web.security.idp.IdpLoginLifecycleManager.java
License:Apache License
@Order(Events.HIGHEST_PLATFORM_PRECEDENCE + 10) @EventListener/* w w w .j a v a 2s. c o m*/ protected void onAppStarted(AppStartedEvent event) throws LoginException { Connection connection = event.getApp().getConnection(); // can be already authenticated by another event listener if (webIdpConfig.getIdpEnabled() && !connection.isAuthenticated()) { VaadinRequest currentRequest = VaadinService.getCurrentRequest(); if (currentRequest != null) { Principal principal = currentRequest.getUserPrincipal(); if (principal instanceof IdpSessionPrincipal) { IdpSession idpSession = ((IdpSessionPrincipal) principal).getIdpSession(); Locale locale = event.getApp().getLocale(); ExternalUserCredentials credentials = new ExternalUserCredentials(principal.getName(), locale); credentials.setSessionAttributes( ImmutableMap.of(IdpService.IDP_USER_SESSION_ATTRIBUTE, idpSession.getId())); connection.login(credentials); } } } }
From source file:com.haulmont.cuba.web.sys.LinkHandler.java
License:Apache License
/** * Called to handle the link./*from w ww. j a v a 2 s. c o m*/ */ public void handle() { try { String folderId = requestParams.get("folder"); if (!StringUtils.isEmpty(folderId)) { AbstractSearchFolder folder = loadFolder(UUID.fromString(folderId)); if (folder != null) { folders.openFolder(folder); } else { log.warn("Folder not found: {}", folderId); } return; } String screenName = requestParams.get("screen"); if (screenName == null) { log.warn("ScreenId not found in request parameters"); return; } WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME); final WindowInfo windowInfo = windowConfig.getWindowInfo(screenName); if (windowInfo == null) { log.warn("WindowInfo not found for screen: {}", screenName); return; } UUID userId = getUUID(requestParams.get("user")); UserSession userSession = app.getConnection().getSession(); if (userSession == null) { log.warn("No user session"); return; } if (!(userId == null || userSession.getCurrentOrSubstitutedUser().getId().equals(userId))) { substituteUserAndOpenWindow(windowInfo, userId); } else { openWindow(windowInfo, requestParams); } } catch (AccessDeniedException e) { accessDeniedHandler.handle(e, app.getWindowManager()); } catch (NoSuchScreenException e) { noSuchScreenHandler.handle(e, app.getWindowManager()); } catch (EntityAccessException e) { entityAccessExceptionHandler.handle(e, app.getWindowManager()); } finally { VaadinRequest request = VaadinService.getCurrentRequest(); WrappedSession wrappedSession = request.getWrappedSession(); wrappedSession.removeAttribute(AppUI.LAST_REQUEST_PARAMS_ATTR); wrappedSession.removeAttribute(AppUI.LAST_REQUEST_ACTION_ATTR); } }
From source file:com.haulmont.cuba.web.sys.remoting.discovery.WebHttpSessionUrlsHolder.java
License:Apache License
@SuppressWarnings("unchecked") @Override/* w w w . j a va 2s . c o m*/ @Nullable public List<String> getUrls(String selectorId) { VaadinRequest vaadinRequest = VaadinService.getCurrentRequest(); if (vaadinRequest != null) return (List) vaadinRequest.getWrappedSession().getAttribute(getAttributeName(selectorId)); else { HttpSession httpSession = getHttpSession(); return httpSession != null ? (List<String>) httpSession.getAttribute(getAttributeName(selectorId)) : null; } }
From source file:com.haulmont.cuba.web.sys.remoting.discovery.WebHttpSessionUrlsHolder.java
License:Apache License
@Override public void setUrls(String selectorId, List<String> urls) { VaadinRequest vaadinRequest = VaadinService.getCurrentRequest(); if (vaadinRequest != null) vaadinRequest.getWrappedSession().setAttribute(getAttributeName(selectorId), urls); else {/*w ww .java 2 s. c om*/ HttpSession httpSession = getHttpSession(); if (httpSession != null) { httpSession.setAttribute(getAttributeName(selectorId), urls); } } }
From source file:com.haulmont.cuba.web.toolkit.ui.CubaMultiUpload.java
License:Apache License
@Override public void beforeClientResponse(boolean initial) { VaadinRequest currentRequest = VaadinService.getCurrentRequest(); if (currentRequest != null) { getState().jsessionId = currentRequest.getWrappedSession().getId(); } else {//from w w w .j av a 2 s.c o m LoggerFactory.getLogger(CubaMultiUpload.class).debug("Unable to set JSESSIONID for widget"); } super.beforeClientResponse(initial); }
From source file:com.hybridbpm.ui.HybridbpmUI.java
License:Apache License
public void login(String username, String password, boolean rememberMe) { try {//from w w w . j a va2s .c o m user = AccessAPI.get(null, null).login(username, password); updateContent(); subscribe(); getBpmAPI().notifyTaskList(); if (rememberMe) { CookieManager.setCookie(COOKIENAME_USERNAME, user.getUsername(), VaadinService.getCurrentRequest().getContextPath()); } } catch (Exception ex) { logger.log(Level.SEVERE, ex.getMessage(), ex); Notification.show("Error", ex.getMessage(), Notification.Type.ERROR_MESSAGE); } }