List of usage examples for javax.servlet.http HttpSession invalidate
public void invalidate();
From source file:com.yahoo.dba.perf.myperf.springmvc.LogoutController.java
@Override protected ModelAndView handleRequestImpl(HttpServletRequest req, HttpServletResponse resp) throws Exception { HttpSession sess = req.getSession(); //do we have session if (sess != null) { UserDBConnections conns = UserDBConnections.class.cast(sess.getAttribute("UserDBConnections")); sess.removeAttribute("UserDBConnections"); sess.invalidate(); new Thread(new LogoutCleaner(conns)).start();//make it async. //TODO Add the thread handle for central process }/*from w w w .j a va 2 s . c o m*/ ModelAndView mv = new ModelAndView(new RedirectView(this.getNosessView())); return mv; }
From source file:edu.dfci.cccb.mev.dataset.rest.controllers.WorkspaceController.java
@RequestMapping(method = GET, value = "/session/close") @ResponseStatus(OK)//from ww w . jav a2 s . co m public void closeSession() { ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder .currentRequestAttributes(); HttpSession session = attributes.getRequest().getSession(true); session.invalidate(); }
From source file:cn.newgxu.lab.info.controller.AuthController.java
/** * RESTful APIPUT??// www. ja v a 2s.c o m * @param model * @param request * @param uid * @return only josn */ @RequestMapping(value = "/users/{uid}", method = RequestMethod.PUT) public String logout(Model model, HttpServletRequest request, @PathVariable("uid") long uid) { HttpSession session = request.getSession(false); if (session != null) { session.invalidate(); } model.addAttribute(ViewConstants.AJAX_STATUS, "ok"); return ViewConstants.BAD_REQUEST; }
From source file:org.workspace7.moviestore.controller.HomeController.java
@PostMapping("/logout") public ModelAndView clear(ModelAndView modelAndView, HttpServletRequest request) { final String hostname = System.getenv().getOrDefault("HOSTNAME", "unknown"); List<Movie> movies = movieDBHelper.getAll(); List<MovieCartItem> movieList = movies.stream() .map((Movie movie) -> MovieCartItem.builder().movie(movie).quantity(0).total(0).build()) .collect(Collectors.toList()); HttpSession session = request.getSession(false); if (session != null) { log.info("Invalidating session:{}", session.getId()); session.invalidate(); }/* w w w.j a v a2 s . c om*/ log.info("New Session"); modelAndView.addObject("movies", movieList); modelAndView.setViewName("home"); modelAndView.addObject("hostname", hostname); return modelAndView; }
From source file:Ctrl.CtrlProducts.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w .j av a 2s .c om * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { String action = request.getParameter("action"); if (action.equals("Tm Kim")) { String name = request.getParameter("txtTenSP"); Products sp = new Products(); List<Product> list = new ArrayList<Product>(); list = sp.HienthiSPadmin(name); request.setAttribute("listSP", list); RequestDispatcher rd = request.getRequestDispatcher("Product.jsp"); rd.forward(request, response); } else if (action.equals("Delete")) { String code = request.getParameter("txtcode"); Products sp = new Products(); sp.delete(code); String url = "Product.jsp"; RequestDispatcher rd = request.getRequestDispatcher(url); rd.forward(request, response); } else if (action.equals("Edit")) { String code = request.getParameter("txtcode").trim(); String name = request.getParameter("txtname"); String pri = request.getParameter("txtprice"); String manhinh = request.getParameter("txtmanhinh"); String ram = request.getParameter("txtram"); String hdd = request.getParameter("txthdd"); String cpu = request.getParameter("txtcpu"); String khuyenmai = request.getParameter("txtkhuyenmai"); String baohanh = request.getParameter("txtbaohanh"); String hinh = request.getParameter("txthinh"); int nkhuyenmai = Integer.parseInt(khuyenmai); float fpri = Float.parseFloat(pri); Product sp = new Product(code, name, fpri, manhinh, ram, hdd, cpu, nkhuyenmai, baohanh, hinh); request.setAttribute("SP", sp); RequestDispatcher rd = request.getRequestDispatcher("chinhsuasp.jsp"); rd.forward(request, response); } else if (action.equals("Update")) { String code = request.getParameter("txtcode"); String name = request.getParameter("txtname"); String pri = request.getParameter("txtprice"); String manhinh = request.getParameter("txtmanhinh"); String ram = request.getParameter("txtram"); String hdd = request.getParameter("txthdd"); String cpu = request.getParameter("txtcpu"); String khuyenmai = request.getParameter("txtkhuyenmai"); String baohanh = request.getParameter("txtbaohanh"); String hinh = request.getParameter("txthinh"); String ten = request.getParameter("txtTenSP"); int nkhuyenmai = Integer.parseInt(khuyenmai); float fpri = Float.parseFloat(pri); String url = "Product.jsp"; Products sp = new Products(); sp.insert(name, fpri, manhinh, ram, hdd, cpu, nkhuyenmai, baohanh, hinh, code); RequestDispatcher rd = request.getRequestDispatcher(url); rd.forward(request, response); } else if (action.equals("Thm")) { String code = request.getParameter("txtcode"); String name = request.getParameter("txtname"); String pri = request.getParameter("txtprice"); String manhinh = request.getParameter("txtmanhinh"); String ram = request.getParameter("txtram"); String hdd = request.getParameter("txthdd"); String cpu = request.getParameter("txtcpu"); String khuyenmai = request.getParameter("txtkhuyenmai"); String baohanh = request.getParameter("txtbaohanh"); String hinh = request.getParameter("txthinh"); int nkhuyenmai = Integer.parseInt(khuyenmai); float fpri = Float.parseFloat(pri); Products sp = new Products(); sp.newsp(code, name, fpri, manhinh, ram, hdd, cpu, nkhuyenmai, baohanh, hinh); RequestDispatcher rd = request.getRequestDispatcher("CtrlProducts?action=Tm+Kim&txtTenSP"); rd.forward(request, response); } else if (action.equals("Thm Sn Phm")) { RequestDispatcher rd = request.getRequestDispatcher("newsp.jsp"); rd.forward(request, response); } else if (action.equals("Qun l ti khon")) { RequestDispatcher rd = request.getRequestDispatcher("Quanliuser.jsp"); rd.forward(request, response); } if (action.equals("Logout")) { HttpSession session = request.getSession(true); session.invalidate(); RequestDispatcher rd = request.getRequestDispatcher("Trangchu.jsp"); rd.forward(request, response); } } catch (Exception e) { e.printStackTrace(); } }
From source file:action.AdminAction.java
public String logout() { HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); HttpSession session = request.getSession(true); session = request.getSession();/* w w w . ja v a 2 s. co m*/ session.invalidate(); // terminate session return SUCCESS; }
From source file:com.impetus.kundera.datakeeper.beans.LoginBean.java
public String logOff() { HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("You have successfully Logged off")); session.invalidate(); return DataKeeperConstants.OUTCOME_LOGOFF_SUCCESSFUL; }
From source file:com.glaf.core.util.RequestUtils.java
public static void removeLoginUser(HttpServletRequest request, HttpServletResponse response) { Cookie[] cookies = request.getCookies(); if (cookies != null && cookies.length > 0) { for (Cookie cookie : cookies) { if (StringUtils.equals(cookie.getName(), Constants.COOKIE_NAME)) { cookie.setMaxAge(0);/* ww w.j a v a 2 s. c om*/ cookie.setPath("/"); cookie.setValue(UUID32.getUUID()); response.addCookie(cookie); logger.debug("remove user from cookie"); } } } HttpSession session = request.getSession(false); if (session != null) { session.removeAttribute(Constants.LOGIN_INFO); session.invalidate(); } }
From source file:com.music.web.AuthenticationController.java
@RequestMapping("/logout") public String logout(HttpSession session, HttpServletRequest request, HttpServletResponse response) { session.invalidate(); Cookie cookie = WebUtils.getCookie(request, SocialSignInAdapter.AUTH_TOKEN_COOKIE_NAME); if (cookie != null) { cookie.setMaxAge(0);/*from w w w . j a v a2s . c o m*/ cookie.setDomain(".computoser.com"); cookie.setPath("/"); response.addCookie(cookie); } cookie = WebUtils.getCookie(request, SocialSignInAdapter.AUTH_TOKEN_SERIES_COOKIE_NAME); if (cookie != null) { cookie.setMaxAge(0); cookie.setDomain(".computoser.com"); cookie.setPath("/"); response.addCookie(cookie); } return "redirect:/"; }
From source file:org.opendatakit.aggregate.servlet.OpenIdLoginPageServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { CallingContext cc = ContextFactory.getCallingContext(this, req); // Check to make sure we are using the canonical server name. // If not, redirect to that name. This ensures that authentication // cookies will have the proper realm(s) established for them. String newUrl = cc.getServerURL() + BasicConsts.FORWARDSLASH + ADDR; String query = req.getQueryString(); if (query != null && query.length() != 0) { newUrl += "?" + query; }/*from w w w.j a va 2 s . co m*/ URL url = new URL(newUrl); if (!url.getHost().equalsIgnoreCase(req.getServerName())) { logger.info("Incoming servername: " + req.getServerName() + " expected: " + url.getHost() + " -- redirecting."); // try to get original destination URL from Spring... String redirectUrl = getRedirectUrl(req, ADDR); try { URI uriChangeable = new URI(redirectUrl); URI newUri = new URI(url.getProtocol(), null, url.getHost(), url.getPort(), uriChangeable.getPath(), uriChangeable.getQuery(), uriChangeable.getFragment()); newUrl = newUri.toString(); } catch (URISyntaxException e) { e.printStackTrace(); } // go to the proper page (we'll most likely be redirected back to here for authentication) resp.sendRedirect(newUrl); return; } // OK. We are using the canonical server name. String redirectParamString = getRedirectUrl(req, AggregateHtmlServlet.ADDR); // we need to appropriately cleanse this string for the OpenID login // strip off the server pathname portion if (redirectParamString.startsWith(cc.getSecureServerURL())) { redirectParamString = redirectParamString.substring(cc.getSecureServerURL().length()); } else if (redirectParamString.startsWith(cc.getServerURL())) { redirectParamString = redirectParamString.substring(cc.getServerURL().length()); } while (redirectParamString.startsWith("/")) { redirectParamString = redirectParamString.substring(1); } // check for XSS attacks. The redirect string is emitted within single and double // quotes. It is a URL with :, /, ? and # characters. But it should not contain // quotes, parentheses or semicolons. String cleanString = redirectParamString.replaceAll(BAD_PARAMETER_CHARACTERS, ""); if (!cleanString.equals(redirectParamString)) { logger.warn("XSS cleanup -- redirectParamString has forbidden characters: " + redirectParamString); redirectParamString = cleanString; } logger.info("Invalidating login session " + req.getSession().getId()); // Invalidate session. HttpSession s = req.getSession(); if (s != null) { s.invalidate(); } // Display page. resp.setContentType(HtmlConsts.RESP_TYPE_HTML); resp.setCharacterEncoding(HtmlConsts.UTF8_ENCODE); resp.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); resp.setHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); resp.setHeader("Pragma", "no-cache"); resp.addHeader(HtmlConsts.X_FRAME_OPTIONS, HtmlConsts.X_FRAME_SAMEORIGIN); PrintWriter out = resp.getWriter(); out.print( "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">" + "<html>" + "<head>" + "<meta http-equiv=\"cache-control\" content=\"no-store, no-cache, must-revalidate\"/>" + "<meta http-equiv=\"expires\" content=\"Mon, 26 Jul 1997 05:00:00 GMT\"/>" + "<meta http-equiv=\"pragma\" content=\"no-cache\"/>" + "<link rel=\"icon\" href=\"favicon.ico\"/>" + "<title>Log onto Aggregate</title>" + "<link type=\"text/css\" rel=\"stylesheet\" href=\"AggregateUI.css\">" + "<link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/button.css\">" + "<link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/table.css\">" + "<link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheets/navigation.css\">" + "<script type=\"text/javascript\">" + "window.onbeforeunload=function() {\n" + "var e=document.getElementById(\"stale\");\n" + "e.value=\"yes\";\n" + "}\n" + "window.onload=function(){\n" + "var e=document.getElementById(\"stale\");\n" + "if(e.value==\"yes\") {window.location.reload(true);}\n" + "}\n" + "</script>" + "</head>" + "<body>" + "<input type=\"hidden\" id=\"stale\" value=\"no\">" + "<table width=\"100%\" cellspacing=\"30\"><tr>" + "<td align=\"LEFT\" width=\"10%\"><img src=\"odk_color.png\" id=\"odk_aggregate_logo\" /></td>" + "<td align=\"LEFT\" width=\"90%\"><font size=\"7\">Log onto Aggregate</font></td></tr></table>" + "<table cellspacing=\"20\">" + "<tr><td valign=\"top\">" + "<form action=\"local_login.html\" method=\"get\">" + "<script type=\"text/javascript\">" + "<!--\n" + "document.write('<input name=\"redirect\" type=\"hidden\" value=\"" + redirectParamString + "' + window.location.hash + '\"/>');" + "\n-->" + "</script>" + "<input class=\"gwt-Button\" type=\"submit\" value=\"Sign in with Aggregate password\"/>" + "</form></td>" + "<td valign=\"top\">Click this button to log onto Aggregate using the username " + "and password that have been assigned to you by the Aggregate site administrator.</td></tr>" + "<tr><td valign=\"top\">" + "<form action=\"j_spring_openid_security_check\" method=\"post\">" + "<script type=\"text/javascript\">" + "<!--\n" + "var pathSlash=(window.location.pathname.lastIndexOf('/') > 1) ? '/' : '';\n" + "document.write('<input name=\"spring-security-redirect\" type=\"hidden\" value=\"' + " + "encodeURIComponent(pathSlash + '" + redirectParamString + "' + window.location.hash) + '\"/>');" + "\n-->" + "</script>" + "<input name=\"openid_identifier\" size=\"50\" maxlength=\"100\" " + "type=\"hidden\" value=\"https://www.google.com/accounts/o8/id\"/>" + "<input class=\"gwt-Button\" type=\"submit\" value=\"Sign in with Google\"/>" + "</form></td>" + "<td valign=\"top\">Click this button to log onto Aggregate using your Google account (via OpenID).<p>" + "<font color=\"blue\">NOTE:</font> you must allow this site to obtain your e-mail address. " + "Your e-mail address will only be used for establishing website access permissions.</p></td></tr>" + "<tr><td valign=\"top\">" + "<script type=\"text/javascript\">" + "<!--\n" + "document.write('<form action=\"" + redirectParamString + "' + window.location.hash + '\" method=\"get\">');" + "document.write('<input class=\"gwt-Button\" type=\"submit\" value=\"Anonymous Access\"/></form>');" + "\n-->" + "</script>" + "</td>" + "<td valign=\"top\">Click this button to access Aggregate without logging in.</td></tr>" + "</table>" + "</body>" + "</html>"); }