List of usage examples for com.vaadin.server VaadinService reinitializeSession
public static void reinitializeSession(VaadinRequest request)
From source file:com.cerebro.gorgone.landingpage.Login.java
public Login() { InputStream iniFile = VaadinServlet.getCurrent().getServletContext() .getResourceAsStream("/WEB-INF/shiro.ini"); if (iniFile == null) { logger.error("Il file Shiro.ini non esiste"); return;/* w ww. ja va 2s.c o m*/ } else { logger.info("File Shiro.ini presente"); } Ini ini = new Ini(); ini.load(iniFile); Factory<org.apache.shiro.mgt.SecurityManager> factory = new IniSecurityManagerFactory(ini); org.apache.shiro.mgt.SecurityManager securityManager = factory.getInstance(); SecurityUtils.setSecurityManager(securityManager); email.focus(); errorMessage.setVisible(false); this.addComponents(email, password, errorMessage, rememberMe, loginB); loginB.addClickListener((Button.ClickEvent e) -> { logger.info("Tentativo di connessione"); Subject currentUser = SecurityUtils.getSubject(); UsernamePasswordToken token = new UsernamePasswordToken(email.getValue(), password.getValue()); token.setRememberMe(rememberMe.getValue()); try { currentUser.login(token); Session session = currentUser.getSession(); User user = new User(); user.loadUser(); //session.setAttribute("User", user); getUI().setContent(new Game()); VaadinService.reinitializeSession(VaadinService.getCurrentRequest()); } catch (Exception ex) { logger.error(ex.toString()); email.setValue(""); password.setValue(""); errorMessage.setVisible(true); } }); }
From source file:com.cerebro.provevaadin.Start.java
public Start() { InputStream iniFile = VaadinServlet.getCurrent().getServletContext() .getResourceAsStream("/WEB-INF/shiro.ini"); if (iniFile == null) { logger.error("Il file Shiro.ini non esiste"); return;/* www .j ava 2 s . c om*/ } else { logger.info("File presente"); } Ini ini = new Ini(); ini.load(iniFile); Factory<SecurityManager> factory = new IniSecurityManagerFactory(ini); SecurityManager securityManager = factory.getInstance(); SecurityUtils.setSecurityManager(securityManager); HorizontalLayout root = new HorizontalLayout(); root.setWidth("800px"); root.setHeight("600px"); this.addComponent(root); this.setComponentAlignment(root, Alignment.MIDDLE_CENTER); FormLayout loginDiv = new FormLayout(); root.addComponent(loginDiv); username.focus(); errorMessage.setVisible(false); loginDiv.addComponents(username, password, rememberMe, login, errorMessage); login.addClickListener((Button.ClickEvent e) -> { logger.info("Pulsante: " + e.toString()); Subject currentUser = SecurityUtils.getSubject(); UsernamePasswordToken token = new UsernamePasswordToken(username.getValue(), password.getValue()); token.setRememberMe(rememberMe.getValue()); try { currentUser.login(token); if (currentUser.hasRole("firsttime")) { logger.info("Configurazione parametri del primo avvio"); getUI().setContent(new FirstTime()); } else { logger.info("Classe di gioco principale"); getUI().setContent(new Game()); VaadinService.reinitializeSession(VaadinService.getCurrentRequest()); } } catch (Exception ex) { logger.error("Errore nel login: " + ex.getMessage()); username.setValue(""); password.setValue(""); errorMessage.setVisible(true); } }); FormLayout signInForm = new FormLayout(); root.addComponent(signInForm); usernameSignIn.focus(); sesso.addItems("Maschio", "Femmina"); signInForm.addComponents(usernameSignIn, passwordSignIn, passwordConf, nome, cognome, sesso, eta, signIn); signIn.addClickListener((Button.ClickEvent event) -> { logger.info("Iscrizione al sito"); User utente = new User(); utente.setEmail(usernameSignIn.getValue()); utente.setPassword(passwordSignIn.getValue()); utente.setNomeUtente(nome.getValue()); utente.setCognomeUtente(cognome.getValue()); utente.setSessoUtente(sesso.getValue().toString()); utente.setDataNascitaUtente(eta.getValue()); SignIn signInWindow = new SignIn(utente); signInWindow.center(); UI.getCurrent().addWindow(signInWindow); }); }
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 w w w. j av a2 s .co m*/ log.debug("Session reinitialized: HttpSession={}, timeout={}sec, UserSession={}", httpSession, timeout, connection.getSession()); } }
From source file:org.vaadin.spring.security.managed.DefaultVaadinManagedSecurity.java
License:Apache License
/** * Clears the session of all attributes except some internal Vaadin attributes and reinitializes it. If Websocket * Push is used, the session will never be reinitialized since this throws errors on at least * Tomcat 8.// w w w . j a v a2 s . c om */ protected void clearAndReinitializeSession() { final VaadinRequest currentRequest = VaadinService.getCurrentRequest(); final UI currentUI = UI.getCurrent(); if (currentUI != null) { final Transport transport = currentUI.getPushConfiguration().getTransport(); if (Transport.WEBSOCKET.equals(transport) || Transport.WEBSOCKET_XHR.equals(transport)) { LOGGER.warn( "Clearing and reinitializing the session is currently not supported when using Websocket Push."); return; } } if (currentRequest != null) { LOGGER.debug("Clearing the session"); final WrappedSession session = currentRequest.getWrappedSession(); final String serviceName = VaadinService.getCurrent().getServiceName(); final Set<String> attributesToSpare = new HashSet<String>(); attributesToSpare.add(serviceName + ".lock"); attributesToSpare.add(VaadinSession.class.getName() + "." + serviceName); for (String s : currentRequest.getWrappedSession().getAttributeNames()) { if (!attributesToSpare.contains(s)) { LOGGER.trace("Removing attribute {} from session", s); session.removeAttribute(s); } } LOGGER.debug("Reinitializing the session {}", session.getId()); VaadinService.reinitializeSession(currentRequest); LOGGER.debug("Session reinitialized, new ID is {}", VaadinService.getCurrentRequest().getWrappedSession().getId()); } else { LOGGER.warn( "No VaadinRequest bound to current thread, could NOT clear/reinitialize the session after login"); } }
From source file:xyz.iipster.security.SecurityUtilsImpl.java
License:Apache License
@Override public Authentication login(String userName, String password) { Authentication authentication = authenticationManager .authenticate(new UsernamePasswordAuthenticationToken(userName, password)); VaadinService.reinitializeSession(VaadinService.getCurrentRequest()); SecurityContextHolder.getContext().setAuthentication(authentication); return authentication; }