Example usage for javax.servlet.http HttpSession invalidate

List of usage examples for javax.servlet.http HttpSession invalidate

Introduction

In this page you can find the example usage for javax.servlet.http HttpSession invalidate.

Prototype

public void invalidate();

Source Link

Document

Invalidates this session then unbinds any objects bound to it.

Usage

From source file:com.bs.loginBean.LoginBean.java

@Autowired
public String logout() {
    HttpSession session = LoginUtil.getSession();
    session.invalidate();
    return "logout";
}

From source file:forum.controller.UserController.java

@RequestMapping(value = "/deconnexion", method = RequestMethod.GET)
public String deconnexion(HttpSession request) {
    request.invalidate();

    return "redirect:/";
}

From source file:org.polymap.service.fs.webdav.WebDavServer.java

/**
 * Initializes a new session for the given user.
 * <p/>// w  w  w .  jav  a 2s.com
 * This method is called by {@link SecurityManagerAdapter}
 * 
 * @param user
 * @return The specified user.
 */
public static Principal createNewSession(final Principal user) {
    HttpServletRequest req = com.bradmcevoy.http.ServletRequest.getRequest();
    final HttpSession session = req.getSession();

    // HTTP session timeout: 30min
    session.setMaxInactiveInterval(30 * 60);

    FsPlugin.getDefault().sessionContextProvider.mapContext(user.getName(), true);
    final SessionContext sessionContext = SessionContext.current();

    // ContentManager
    Locale locale = req.getLocale();
    sessionContext.setAttribute("contentManager",
            ContentManager.forUser(user.getName(), locale, sessionContext));

    // invalidate HTTP session when context is destroyed
    sessionContext.addSessionListener(new ISessionListener() {
        public void beforeDestroy() {
            log.info("SessionContext is destroyed -> invalidating HTTP session");
            try {
                //sessionContext.removeSessionListener( this );
                session.invalidate();
            } catch (Exception e) {
                log.warn("HTTP session already invalidated: " + e);
            }
        }
    });
    // session destroy listener
    session.setAttribute("sessionListener", new HttpSessionBindingListener() {
        public void valueBound(HttpSessionBindingEvent ev) {
        }

        public void valueUnbound(HttpSessionBindingEvent ev) {
            //
            sessionContext.execute(new Runnable() {
                public void run() {
                    ContentManager.releaseSession(user.getName());
                }
            });
            // prevent life-lock
            if (!sessionContext.isDestroyed() && sessionContext.getAttribute("destroying") == null) {
                sessionContext.setAttribute("destroying", true);
                FsPlugin.getDefault().sessionContextProvider.destroyContext(sessionContext.getSessionKey());
                log.info("HTTP Session destroyed: " + session.getId() + ", user: " + user);
            }
        }
    });
    log.info("New HTTP session: " + session.getId() + ", user: " + user);
    return user;
}

From source file:nl.b3p.kaartenbalie.struts.LogoutAction.java

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    HttpSession session = request.getSession();
    String sessionId = session.getId();

    session.invalidate();
    log.debug("Logged out from session: " + sessionId);

    return mapping.findForward("success");
}

From source file:br.ufsm.csi.hotelmanagementats.controller.AcessoController.java

@RequestMapping("realizarLogout.html")
public ModelAndView realizarLogout(HttpSession session) {

    session.invalidate();

    ModelAndView mv = new ModelAndView("/WEB-INF/views/paginaInicial");

    // mv.addObject("mensagem", "<Strong> Sucesso</Strong> Usurio saiu do sistema!");
    // mv.addObject("tipo", "success");

    return mv;// ww w.j  a  v  a 2s .  c o m
}

From source file:com.haulmont.cuba.portal.sys.exceptions.PortalExceptionResolver.java

@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) {/*from ww w  .j  a  va  2s. com*/
    if (ex instanceof NoUserSessionException) {
        log.warn(ex.getMessage());

        HttpSession httpSession = request.getSession();
        httpSession.invalidate();

        if (StringUtils.isNotEmpty(noUserSessionUrl))
            return new ModelAndView("redirect:" + noUserSessionUrl);
        else
            return new ModelAndView("redirect:/");
    } else if (ex instanceof NoMiddlewareConnectionException) {
        log.error(ex.getMessage());
        HttpSession httpSession = request.getSession();
        httpSession.invalidate();

        if (StringUtils.isNotEmpty(noMiddlewareConnectionUrl))
            return new ModelAndView(noMiddlewareConnectionUrl);
        else
            return new ModelAndView("/");
    } else {
        log.error(ExceptionUtils.getStackTrace(ex));
    }

    return null;
}

From source file:com.education.lessons.ui.server.login.AbstractLoginController.java

/**
 * Handles sign out.//from   w w w .  j ava 2 s  . c  o  m
 */
@RequestMapping(value = "/logout")
protected String signOut(HttpSession session) {
    session.invalidate();
    return "redirect:/";
}

From source file:org.beangle.security.web.auth.logout.SecurityContextLogoutHandler.java

/**
 * Requires the request to be passed in.
 * /*from  ww w .  ja v  a2  s.  c  om*/
 * @param request
 *            from which to obtain a HTTP session (cannot be null)
 * @param response
 *            not used (can be <code>null</code>)
 * @param authentication
 *            not used (can be <code>null</code>)
 */
public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
    Validate.notNull(request, "HttpServletRequest required");
    if (invalidateHttpSession) {
        HttpSession session = request.getSession(false);
        if (session != null) {
            session.invalidate();
        }
    }
    SecurityContextHolder.clearContext();
}

From source file:com.lyh.licenseworkflow.web.action.LogoutAction.java

@Override
public String execute() throws Exception {
    HttpSession session = request.getSession();
    if (session != null) {
        //Session
        session.invalidate();
    }/*from  w  w w .  j a  v a2s .co  m*/
    users = userService.getAllUsers();
    return "login";
}

From source file:be.kdg.repaircafe.beans.LoginBean.java

public String logOut() {
    FacesContext ctx = FacesContext.getCurrentInstance();
    HttpSession session = (HttpSession) ctx.getExternalContext().getSession(false);
    session.invalidate();
    return "index";
}