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:net.duckling.ddl.service.authenticate.impl.AuthenticationServiceImpl.java

public void invalidateSession(HttpServletRequest request) {
    if (request == null) {
        LOGGER.error("No HTTP reqest provided; cannot log out.");
        return;//w w  w. ja  va2 s . c o m
    }

    HttpSession session = request.getSession();
    String sid = (session == null) ? "(null)" : session.getId();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Invalidating WikiSession for session ID=" + sid);
    }
    VWBSession vwbsession = VWBSession.findSession(request);
    vwbsession.invalidate();
    session.invalidate();
}

From source file:fr.paris.lutece.portal.web.user.AdminLoginJspBean.java

/**
 * Process the logout of user//from  www.  j av  a2s.c om
 *
 * @param request Http request
 * @return The Jsp URL of the process result
 */
public String doLogout(HttpServletRequest request) {
    // Invalidation of the session
    HttpSession session = request.getSession();

    if (session != null) {
        session.invalidate();
    }

    String strLoginUrl = AdminAuthenticationService.getInstance().getLoginPageUrl();

    return AdminMessageService.getMessageUrl(request, Messages.MESSAGE_LOGOUT, strLoginUrl,
            AdminMessage.TYPE_INFO);
}

From source file:com.autentia.intra.bean.DynMenuBean.java

/**
 * Clear admin beans from session/*  w  w  w  .  j av a2s  .  c  om*/
 * private void clearSession() {
 * // Remove admin beans from session
 * FacesUtils.removeFromSession("userBean");
 * FacesUtils.removeFromSession("userCategoryBean");
 * FacesUtils.removeFromSession("inventaryBean");
 * FacesUtils.removeFromSession("projectBean");
 * FacesUtils.removeFromSession("ideaBean");
 * FacesUtils.removeFromSession("changePasswordBean");
 * FacesUtils.removeFromSession("userBean");
 * FacesUtils.removeFromSession("userCategoryBean");
 * FacesUtils.removeFromSession("inventaryBean");
 * FacesUtils.removeFromSession("projectBean");
 * FacesUtils.removeFromSession("projectRoleBean");
 * FacesUtils.removeFromSession("ideaBean");
 * FacesUtils.removeFromSession("changePasswordBean");
 * FacesUtils.removeFromSession("departmentBean");
 * FacesUtils.removeFromSession("contractTypeBean");
 * <p/>
 * // Remove biling beans from session
 * FacesUtils.removeFromSession("billBean");
 * FacesUtils.removeFromSession("accountBean");
 * FacesUtils.removeFromSession("accountEntryTypeBean");
 * FacesUtils.removeFromSession("accountEntryBean");
 * FacesUtils.removeFromSession("periodicalAccountEntryBean");
 * FacesUtils.removeFromSession("nofBean");
 * FacesUtils.removeFromSession("financialRatioBean");
 * <p/>
 * // Remove contacts beans from session
 * FacesUtils.removeFromSession("organizationBean");
 * FacesUtils.removeFromSession("contactBean");
 * FacesUtils.removeFromSession("interactionBean");
 * FacesUtils.removeFromSession("interactionTypeBean");
 * FacesUtils.removeFromSession("organizationTypeBean");
 * FacesUtils.removeFromSession("organizationISOCategoryBean");
 * FacesUtils.removeFromSession("offerRejectReasonBean");
 * FacesUtils.removeFromSession("offerBean");
 * <p/>
 * // Remove quality beans from session
 * FacesUtils.removeFromSession("qualityDocumentBean");
 * <p/>
 * // Remove bulletin beans from session
 * FacesUtils.removeFromSession("bulletinBoardBean");
 * FacesUtils.removeFromSession("companypathBean");
 * FacesUtils.removeFromSession("bulletinBoardCategoryBean");
 * <p/>
 * // Remove activity beans from session
 * FacesUtils.removeFromSession("activityBean");
 * FacesUtils.removeFromSession("objectiveBean");
 * <p/>
 * // Remove activity beans from session
 * FacesUtils.removeFromSession("activityReportBean");
 * FacesUtils.removeFromSession("generalReportBean");
 * FacesUtils.removeFromSession("billReportBean");
 * FacesUtils.removeFromSession("interactionReportBean");
 * FacesUtils.removeFromSession("projectReportBean");
 * FacesUtils.removeFromSession("organizationReportBean");
 * FacesUtils.removeFromSession("personalReportBean");
 * FacesUtils.removeFromSession("offerReportBean");
 * <p/>
 * // Remove tutorial beans from session
 * FacesUtils.removeFromSession("tutorialBean");
 * FacesUtils.removeFromSession("publicationBean");
 * FacesUtils.removeFromSession("magazineBean");
 * <p/>
 * // Remove util beans from session
 * FacesUtils.removeFromSession("sendMailBean");
 * }
 */

public String exit() {
    HttpSession sessionContext = (HttpSession) FacesContext.getCurrentInstance().getExternalContext()
            .getSession(false);
    if (sessionContext != null) {
        sessionContext.invalidate();
    }

    return "exit";

}

From source file:ManualInvalidate.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/html");

    HttpSession session = req.getSession();

    // Invalidate the session if it's more than a day old or has been
    // inactive for more than an hour.
    if (!session.isNew()) { // skip new sessions
        Date dayAgo = new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000);
        Date hourAgo = new Date(System.currentTimeMillis() - 60 * 60 * 1000);
        Date created = new Date(session.getCreationTime());
        Date accessed = new Date(session.getLastAccessedTime());

        if (created.before(dayAgo) || accessed.before(hourAgo)) {
            session.invalidate();
            session = req.getSession(); // get a new session
        }/*from   w  w  w  . j av a2  s  .co  m*/
    }
}

From source file:org.alfresco.repo.webdav.auth.BaseAuthenticationFilter.java

/**
 * Remove the user from the session and expire the session - after failed ticket auth.
 * //from  w w  w  .j  a  v  a 2s.  c o  m
 * @param req HttpServletRequest
 */
protected void invalidateSession(HttpServletRequest req) {
    HttpSession session = req.getSession(false);
    if (session != null) {
        setExternalAuth(session, false);
        session.removeAttribute(getUserAttributeName());
        session.invalidate();
    }
}

From source file:nl.strohalm.cyclos.controls.general.RedirectFromMessageAction.java

@Override
protected ActionForward executeAction(final ActionMapping mapping, final ActionForm actionForm,
        final HttpServletRequest request, final HttpServletResponse response) throws Exception {

    final RedirectFromMessageForm form = (RedirectFromMessageForm) actionForm;

    // Get the path
    final String path = StringUtils.trimToNull(form.getPath());
    if (path == null) {
        return null;
    }//from  www  . j  a  v a 2s .c o m

    // Get the element
    final long userId = form.getUserId();
    Element element = null;
    if (userId > 0L) {
        element = LoggedUser.runAsSystem(new Callable<Element>() {
            @Override
            public Element call() throws Exception {
                try {
                    return elementService.load(userId, RelationshipHelper.nested(Element.Relationships.GROUP,
                            Group.Relationships.GROUP_FILTERS));
                } catch (final Exception e) {
                    // ok, leave element null
                    return null;
                }
            }
        });
    }

    // Find the currently logged user
    final User loggedUser = LoginHelper.getLoggedUser(request);
    HttpSession session = request.getSession();
    if (userId > 0L && loggedUser != null) {
        if (loggedUser.getId().equals(userId)) {
            // The expected user is already logged in. Redirect to the path directly
            return new ActionForward(path, true);
        } else {
            // When there was another user logged in, invalidate the session, because we expect a fixed user
            session.invalidate();
            session = request.getSession();
        }
    }

    String containerUrl = null;
    SystemGroup group = null;
    if (element != null) {
        // Find the container url
        if (element instanceof Operator) {
            group = (SystemGroup) ((Operator) element).getMember().getGroup();
        } else {
            group = (SystemGroup) element.getGroup();
        }
        if (StringUtils.isNotEmpty(group.getContainerUrl())) {
            containerUrl = group.getContainerUrl();
        } else {
            for (final GroupFilter groupFilter : group.getGroupFilters()) {
                if (StringUtils.isNotEmpty(groupFilter.getContainerUrl())) {
                    containerUrl = groupFilter.getContainerUrl();
                    break;
                }
            }
        }
    }
    if (StringUtils.isEmpty(containerUrl)) {
        // Get the default container url
        final LocalSettings localSettings = settingsService.getLocalSettings();
        containerUrl = localSettings.getContainerUrl();
    }
    // Set the containerUrl to session
    session.setAttribute("containerUrl", containerUrl);

    // Update the cookie for the group
    responseHelper.setLoginCookies(request, response, group);

    // Set the returnTo on the session, so that after logging in, the user will be redirected to this page
    session.setAttribute("returnTo", path);

    return mapping.findForward("login");
}

From source file:SessionExpirationFilter.java

public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest hReq = (HttpServletRequest) req;

    HttpSession session = hReq.getSession(false);
    if (null != session) {
        Date expirationDate = (Date) session.getAttribute("expirationDate");

        if (expirationDate == null)
            expirationDate = new Date(System.currentTimeMillis() + 1000000); // only
        // for/*  w w  w  .  j a v a  2  s .c  o  m*/
        // make
        // false
        // "expirationDate.before(new Date())"
        // in
        // the
        // first
        // execution

        if (expirationDate.before(new Date())) {
            session.invalidate();
            session = null;
        } else {
            // ignore requests marked as both ajaxCall and ignoreForSessionTimeout
            String isAjaxCall = hReq.getParameter("IsAjaxCall");
            String ignoreForSessionTimeout = hReq.getParameter("ignoreForSessionTimeout");
            boolean ignoreForTimeout = "1".equals(isAjaxCall) && ("1".equals(ignoreForSessionTimeout));
            if (ignoreForTimeout) {
                // Do nothing; don't update the session timestamp
            } else {
                session.setAttribute("expirationDate",
                        new Date(System.currentTimeMillis() + session.getMaxInactiveInterval() * 1000));
            }
        }
    }
    chain.doFilter(req, resp);
}

From source file:org.structr.web.auth.HttpAuthenticator.java

@Override
public void doLogout(HttpServletRequest request) {

    final App app = StructrApp.getInstance();

    try {/*  w ww .  j ava2 s .  c o  m*/

        app.beginTx();

        Principal user = getUser(request, false);
        if (user != null) {

            user.setProperty(Principal.sessionId, null);
        }

        HttpSession session = request.getSession(false);

        if (session != null) {
            session.invalidate();
        }

        request.logout();

        app.commitTx();

    } catch (Exception ex) {

        logger.log(Level.WARNING, "Error while logging out user", ex);

    } finally {

        app.finishTx();
    }
}

From source file:org.inbio.modeling.web.controller.LayerController.java

@Override
protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response,
        BindException errors) {//from   w ww  .ja va 2  s .  c  om

    CurrentInstanceData currentInstanceData = null;
    ListLayerForm layerListForm = null;
    HttpSession session = null;
    ModelAndView model = null;

    // Create the object that will retain all the user information trought the process.
    currentInstanceData = new CurrentInstanceData();
    currentInstanceData.setUserSessionId(Calendar.getInstance().getTimeInMillis());

    // Asing the SessionInfo Object to the session
    session = request.getSession(true);

    //validate the new Session
    if (!session.isNew()) {
        session.invalidate();
        session = request.getSession(true);
    }

    session.setAttribute("CurrentSessionInfo", currentInstanceData);

    //creates the form to the page and upload it.
    layerListForm = new ListLayerForm();
    layerListForm.setLayerList(FormDTOConverter.convert(layerManager.getLayerList(), Layer.class));

    // Send the layer list to the JSP
    model = new ModelAndView();
    if (errors != null && errors.hasErrors())
        model.addAllObjects(errors.getModel());

    model.setViewName("layers");
    model.addObject("layersForm", layerListForm);

    return model;
}

From source file:com.pivotal.gemfire.tools.pulse.internal.controllers.PulseController.java

@RequestMapping(value = "/clusterLogout", method = RequestMethod.GET)
public void clusterLogout(HttpServletRequest request, HttpServletResponse response) throws IOException {
    HttpSession session = request.getSession(false);
    if (session != null) {

        // End session and redirect
        session.invalidate();
    }/*from  ww w .j ava2s  .c  om*/
    response.sendRedirect("../Login.html");
}