List of usage examples for com.vaadin.server VaadinSession getSession
public WrappedSession getSession()
From source file:annis.gui.requesthandler.LoginServletRequestHandler.java
License:Apache License
private void doPost(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { response.setContentType("text/html"); String username = request.getParameter("annis-login-user"); String password = request.getParameter("annis-login-password"); if (username != null && password != null) { // forget any old user information session.getSession().removeAttribute(AnnisBaseUI.USER_KEY); session.getSession().removeAttribute(AnnisBaseUI.USER_LOGIN_ERROR); // get the URL for the REST service Object annisServiceURLObject = session.getSession().getAttribute(AnnisBaseUI.WEBSERVICEURL_KEY); if (annisServiceURLObject == null || !(annisServiceURLObject instanceof String)) { log.warn("AnnisWebService.URL was not set as init parameter in web.xml"); }/*from www.j a v a 2s.c om*/ String webserviceURL = (String) annisServiceURLObject; try { AnnisUser user = new AnnisUser(username, password); WebResource res = user.getClient().resource(webserviceURL).path("admin").path("is-authenticated"); if ("true".equalsIgnoreCase(res.get(String.class))) { // everything ok, save this user configuration for re-use Helper.setUser(user); } } catch (ClientHandlerException ex) { session.getSession().setAttribute(AnnisBaseUI.USER_LOGIN_ERROR, "Authentification error: " + ex.getMessage()); response.setStatus(502); // bad gateway } catch (LoginDataLostException ex) { session.getSession().setAttribute(AnnisBaseUI.USER_LOGIN_ERROR, "Lost password in memory. Sorry."); response.setStatus(500); // server error } catch (UniformInterfaceException ex) { if (ex.getResponse().getStatus() == Response.Status.UNAUTHORIZED.getStatusCode()) { session.getSession().setAttribute(AnnisBaseUI.USER_LOGIN_ERROR, "Username or password wrong"); response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); } else if (ex.getResponse().getStatus() == Response.Status.FORBIDDEN.getStatusCode()) { session.getSession().setAttribute(AnnisBaseUI.USER_LOGIN_ERROR, "Account has expired"); response.setStatus(Response.Status.FORBIDDEN.getStatusCode()); // Forbidden } else { log.error(null, ex); session.getSession().setAttribute(AnnisBaseUI.USER_LOGIN_ERROR, "Unexpected exception: " + ex.getMessage()); response.setStatus(500); } } try (OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream(), Charsets.UTF_8)) { String html = Resources.toString(LoginServletRequestHandler.class.getResource("closelogin.html"), Charsets.UTF_8); CharStreams.copy(new StringReader(html), writer); } } // end if login attempt }
From source file:annis.libgui.Helper.java
License:Apache License
public static AnnisUser getUser() { VaadinSession vSession = VaadinSession.getCurrent(); WrappedSession wrappedSession = null; if (vSession != null) { wrappedSession = vSession.getSession(); }/* w w w. j a va 2s. co m*/ if (wrappedSession != null) { Object o = VaadinSession.getCurrent().getSession().getAttribute(AnnisBaseUI.USER_KEY); if (o != null && o instanceof AnnisUser) { return (AnnisUser) o; } } return null; }
From source file:com.foc.vaadin.FocWebApplication.java
License:Apache License
public String getSessionID_Debug() { String id = ""; if (getHttpSession() != null) { id = "HTTP_" + getHttpSession().getId(); // focWebSession = (FocWebSession) getHttpSession().getAttribute("FOC_WEB_SESSION"); } else {//from w ww .j a va 2 s . c om VaadinSession vaadinSession = getSession(); if (vaadinSession == null) { id = "VAAD_NULL"; } else { if (vaadinSession.getSession() != null) { id = "VAAD_" + vaadinSession.getSession().getId(); } else { id = "VAAD_X_NULL"; } } } return id; }
From source file:edu.nps.moves.mmowgli.modules.registrationlogin.RegistrationPageBase.java
License:Open Source License
@HibernateUpdate @HibernateUserUpdate/* w w w . jav a 2 s. c o m*/ private void wereInReallyTL(User _u_) { boolean updateneeded = false; // avoid db hit if possible if (currentPopup != null) UI.getCurrent().removeWindow(currentPopup); // app.getMainWindow().removeWindow(currentPopup); MmowgliSessionGlobals globs = Mmowgli2UI.getGlobals(); globs.setLoggedIn(true); if (_u_ != null) { Object cacId = CACManager.getCacId(globs.getCACInfo()); if (cacId == null) { if (_u_.getCacId() != null) { _u_.setCacId(null); updateneeded = true; } } else if (!_u_.getCacId().equals(cacId.toString())) { _u_.setCacId(cacId.toString()); updateneeded = true; } //_u_.setCacId(cacId == null? null :cacId.toString()); if (!_u_.isWelcomeEmailSent()) { MailManager mmgr = AppMaster.instance().getMailManager(); mmgr.onNewUserSignupTL(_u_); _u_.setWelcomeEmailSent(true); updateneeded = true; } // If we're here, we've either been email-confirmed or that is not necessary; make sure here if (!_u_.isEmailConfirmed()) { _u_.setEmailConfirmed(true); updateneeded = true; } // Adjust session timeouts. Default (standard user) is set in web.xml VaadinSession vsess = UI.getCurrent().getSession(); WrappedSession sess = vsess.getSession(); if (_u_.isGameMaster()) sess.setMaxInactiveInterval(GAMEMASTER_SESSION_TIMEOUT_SECONDS); if (_u_.isAdministrator()) sess.setMaxInactiveInterval(ADMINSTRATOR_SESSION_TIMEOUT_SECONDS); MSysOut.println(SYSTEM_LOGS, "Vaadin heartbeat interval (sec): " + vsess.getConfiguration().getHeartbeatInterval()); MSysOut.println(SYSTEM_LOGS, "Tomcat timeout (\"maxInactiveInterval\") (sec): " + sess.getMaxInactiveInterval()); GameEventLogger.logUserLoginTL(_u_); if (updateneeded) { User.updateTL(_u_); } HSess.closeAndReopen(); // should be ok _u_ = User.merge(_u_, HSess.get()); MmowgliController cntlr = globs.getController(); if (cntlr != null) cntlr.handleEventTL(MmowgliEvent.HANDLE_LOGIN_STARTUP, _u_, null); //don't want User.get() in this session, userId, null); else System.err.println("No controller in RegistrationPageBase.wereIn()"); AppMaster.instance().sendMySessionReport(); } }
From source file:fr.univlorraine.mondossierweb.controllers.UiController.java
License:Apache License
/** * Confirme la fermeture d'une session/*from w ww.jav a 2s . c o m*/ * @param session */ public void confirmKillSession(VaadinSession session) { SecurityContext securityContext = (SecurityContext) session.getSession() .getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY); ConfirmWindow confirmWindow = new ConfirmWindow(applicationContext.getMessage( "admin.uiList.confirmKillSession", new Object[] { session.getSession().getId(), securityContext.getAuthentication().getName() }, UI.getCurrent().getLocale())); confirmWindow.addBtnOuiListener(e -> killSession(session)); UI.getCurrent().addWindow(confirmWindow); }
From source file:org.ikasan.dashboard.ui.framework.action.LogoutAction.java
License:BSD License
@Override public void exectuteAction() { VaadinService.getCurrentRequest().getWrappedSession().setAttribute(DashboardSessionValueConstants.USER, null);/*from w w w . j a v a2 s . c o m*/ this.visibilityGroup.setVisible(); this.editableGroup.setEditable(false); layout.removeComponent(this.logOutButton); layout.addComponent(this.loginButton, 2, 0); layout.addComponent(this.setupButton, 3, 0); layout.setComponentAlignment(this.setupButton, Alignment.MIDDLE_RIGHT); layout.setComponentAlignment(this.loginButton, Alignment.MIDDLE_RIGHT); this.layout.removeComponent(userLabel); VaadinSession vSession = VaadinSession.getCurrent(); WrappedSession httpSession = vSession.getSession(); this.navigationPanel.reset(); //Invalidate HttpSession httpSession.invalidate(); vSession.close(); //Redirect the user to the login/default Page Page.getCurrent().setLocation("/ikasan-dashboard"); }
From source file:org.jdal.vaadin.beans.VaadinScope.java
License:Apache License
private String getConversationId(Integer id) { VaadinSession session = VaadinSession.getCurrent(); if (session == null) { log.info("Request Conversation id without session"); return null; }/* w w w. ja va2 s . c o m*/ return session.getSession().getId() + ":" + id.toString(); }
From source file:org.vaadin.spring.security.internal.VaadinSharedSecurity.java
License:Apache License
private WrappedSession getSession() { VaadinSession vaadinSession = VaadinSession.getCurrent(); if (vaadinSession != null) { return vaadinSession.getSession(); } else {/* w ww.j a v a 2 s . com*/ return null; } }
From source file:org.vaadin.spring.security.shared.DefaultVaadinSharedSecurity.java
License:Apache License
private static WrappedSession getSession() { VaadinSession vaadinSession = VaadinSession.getCurrent(); if (vaadinSession != null) { return vaadinSession.getSession(); } else {//w w w . ja v a 2s . c o m return null; } }