List of usage examples for com.vaadin.server SessionDestroyListener SessionDestroyListener
SessionDestroyListener
From source file:com.peergreen.webconsole.core.vaadin7.BaseUI.java
License:Open Source License
/** * Init UI/*from w w w.j av a2 s . c om*/ * * @param request vaadin request */ @Override protected void init(VaadinRequest request) { setLocale(Locale.US); getPage().setTitle("Welcome to " + consoleName); setContent(root); root.addStyleName("root"); root.setSizeFull(); Label bg = new Label(); bg.setSizeUndefined(); bg.addStyleName("login-bg"); root.addComponent(bg); Boolean isLogged = (Boolean) getSession().getAttribute("is.logged"); if (!enableSecurity || (isLogged != null && isLogged)) { securityManager = (ISecurityManager) getSession().getAttribute("security.manager"); if (securityManager == null) { Subject defaultSubject = new Subject(); defaultSubject.getPrincipals().add(new UserPrincipal(ANONYMOUS_USER)); RoleGroup group = new RoleGroup(); if (defaultRoles != null) { for (String role : defaultRoles) { group.addMember(new RolePrincipal(role)); } } defaultSubject.getPrincipals().add(group); defaultSubject.setReadOnly(); securityManager = new SecurityManager(defaultSubject); getSession().setAttribute("security.manager", securityManager); getSession().getService().addSessionDestroyListener(new SessionDestroyListener() { @Override public void sessionDestroy(SessionDestroyEvent sessionDestroyEvent) { sessionDestroyEvent.getSession().getSession().removeAttribute("security.manager"); } }); } buildMainView(); } else { // Cookie userCookie = getCookieByName(PEERGREEN_USER_COOKIE_NAME); // if (userCookie != null) { // String token = userCookie.getValue(); // // get user by token and show main view // } buildLoginView(false); } }
From source file:com.peergreen.webconsole.core.vaadin7.BaseUIProvider.java
License:Open Source License
/** * {@inheritDoc}// w w w . j av a 2 s.c o m */ @Override public UI createInstance(final UICreateEvent e) { BaseUI ui = null; try { // Create an instance of baseUI String uiId = consoleAlias + "-" + i; ui = new BaseUI(SCOPE_EXTENSION_POINT, uiId, securityServicePid != null); ui.setConsoleId(consoleId); ui.setConsoleName(consoleName); ui.setDefaultRoles(defaultRoles); ui.setDomains(domains); // Configuration properties for ipojo component Dictionary<String, Object> props = new Hashtable<>(); props.put("instance.object", ui); Dictionary<String, Object> bindFilters = new Hashtable<>(); bindFilters.put("ScopeView", String.format("(&(%s=%s)(%s=%s))", UI_ID, uiId, EXTENSION_POINT, SCOPE_EXTENSION_POINT)); bindFilters.put("NotifierService", String.format("(%s=%s)", CONSOLE_ID, consoleId)); if (securityServicePid != null) { bindFilters.put("AuthenticateService", String.format("(%s=%s)", "factory.name", securityServicePid)); } props.put(REQUIRES_FILTER, bindFilters); // Create ipojo component from its factory final ComponentInstance instance = factory.createComponentInstance(props); ui.addDetachListener(new ClientConnector.DetachListener() { @Override public void detach(ClientConnector.DetachEvent event) { stop(instance); } }); e.getService().addSessionDestroyListener(new SessionDestroyListener() { @Override public void sessionDestroy(SessionDestroyEvent event) { stop(instance); } }); uis.add(instance); i++; } catch (UnacceptableConfiguration | MissingHandlerException | ConfigurationException ex) { LOGGER.error(ex.getMessage(), ex); } return ui; }
From source file:eu.eco2clouds.portal.E2CPortal.java
License:Apache License
@Override protected void init(VaadinRequest request) { SchedulerManagerFactory.configure(Configuration.schedulerUrl, Configuration.keystoreFilename, Configuration.keystorePwd); super.getSession().getService().addSessionDestroyListener(new SessionDestroyListener() { @Override/* ww w.j a v a2 s . c o m*/ public void sessionDestroy(SessionDestroyEvent event) { if (refreshThread != null) { refreshThread.done(); } } }); layout = new VerticalLayout(); layout.setStyleName(Reindeer.LAYOUT_WHITE); this.setContent(layout); this.sessionStatus.setLoggedUser("dperez"); this.sessionStatus.setLoggedGroup("eco2clouds"); this.sessionStatus.setStatus(SessionStatus.UNLOGGED); this.render(); //if (Configuration.refreshUIActive == true) { // System.out.println("start repaint"); refreshThread = new RefreshThread(); refreshThread.start(); //} }
From source file:org.opennms.features.vaadin.nodemaps.internal.NodeMapsApplication.java
License:Open Source License
@Override protected void init(final VaadinRequest vaadinRequest) { m_request = vaadinRequest;//from ww w. j ava2 s. c o m LOG.debug("initializing"); final VaadinApplicationContextImpl context = new VaadinApplicationContextImpl(); final UI currentUI = UI.getCurrent(); context.setSessionId(currentUI.getSession().getSession().getId()); context.setUiId(currentUI.getUIId()); context.setUsername(vaadinRequest.getRemoteUser()); Assert.notNull(m_alarmTable); Assert.notNull(m_nodeTable); final String searchString = vaadinRequest.getParameter("search"); final Integer maxClusterRadius = Integer.getInteger("gwt.maxClusterRadius", 350); LOG.info("Starting search string: {}, max cluster radius: {}", searchString, maxClusterRadius); m_alarmTable.setVaadinApplicationContext(context); final EventProxy eventProxy = new EventProxy() { @Override public <T> void fireEvent(final T eventObject) { LOG.debug("got event: {}", eventObject); if (eventObject instanceof VerticesUpdateEvent) { final VerticesUpdateEvent event = (VerticesUpdateEvent) eventObject; final List<Integer> nodeIds = new ArrayList<Integer>(); for (final VertexRef ref : event.getVertexRefs()) { if ("nodes".equals(ref.getNamespace()) && ref.getId() != null) { nodeIds.add(Integer.valueOf(ref.getId())); } } m_mapWidgetComponent.setSelectedNodes(nodeIds); return; } LOG.warn("Unsure how to deal with event: {}", eventObject); } @Override public <T> void addPossibleEventConsumer(final T possibleEventConsumer) { LOG.debug("(ignoring) add consumer: {}", possibleEventConsumer); /* throw new UnsupportedOperationException("Not yet implemented!"); */ } }; m_alarmTable.setEventProxy(eventProxy); m_nodeTable.setEventProxy(eventProxy); createMapPanel(searchString, maxClusterRadius); createRootLayout(); addRefresher(); // Notify the user if no tileserver url or options are set if (!NodeMapConfiguration.isValid()) { new InvalidConfigurationWindow().open(); } // Schedule refresh of node data m_executor.scheduleWithFixedDelay(() -> m_mapWidgetComponent.refreshNodeData(), 0, 5, TimeUnit.MINUTES); // If we do not shutdown the executor, the scheduler keeps refreshing the node data, even if the // UI may already been detached, resulting at one point in a OutOfMemory. See NMS-8589. vaadinRequest.getService().addSessionDestroyListener(new SessionDestroyListener() { @Override public void sessionDestroy(SessionDestroyEvent event) { m_executor.shutdown(); } }); }