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.erudika.para.security.SecurityUtils.java

/**
 * Clears the session. Deletes cookies and clears the security context.
 * @param req HTTP request/*w w w .j a v a2  s.co m*/
 */
public static void clearSession(HttpServletRequest req) {
    SecurityContextHolder.clearContext();
    if (req != null) {
        HttpSession session = req.getSession(false);
        if (session != null) {
            session.invalidate();
        }
    }
}

From source file:nl.b3p.catalog.security.GisPrincipal.java

public static GisPrincipal getGisPrincipal(HttpServletRequest request) {
    Principal user = request.getUserPrincipal();
    if (!(user instanceof GisPrincipal && request instanceof SecurityRequestWrapper)) {
        return null;
    }//from w w w  . j ava  2 s  .  c om
    GisPrincipal gp = (GisPrincipal) user;

    String code = request.getParameter(URL_AUTH);
    if (code != null && code.length() != 0) {
        if (gp != null && code.equals(gp.getCode())) {
            return gp;
        }

        // user is using different code, so invalidate session and login again
        HttpSession session = request.getSession();
        session.invalidate();
        String url = GisSecurityRealm.createCapabilitiesURL(code);
        gp = GisSecurityRealm.authenticateHttp(url, ConfigServlet.ANONYMOUS_USER, null, code);
    }

    // log in found principal
    if (gp != null) {
        SecurityRequestWrapper srw = (SecurityRequestWrapper) request;
        srw.setUserPrincipal(gp);
        log.debug("Automatic login for user: " + gp.name);
    }
    return gp;
}

From source file:nl.b3p.datastorelinker.security.GisPrincipal.java

public static GisPrincipal getGisPrincipal(HttpServletRequest request) {
    Principal user = request.getUserPrincipal();
    if (!(user instanceof GisPrincipal && request instanceof SecurityRequestWrapper)) {
        return null;
    }/*ww w  .  jav a 2s  .  c  o  m*/
    GisPrincipal gp = (GisPrincipal) user;

    String code = request.getParameter(URL_AUTH);
    if (code != null && code.length() != 0) {
        if (gp != null && code.equals(gp.getCode())) {
            return gp;
        }

        // user is using different code, so invalidate session and login again
        HttpSession session = request.getSession();
        session.invalidate();
        //String url = GisSecurityRealm.createCapabilitiesURL(code);
        //gp = GisSecurityRealm.authenticateHttp(url, ConfigServlet.ANONYMOUS_USER, null, code);
    }

    // log in found principal
    if (gp != null) {
        SecurityRequestWrapper srw = (SecurityRequestWrapper) request;
        srw.setUserPrincipal(gp);
        log.debug("Automatic login for user: " + gp.name);
    }
    return gp;
}

From source file:com.vangent.hieos.DocViewer.server.framework.ServletUtilMixin.java

/**
 * /* ww  w  . j  av a  2s.c o m*/
 * @param request
 */
static public void invalidateSession(HttpServletRequest request) {
    // Get session and invalidate.
    HttpSession session = request.getSession();
    session.invalidate();
}

From source file:de.fhg.igd.vaadin.util.VaadinUtil.java

/**
 * same as {@link VaadinUtil#closeApplication(Application)} but tries to retrieve 
 * application from ThreadLocal variable, that can be set up by 
 * {@link VaadinUtil#setApplication()} /*from   w  ww. j  a  v a 2 s  .  co  m*/
 */
public static void closeApplication() {
    final Application app = getApplicationInstance();
    final HttpSession session = getHttpSession(app);
    app.close();
    session.invalidate();
}

From source file:de.fhg.igd.vaadin.util.VaadinUtil.java

/**
 * closes the application and in addition invalidates the HttpSession, 
 * which is crucial for using session scoped spring beans 
 * in conjunction with vaadin applications  
 *///from  ww w .ja  v  a2 s .c o m
public static void closeApplication(Application application) {
    final Application app = getApplicationInstance();
    final HttpSession session = getHttpSession(app);
    app.close();
    session.invalidate();
}

From source file:org.sloth.util.ControllerUtils.java

/**
 * De-Authorizes the {@code HttpSession}.
 * /*www  .  j  a va  2s.  c  o m*/
 * @param s
 *            the {@code HttpSession}
 */
public static void deAuth(HttpSession s) {
    User u = getUser(s);
    if (u != null) {
        logger.info("Unbinding User {} from Session {}", u.getId(), s.getId());
    }
    s.invalidate();
}

From source file:com.liusoft.dlog4j.UserLoginManager.java

/**
 * //from w  w  w .  jav  a2  s  .com
 * 
 * @param req
 * @param res
 * @see com.liusoft.dlog4j.action.UserAction#doLogout(ActionMapping,
 *      ActionForm, HttpServletRequest, HttpServletResponse, String)
 */
public static void logoutUser(HttpServletRequest req, HttpServletResponse res) {
    // keep_days??
    SessionUserObject ubean = getLoginUser(req, res, false);
    if (ubean != null && ubean.getKeepDays() != 0) {
        DLOGUserManager.userLogout(ubean, true);
    }

    // Cookie
    RequestUtils.setCookie(req, res, COOKIE_UUID_KEY, "", 0);
    RequestUtils.setCookie(req, res, COOKIE_LASTLOGIN_KEY, "", 0);

    // session
    HttpSession ssn = req.getSession(false);
    if (ssn != null) {
        ssn.invalidate();
    }
}

From source file:de.metas.ui.web.login.LoginRestController.java

private static void destroySession(final Login loginService, final MSession session) {
    if (session != null) {
        session.logout();/*  ww  w  .  j ava  2s  .  c o m*/
    }

    if (loginService != null) {
        loginService.getCtx().resetAD_Session_ID();
    }

    //
    // Destroy http session
    final ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder
            .currentRequestAttributes();
    final HttpSession httpSession = servletRequestAttributes.getRequest().getSession(false);
    if (httpSession != null) {
        httpSession.invalidate();
    }
}

From source file:org.b3log.latke.util.Sessions.java

/**
 * Logouts a user with the specified request.
 *
 * @param request the specified request//  w w  w.j  a v  a  2 s . co m
 * @param response the specified response
 * @return {@code true} if succeed, otherwise returns {@code false}
 */
public static boolean logout(final HttpServletRequest request, final HttpServletResponse response) {
    final HttpSession session = request.getSession(false);

    if (null != session) {
        final Cookie cookie = new Cookie("b3log-latke", null);

        cookie.setMaxAge(0);
        cookie.setPath("/");

        response.addCookie(cookie);

        session.invalidate();

        return true;
    }

    return false;
}