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:edu.emory.cci.aiw.cvrg.eureka.servlet.LogoutServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    HttpSession session = req.getSession(false);
    if (session != null) {
        session.invalidate();
    }/*  w  w  w.  ja v a 2 s  .c  om*/
    /*
     * We need to redirect here rather than forward so that 
     * logout.jsp gets a request object without a user. Otherwise,
     * the button bar will think we're still logged in.
     */
    StringBuilder buf = new StringBuilder();
    String casLogoutUrl = webappProperties.getCasLogoutUrl();
    buf.append(casLogoutUrl);
    String awaitingActivation = req.getParameter("awaitingActivation");
    boolean aaEmpty = StringUtils.isEmpty(awaitingActivation);
    if (!aaEmpty && BooleanUtils.toBooleanObject(awaitingActivation) == null) {
        resp.sendError(HttpStatus.SC_BAD_REQUEST);
        return;
    }
    String notRegistered = req.getParameter("notRegistered");
    boolean nrEmpty = StringUtils.isEmpty(notRegistered);
    if (!nrEmpty && BooleanUtils.toBooleanObject(notRegistered) == null) {
        resp.sendError(HttpStatus.SC_BAD_REQUEST);
        return;
    }
    if (!aaEmpty || !nrEmpty) {
        buf.append('?');
    }
    if (!aaEmpty) {
        buf.append("awaitingActivation=").append(awaitingActivation);
    }
    if (!aaEmpty && !nrEmpty) {
        buf.append('&');
    }
    if (!nrEmpty) {
        buf.append("notRegistered=").append(notRegistered);
    }
    log("URL IS " + buf.toString());
    resp.sendRedirect(buf.toString());
}

From source file:il.co.brandis.controller.UserController.java

/**
 * Performing logout including cookie handling and session invalidation
*//*from  w w  w.  j  a  va 2  s .c  o m*/
@RequestMapping("/logout")
public String logout(ModelMap modelMap, HttpSession session, HttpServletResponse res, HttpServletRequest req) {
    session.invalidate();
    Cookie cookie = CookiesUtil.getUserCookie(req);
    if (cookie != null)
        CookiesUtil.removeUserCookie(res, cookie);
    return "redirect:/user/index";
}

From source file:edu.harvard.i2b2.oauth2.register.ejb.UserManager.java

public String logout() {
    FacesContext context = FacesContext.getCurrentInstance();

    context.addMessage(null, new FacesMessage("Logout successful!"));

    HttpSession httpSession = (HttpSession) context.getExternalContext().getSession(false);
    httpSession.invalidate();
    return "/login/signin";

}

From source file:org.jetbrains.webdemo.servlet.AuthorizationServlet.java

private void processLogoutRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
    HttpSession session = request.getSession();
    if (session != null) {
        session.invalidate();
    }//from   w ww .j  a  v a2s .  com
    response.setStatus(HttpServletResponse.SC_OK);
}

From source file:com.exam.controller.LoginController.java

@RequestMapping("/logout.htm")
public String logout(final HttpSession session, final Model model) {
    String returnValue = "welcome";

    if (null != session) {
        session.invalidate();
    }//  w ww . j av a2  s . c  om

    model.addAttribute("message", "Logged out successfully!");
    return returnValue;
}

From source file:bc8.movies.controllers.LoginController.java

@RequestMapping(value = "/logout")
public ModelAndView logout(HttpSession session) {
    ModelAndView mv = new ModelAndView("redirect:/home");
    mv.addObject("message", "Logged out!");
    session.invalidate();

    return mv;/*from ww w  . j  a va  2s .c  o  m*/
}

From source file:org.saiku.plugin.PentahoSessionService.java

public void logout(HttpServletRequest req) {
    if (SecurityContextHolder.getContext() != null
            && SecurityContextHolder.getContext().getAuthentication() != null) {
        Object p = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (sessionHolder.containsKey(p)) {
            sessionHolder.remove(p);//from  w  w w.jav a 2  s . c  o  m
        }
    }
    SecurityContextHolder.clearContext();
    HttpSession session = req.getSession(true);
    session.invalidate();
}

From source file:Project.LoginServlet.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request/*  w  w w .j a va 2s.co m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    //processRequest(request, response);

    HttpSession session = request.getSession();

    session.invalidate();
    response.sendRedirect("login.jsp");
    request.setAttribute("loginFailedMessage", "Logged out Successfully");
}

From source file:cz.muni.fi.pa165.mvc.controllers.LoginController.java

@RequestMapping(value = "/logout", method = RequestMethod.POST)
public String logout(HttpServletRequest request, Model model, RedirectAttributes redirectAttributes,
        UriComponentsBuilder uriBuilder) {

    HttpSession session = request.getSession(false);

    if (session.getAttribute("authenticatedUser") != null) {
        session.invalidate();
    }//from  w  ww .j  av a2 s. c om
    redirectAttributes.addFlashAttribute("alert_success", "You were successfully logouted");
    return "redirect:" + uriBuilder.path("/").toUriString();
}

From source file:org.alfresco.web.app.Application.java

/**
 * Invalidate Alfresco ticket and Web/Portlet session and clear the Security context for this thread.
 * @param context/* w  ww  . j  a v  a 2s.com*/
 */
public static void logOut(FacesContext context) {
    String ticket = null;
    if (Application.inPortalServer()) {
        ticket = AlfrescoFacesPortlet.onLogOut(context.getExternalContext().getRequest());
    } else {
        SessionUser user = getCurrentUser(context);
        if (user != null) {
            ticket = user.getTicket();
        }
        HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
        HttpSession session = request.getSession(false);
        if (session != null) {
            session.invalidate();
        }
    }

    // Explicitly invalidate the Alfresco ticket. This no longer happens on session expiry to allow for ticket
    // 'sharing'
    WebApplicationContext wc = FacesContextUtils.getRequiredWebApplicationContext(context);
    AuthenticationService unprotAuthService = (AuthenticationService) wc.getBean(BEAN_UNPROTECTED_AUTH_SERVICE);
    if (ticket != null) {
        unprotAuthService.invalidateTicket(ticket);
    }
    unprotAuthService.clearCurrentSecurityContext();
}