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.digitalizat.control.TaclController.java

@RequestMapping(value = "doLoginClose")
public String doLoginClose(HttpServletRequest request) {
    HttpSession sesion = request.getSession();
    sesion.invalidate();
    return "/plataforma/signin";
}

From source file:io.github.benas.todolist.web.controller.SessionController.java

/**
 * *******************// w w w  . j a v a 2 s  . co  m
 * Logout method
 * ********************
 */

@RequestMapping("/user/logout")
public String logout(HttpSession session) {
    sessionData.setUser(null); //sessionData = null causes NPE in next login
    session.invalidate();
    return "index";
}

From source file:org.dspace.webmvc.utils.Authenticate.java

/**
 * Store information about the current user in the request and context
 * /* w  w w.  j a  va2 s  .c o  m*/
 * @param context
 *            DSpace context
 * @param request
 *            HTTP request
 * @param eperson
 *            the eperson logged in
 */
public static void loggedIn(Context context, HttpServletRequest request, EPerson eperson) {
    HttpSession session = request.getSession();

    // For security reasons after login, give the user a new session
    if ((!session.isNew()) && (session.getAttribute("dspace.current.user.id") == null)) {
        // Keep the user's locale setting if set
        Locale sessionLocale = getSessionLocale(request);

        // Get info about the interrupted request, if set
        RequestInfo requestInfo = (RequestInfo) session.getAttribute("interrupted.request.info");

        // Get the original URL of interrupted request, if set
        String requestUrl = (String) session.getAttribute("interrupted.request.url");

        // Invalidate session unless dspace.cfg says not to
        if (ConfigurationManager.getBooleanProperty("webui.session.invalidate", true)) {
            session.invalidate();
        }

        // Give the user a new session
        session = request.getSession();

        // Restore the session locale
        if (sessionLocale != null) {
            //Config.set(request.getSession(), Config.FMT_LOCALE, sessionLocale);
            session.setAttribute("FMT_LOCALE", sessionLocale);
        }

        // Restore interrupted request information and url to new session
        if (requestInfo != null && requestUrl != null) {
            session.setAttribute("interrupted.request.info", requestInfo);
            session.setAttribute("interrupted.request.url", requestUrl);
        }
    }

    context.setCurrentUser(eperson);

    boolean isAdmin = false;

    try {
        isAdmin = AuthorizeManager.isAdmin(context);
    } catch (SQLException se) {
        log.warn("Unable to use AuthorizeManager " + se);
    } finally {
        request.setAttribute("isadmin", Boolean.valueOf(isAdmin));
    }

    // We store the current user in the request as an EPerson object...
    request.setAttribute("dspace.current.user", eperson);

    // and in the session as an ID
    session.setAttribute("dspace.current.user.id", Integer.valueOf(eperson.getID()));

    // and the remote IP address to compare against later requests
    // so we can detect session hijacking.
    session.setAttribute("dspace.current.remote.addr", request.getRemoteAddr());

}

From source file:edu.mum.managedBean.LoginManagedBean.java

public void logout() {
    userLogin = null;/*from   w  w  w.jav a 2s  .  c  o  m*/
    FacesContext ctx = FacesContext.getCurrentInstance();

    HttpSession session = (HttpSession) ctx.getExternalContext().getSession(false);
    session.invalidate();
    //        FacesContext context = FacesContext.getCurrentInstance();
    //        ConfigurableNavigationHandler handler = (ConfigurableNavigationHandler) context.getApplication().getNavigationHandler();
    //        handler.performNavigation("/views/login");
    try {

        getFacesContext().getExternalContext().redirect(getRequest().getContextPath() + "/views/login.jsf");
    } catch (IOException ex) {
        Logger.getLogger(LoginManagedBean.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:io.github.benas.todolist.web.servlet.user.account.DeleteAccountServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession session = request.getSession();
    User user = (User) session.getAttribute(TodoListUtils.SESSION_USER);
    userService.remove(user);/*ww w. ja  v  a 2  s  .  c om*/
    session.invalidate();
    request.getRequestDispatcher("/index").forward(request, response);
}

From source file:jp.terasoluna.fw.web.struts.actions.LogoffAction.java

/**
 * ?OIt???s?BHTTPZbV?A/*from w  ww.ja va 2 s . c  om*/
 * parameter??J?
 * ANVtH??[hZbg?B
 * parameter?????A?i404?jG?[?B
 *
 * @param mapping ANV}bsO
 * @param form ANVtH?[
 * @param req HTTPNGXg
 * @param res HTTPX|X
 * @return J?ANVtH??[h
 */
@Override
public ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest req,
        HttpServletResponse res) {
    if (log.isDebugEnabled()) {
        log.debug("doExecute() called.");
    }

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

    // parameter??itH??[h??j
    String path = mapping.getParameter();

    if (path == null) {
        // parameter?????A?i404?jG?[p
        try {
            res.sendError(HttpServletResponse.SC_NOT_FOUND);
        } catch (IOException e) {
            log.error("Error page(404) forwarding failed.");

            throw new SystemException(e, FORWARD_ERRORPAGE_ERROR);
        }
        return null;
    }

    // ANVtH??[h??
    ActionForward retVal = new ActionForward(path);

    return retVal;
}

From source file:me.ineson.demo.app.MainController.java

/**
 * @param model/*from  w  w  w  .  ja  v a  2 s. c  om*/
 * @return
 */
@RequestMapping(value = "/logout")
public @ResponseBody String logout(HttpSession session) {
    log.info("User " + session.getAttribute(SecurityContext.ATTRIBUTE_NAME) + " is logging out");
    session.invalidate();
    return StringUtils.EMPTY;
}

From source file:photosharing.api.LoginServlet.java

/**
 * Manages the authorization for a given user, creates a session or returns session invalid
 * /*from  w  w  w .jav  a  2 s  .c  o m*/
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    /*
     * Checks to see if the User is logged in forces logout for any existing user, you wouldn't actually do this in production
     */
    Principal user = request.getUserPrincipal();
    if (user != null) {
        HttpSession session = request.getSession(false);
        if (session != null) {
            session.invalidate();
        }

        request.logout();

    }

    /*
     * Authorizes the User
     */
    String auth = request.getHeader("Authorization");

    if (auth != null && !auth.isEmpty()) {
        auth = auth.replace("Basic ", "");

        String authDecoded = new String(Base64.decodeBase64(auth));

        String[] creds = authDecoded.split(":");
        String username = creds[0];
        String password = creds[1];
        try {
            request.login(username, password);
            request.getSession(true);
        } catch (Exception e) {
            response.setStatus(HttpStatus.SC_UNAUTHORIZED);
        }

    } else {
        response.setStatus(HttpStatus.SC_BAD_REQUEST);
    }

}

From source file:org.obm.sync.server.Request.java

public void destroySession() {
    HttpSession session = req.getSession(false);
    if (session != null) {
        session.invalidate();
    }
}

From source file:puma.application.webapp.users.AuthenticationController.java

@RequestMapping(value = "/user/logout", method = RequestMethod.GET)
public RedirectView logout(ModelMap model, HttpSession session, HttpServletRequest request,
        UriComponentsBuilder builder) {//from  w ww. j a  v a 2s.c  o m
    session.invalidate();
    String relayState = builder.path("/").build().toString();
    try {
        relayState = URLEncoder.encode(relayState, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return new RedirectView(LOGOUT_URL + "?RelayState=" + relayState);
}