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.liusoft.dlog4j.UserLoginManager.java

/**
 *  Velocity?//  w w  w. j  a v  a2s .  c  o m
 * 
 * @param request
 * @param response
 * @param uuid
 * @param verify_host
 * @return
 * @see com.liusoft.dlog4j.velocity.DLOG_VelocityTool#verify_login_cookie(String,
 *      boolean)
 */
public static SessionUserObject getLoginUser(HttpServletRequest request, HttpServletResponse response,
        boolean verify_host) {
    // sessionsession?
    Cookie uuidCookie = null;
    HttpSession ssn = request.getSession(false);
    if (ssn != null) {
        SessionUserObject user = (SessionUserObject) ssn.getAttribute(SESSION_USER_KEY);
        if (user != null) {
            uuidCookie = getUuidCookie(request);
            //sessioncookie?
            //(?s1s2?)
            if (uuidCookie != null)
                return user;
            ssn.invalidate();
            return null;
        }
    }
    String uuid = null;
    if (uuidCookie == null)
        uuidCookie = getUuidCookie(request);
    if (uuidCookie != null)
        uuid = uuidCookie.getValue();
    if (StringUtils.isEmpty(uuid))
        return null;
    // session?
    try {
        UUID oUUID = new UUID(uuid);
        String new_host = request.getRemoteAddr();
        if (verify_host && !StringUtils.equals(new_host, oUUID.host))
            return null;
        UserBean user = UserDAO.getUserByID(oUUID.uid);
        // ?
        if (user == null || user.getStatus() != UserBean.STATUS_NORMAL
                || user.getPassword().hashCode() != oUUID.pwdCode) {
            RequestUtils.setCookie(request, response, COOKIE_UUID_KEY, "", 0);
            RequestUtils.setCookie(request, response, COOKIE_LASTLOGIN_KEY, "", 0);
            return null;
        }
        int keep_days = user.getKeepDays();
        if (keep_days < 1)
            keep_days = 365;
        return loginUser(request, response, user, keep_days);
    } catch (Exception e) {
        log.error("Exception occur when get current user.", e);
    }

    return null;
}

From source file:br.com.cobranca.util.Util.java

/**
 * Metodo que remove usuario da sessao/*from   w  ww  . jav a  2s . co m*/
 */
public static void retirarUsuarioSessao() {
    HttpSession ses = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
    ses.invalidate();
}

From source file:org.frat.common.security.BaseSecurityContext.java

/**
 * .//from w ww . j  av a  2 s .  c  o m
 * 
 * @param username
 */
public static void kickOutUser(String username) {
    try {
        // applicationHashSet?session
        @SuppressWarnings("unchecked")
        HashSet<HttpSession> sessions = (HashSet<HttpSession>) WebUtil.getServletContext()
                .getAttribute("loginSessions");
        List<HttpSession> sessionList = new ArrayList<HttpSession>();
        for (HttpSession session : sessions) {
            if (null != session && StringUtil.isEqualObj(
                    String.valueOf(session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)),
                    username)) {
                // session
                if (!StringUtil.isEqualObj(session.getId(), WebUtil.getSessionId())) {
                    sessionList.add(session);
                }
            }
        }
        for (HttpSession session : sessionList) {
            session.invalidate();
            LOGGER.info("success kick out session [" + session.getId() + "]");
            LOGGER.info("success kick out user [" + username + "]");
        }
    } catch (Exception e) {
        LOGGER.error("");
        LOGGER.error(StackTraceUtil.getStackTrace(e));
    }
}

From source file:com.gtwm.pb.servlets.AppController.java

/**
 * Invalidate the user's session// w w  w.  jav a  2  s  .co m
 */
private static void logout(HttpServletRequest request) {
    HttpSession session = request.getSession();
    session.invalidate();
}

From source file:com.project.framework.controller.LogoutController.java

@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String logOut(HttpSession session) {
    session.invalidate();
    return "redirect:/framework.htm";
}

From source file:com.mohit.program.controller.logout.LogoutController.java

@RequestMapping(method = RequestMethod.GET)
public String doGet(HttpSession session) {
    session.invalidate();
    return "redirect/?success";
}

From source file:com.healthcit.analytics.servlet.LogoutController.java

@RequestMapping(method = RequestMethod.GET)
public String logout(HttpSession session) {
    session.invalidate();

    return "redirect:/";
}

From source file:com.stormpath.tooter.controller.LogoutController.java

@RequestMapping(method = RequestMethod.GET)
public String logout(HttpSession session) {
    session.invalidate();
    return "logout";
}

From source file:edu.pitt.sis.infsci2730.finalProject.web.LogoutController.java

@RequestMapping(value = "", method = RequestMethod.GET)
public void logout(HttpServletResponse res, HttpSession session) {
    session.invalidate();
    try {//w  w w .  ja v  a 2s  .c  om
        res.sendRedirect("/eBusiness/user");
    } catch (IOException ex) {
        Logger.getLogger(LogoutController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:puma.sp.authentication.controllers.authentication.TerminateController.java

@RequestMapping(value = "/LogoutServlet", method = RequestMethod.GET)
public String logout(@RequestParam(value = "RelayState", defaultValue = "") String relayState, ModelMap model,
        HttpSession session) {
    session.invalidate();
    return "redirect:" + relayState;
}