private static String getSessionDetails(VaadinSession session) { if (session == null) { return null; } else { return session + " for " + session.getService().getServiceName(); } }
/** * Gets the router used for navigating in this UI, if the router was active * when this UI was initialized. * * @return the router used for this UI, or <code>null</code> if there is no * router */ public Router getRouter() { return getSession().getService().getRouter(); }
private String translateTheme(String importValue) { if (theme != null) { VaadinService service = session.getService(); WebBrowser browser = session.getBrowser(); Optional<String> themedUrl = service.getThemedUrl(importValue, browser, theme); return themedUrl.orElse(importValue); } else { Matcher componentMatcher = componentSource.matcher(importValue); if (componentMatcher.matches()) { String componentName = componentMatcher.group(1); getLogger().trace( "Vaadin component '{}' is used and missing theme definition.", componentName); } } return importValue; }
return getService().accessSession(this, command);
/** * Gets the instantiator to use for the given UI. * * @param ui * the attached UI for which to find an instantiator, not * <code>null</code> * @return the instantiator, not <code>null</code> */ static Instantiator get(UI ui) { assert ui != null; VaadinSession session = ui.getSession(); assert session != null; return session.getService().getInstantiator(); }
protected void setupPushConnectionFactory( PushConfiguration pushConfiguration, BootstrapContext context) { VaadinService service = context.getSession().getService(); Iterator<PushConnectionFactory> iter = ServiceLoader .load(PushConnectionFactory.class, service.getClassLoader()) .iterator(); if (iter.hasNext()) { pushConfiguration.setPushConnectionFactory(iter.next()); if (iter.hasNext()) { throw new BootstrapException( "Multiple " + PushConnectionFactory.class.getName() + " implementations found"); } } }
/** * Sets current instances for the {@link VaadinSession} and all related * classes. The previously defined values can be restored by passing the * returned map to {@link #restoreInstances(Map)}. * * * @param session * The VaadinSession * @return A map containing the old values of the instances this method * updated. */ public static Map<Class<?>, CurrentInstance> setCurrent( VaadinSession session) { Map<Class<?>, CurrentInstance> old = new HashMap<>(); old.put(VaadinSession.class, doSet(VaadinSession.class, session)); VaadinService service = null; if (session != null) { service = session.getService(); } old.put(VaadinService.class, doSet(VaadinService.class, service)); return old; }
/** * Get the session registry for VaadinSession. If no SessionRegistry exists * then one will be created for given VaadinSession. * * @param session * vaadin session to get registry for * @return session registry for given session */ public static RouteRegistry getSessionRegistry(VaadinSession session) { Objects.requireNonNull(session, "Null session is not supported for session route registry"); SessionRouteRegistry registry = session .getAttribute(SessionRouteRegistry.class); if (registry == null) { registry = new SessionRouteRegistry(session, session.getService()); session.setAttribute(SessionRouteRegistry.class, registry); } if (!registry.session.equals(session)) { throw new IllegalStateException( "Session has as the attribute a route registered to another session"); } return registry; }
private SessionBeanStore(VaadinSession session) { super(session); if (session instanceof SpringVaadinSession) { sessionDestroyListenerRegistration = null; ((SpringVaadinSession) session) .addDestroyListener(event -> destroy()); } else { sessionDestroyListenerRegistration = session.getService() .addSessionDestroyListener(event -> destroy()); } }
/** * Verifies that the given CSRF token (aka double submit cookie) is valid * for the given session. This is used to protect against Cross Site Request * Forgery attacks. * <p> * This protection is enabled by default, but it might need to be disabled * to allow a certain type of testing. For these cases, the check can be * disabled by setting the init parameter * <code>disable-xsrf-protection</code> to <code>true</code>. * * @param session * the vaadin session for which the check should be done * @param requestToken * the CSRF token provided in the request * @return <code>true</code> if the token is valid or if the protection is * disabled; <code>false</code> if protection is enabled and the * token is invalid * @see DeploymentConfiguration#isXsrfProtectionEnabled() */ public static boolean isCsrfTokenValid(VaadinSession session, String requestToken) { if (session.getService().getDeploymentConfiguration() .isXsrfProtectionEnabled()) { String sessionToken = session.getCsrfToken(); if (sessionToken == null || !sessionToken.equals(requestToken)) { return false; } } return true; }
private UIStoreWrapper(VaadinSession session) { assert session.hasLock(); uiStores = new HashMap<>(); this.session = session; if (session instanceof SpringVaadinSession) { sessionDestroyListenerRegistration = null; ((SpringVaadinSession) session) .addDestroyListener(event -> destroy()); } else { sessionDestroyListenerRegistration = session.getService() .addSessionDestroyListener(event -> destroy()); } }
private UIStoreWrapper(VaadinSession session) { assert session.hasLock(); uiStores = new HashMap<>(); this.session = session; if (session instanceof SpringVaadinSession) { sessionDestroyListenerRegistration = null; ((SpringVaadinSession) session) .addDestroyListener(event -> destroy()); } else { sessionDestroyListenerRegistration = session.getService() .addSessionDestroyListener(event -> destroy()); } }
private SessionBeanStore(VaadinSession session) { super(session); if (session instanceof SpringVaadinSession) { sessionDestroyListenerRegistration = null; ((SpringVaadinSession) session) .addDestroyListener(event -> destroy()); } else { sessionDestroyListenerRegistration = session.getService() .addSessionDestroyListener(event -> destroy()); } }
@Override public boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { UI uI = session.getService().findUI(request); if (uI == null) {
/** * Handles a heartbeat request for the given session. Reads the GET * parameter named {@link ApplicationConstants#UI_ID_PARAMETER} to identify * the UI. If the UI is found in the session, sets it * {@link UIInternals#getLastHeartbeatTimestamp() heartbeat timestamp} to * the current time. Otherwise, writes a HTTP Not Found error to the * response. */ @Override public boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { UI ui = session.getService().findUI(request); if (ui != null) { ui.getInternals() .setLastHeartbeatTimestamp(System.currentTimeMillis()); // Ensure that the browser does not cache heartbeat responses. // iOS 6 Safari requires this (#10370) response.setHeader("Cache-Control", "no-cache"); // If Content-Type is not set, browsers assume text/html and may // complain about the empty response body (#12182) response.setHeader("Content-Type", "text/plain"); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND, "UI not found"); } return true; }
/** * Adds the dependencies defined using {@link StyleSheet}, * {@link JavaScript} or {@link HtmlImport} on the given Component class. * * @param componentClass * the component class to read annotations from */ public void addComponentDependencies( Class<? extends Component> componentClass) { Page page = ui.getPage(); DependencyInfo dependencies = ComponentUtil .getDependencies(session.getService(), componentClass); dependencies.getHtmlImports() .forEach(html -> addHtmlImport(html, page)); dependencies.getJavaScripts() .forEach(js -> page.addJavaScript(js.value(), js.loadMode())); dependencies.getStyleSheets().forEach(styleSheet -> page .addStyleSheet(styleSheet.value(), styleSheet.loadMode())); }
getSession().getService().runPendingAccessTasks(getSession());
@Override public void setPushMode(PushMode pushMode) { if (pushMode == null) { throw new IllegalArgumentException("Push mode cannot be null"); } VaadinSession session = ui.getSession(); if (session == null) { throw new UIDetachedException( "Cannot set the push mode for a detached UI"); } session.checkHasLock(); if (pushMode.isEnabled() && !session.getService().ensurePushAvailable()) { throw new IllegalStateException( "Push is not available. See previous log messages for more information."); } PushMode oldMode = getPushConfigurationMap().getPushMode(); if (oldMode != pushMode) { getPushConfigurationMap().setPushMode(pushMode); if (!oldMode.isEnabled() && pushMode.isEnabled()) { // The push connection is initially in a disconnected state; // the client will establish the connection ui.getInternals() .setPushConnection(pushConnectionFactory.apply(ui)); } // Nothing to do here if disabling push; // the client will close the connection } }
context.getResponse(), document, context.getUI(), context.getUriResolver()); context.getSession().getService().modifyBootstrapPage(response);
VaadinService service = session.getService(); if (!service.isResourceAvailable(webcomponentsLoaderUrl, session.getBrowser(), null)) {