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:jp.co.opentone.bsol.linkbinder.view.filter.LoginFilter.java

private void startNewSession(HttpServletRequest request, HttpServletResponse response) {
    HttpSession session = request.getSession(false);
    String oldId = session.getId();
    Map<String, Object> attributes = collectSessionAttributes(session);
    session.invalidate();
    HttpSession newSession = request.getSession(true);
    copyAttributes(newSession, attributes);

    newSession.removeAttribute(Constants.KEY_START_NEW_SESSION);

    if (log.isDebugEnabled()) {
        log.debug("session '{}' was invalidated.", oldId);
        log.debug("session '{}' was started.", newSession.getId());
    }//from   w w  w .  j a va  2s.c  om
}

From source file:de.mpg.escidoc.pubman.desktop.Login.java

/**
 * one method for login and logout according to the current login state
 * /* www .j a  v a 2 s .co m*/
 * @return String empty navigation string for reloading the page
 */
public String loginLogout() throws ServletException, IOException, ServiceException, URISyntaxException {
    FacesContext fc = FacesContext.getCurrentInstance();
    LoginHelper loginHelper = (LoginHelper) getSessionBean(LoginHelper.class);
    String userHandle = loginHelper.getESciDocUserHandle();

    if (loginHelper.isLoggedIn() && loginHelper.getESciDocUserHandle() != null) {
        // logout mechanism
        loginHelper.setBtnLoginLogout("login_btLogin");
        if (userHandle != null) {
            long zeit = -System.currentTimeMillis();

            zeit += System.currentTimeMillis();
            logger.info("logout->" + zeit + "ms");
            //                loginHelper.setLoggedIn(false);
            //                loginHelper.getAccountUser().setName("");
            //                loginHelper.setESciDocUserHandle(null);
            //                depWSSessionBean.setMyWorkspace(false);
            //                depWSSessionBean.setDepositorWS(false);
            //                depWSSessionBean.setNewSubmission(false);

            // Logout mechanism

            //PubManSessionListener will call logout method

            HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext()
                    .getSession(false);
            session.invalidate();

        }
    } else {
        fc.getExternalContext().redirect(getLoginUrlFromCurrentBreadcrumb());
    }
    return "";
}

From source file:com.mylab.ShowPreviewBean.java

/**
 * logout the user/*from  w  ww .j  ava2 s  .  co m*/
 *
 */
public void logout() {

    HttpSession session = getRequest().getSession(false);
    if (session != null) {
        session.invalidate();
    }
}

From source file:org.glassmaker.spring.oauth.OAuth2LogoutFilter.java

@Override
protected boolean requiresLogout(HttpServletRequest request, HttpServletResponse response) {
    logger.debug("OAuth2LogoutFilter.requiresLogout");
    // Normal logout processing (i.e. detect logout URL)
    if (super.requiresLogout(request, response))
        return true;
    // If SSO cookie is stale, clear session contents
    String cookieName = getCookieName();

    HttpSession session = request.getSession();
    String sessionSso = (String) request.getSession().getAttribute(cookieName);
    if (sessionSso != null) {
        String browserSso = getCookieValue(request, cookieName);
        if (!sessionSso.equals(browserSso)) {
            logger.debug("Invalidating stale session: " + sessionSso);
            session.invalidate();
        }//from   ww  w. jav  a2 s . c o  m
    }
    return false;
}

From source file:com.swiftcorp.portal.common.login.web.LoginAction.java

public ActionForward logout(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    log.info("logout()::");
    System.out.println("logout()::");
    HttpSession session = request.getSession();
    if (session != null) {
        session.setAttribute(SESSION_KEYS.LOGIN_INFO, null);
        session.invalidate();
        log.debug("logout() : successfully ending session");
    }//from w w w. ja v  a2s.c om
    return promptLogin(mapping, form, request, response);
}

From source file:org.squale.welcom.taglib.security.CheckPageTag.java

/**
 * @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
 *//*from  www . j a v a 2 s.c o  m*/
public int doEndTag() throws JspException {
    boolean valid = false;
    final HttpSession session = super.pageContext.getSession();

    // if(session != null && session.getAttribute(name) != null)
    if (session != null) {
        valid = true;
    }

    if (valid) {

        computeMode();

        return EVAL_PAGE;
    }

    try {
        session.invalidate();

        final JspWriter out = super.pageContext.getOut();
        out.println(
                "<html><body><table class=\"wide\"><tr><td bgcolor=\"#e0e0e0\"><tr><td><table class=\"wide\"><tr><td align=\"center\" bgcolor=\"#cacaca\">"
                        + "<font face=\"Arial, Helvetica, sans-serif\"><b>Erreurs</b></font></td></tr><tr><td class=\"boxtext\" bgcolor=\"#dae6e6\">&nbsp;-&nbsp;"
                        + "<a href=\"/index.jsp\">Session invalid\351e</a></td></tr></table></td></tr></table></body></html>");
    } catch (final Exception e) {
        log.error(e, e);
        throw new JspException(e.toString());
    }

    return SKIP_PAGE;
}

From source file:org.finra.dm.app.security.HttpHeaderAuthenticationFilter.java

/**
 * Invalidates a user by invalidating their session and removing them from the security context holder.
 *
 * @param servletRequest the servlet request.
 * @param invalidateSession flag to indicate whether the Http Session should be invalidated or not.
 */// w  w w .j a v  a  2s .  co m
protected void invalidateUser(HttpServletRequest servletRequest, boolean invalidateSession) {
    if (invalidateSession) {
        HttpSession session = servletRequest.getSession(false);
        if (session != null) {
            LOGGER.debug("Invalidating the session.");
            session.invalidate();
        }
    }
    LOGGER.debug("Clearing the security context.");
    SecurityContextHolder.clearContext();
}

From source file:org.wso2.carbon.ml.rest.api.LoginLogoutApiV10.java

/**
 * Logout./*  w  w w .  ja v  a2 s .c om*/
 */
@POST
@Path("/logout")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response logout() {
    HttpSession session = httpServletRequest.getSession();
    PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    String username = carbonContext.getUsername();
    String tenantDomain = carbonContext.getTenantDomain();
    int tenantId = carbonContext.getTenantId();
    if (session != null) {
        session.invalidate();
    }
    auditLog.info(String.format(
            "User [name] %s of tenant [id] %s [domain] %s is logged-out from WSO2 Machine Learner. "
                    + "Granted session id is %s",
            username, tenantId, tenantDomain, session == null ? null : session.getId()));
    return Response.status(Response.Status.OK).entity("User logged out: " + carbonContext.getUsername())
            .build();
}

From source file:com.mylab.ShowPreviewBean.java

/**
 * Login the given user, preserving the current project context.
 * //  w  ww.  jav  a2 s  .c  om
 * @param User username to login
 * @param Password user's password
 * @return FORMACTION_OK if successful, else FORMACTION_ERROR. If an error occurred
 *         the error message can be retrieved via {@link #getRegisterActionMessage()}
 */
protected int loginUser() {

    try {
        // attempt to login the user
        String OU = "/cardadmin";
        getCmsObject().loginUser(OU, "xxx17yyy");

        // make sure we have a new session after login for security reasons
        HttpSession session = getRequest().getSession(false);
        if (session != null) {
            session.invalidate();
        }
        session = getRequest().getSession(true);

    } catch (CmsException e) {
        // return error code
    } finally {
        // switch back to original project
    }

    return 0;
}

From source file:com.huateng.ebank.framework.session.SessionManager.java

public boolean destroySession(HttpServletRequest req) {
    if (logger.isDebugEnabled()) {
        logger.debug("destroySession(HttpServletRequest) - start"); //$NON-NLS-1$
    }//from w  w  w  . jav  a 2  s .  co m

    HttpSession session = req.getSession(false);
    if (null == session)
        return false;
    session.invalidate();

    if (logger.isDebugEnabled()) {
        logger.debug("destroySession(HttpServletRequest) - end"); //$NON-NLS-1$
    }
    return true;
}