List of usage examples for javax.servlet.http Cookie setPath
public void setPath(String uri)
From source file:com.woonoz.proxy.servlet.CookieFormatterTest.java
@Test public void testJSessionIdCookie() throws InvalidCookieException { String sessionId = "JJJ2234312421"; Cookie cookie = new Cookie("JSESSIONID", sessionId); cookie.setPath("/"); CookieFormatter formatter = CookieFormatter.createFromServletCookie(cookie); Assert.assertEquals("JSESSIONID=JJJ2234312421; path=/;", formatter.asString()); }
From source file:nl.strohalm.cyclos.controls.members.printsettings.RemoveReceiptPrinterSettingsAction.java
@Override protected ActionForward executeAction(final ActionContext context) throws Exception { final HttpServletRequest request = context.getRequest(); final RemoveReceiptPrinterSettingsForm form = context.getForm(); final Long id = form.getId(); receiptPrinterSettingsService.remove(id); context.sendMessage("receiptPrinterSettings.removed"); final String currentReceiptPrinter = RequestHelper.getCookieValue(request, "receiptPrinterId"); // If the member removes a printer he's currently using, clear the cookie. We cannot, however, do this for cookies on other clients. // They'll get an error when trying to print if (StringUtils.isNotEmpty(currentReceiptPrinter) && id.toString().equals(currentReceiptPrinter)) { final HttpServletResponse response = context.getResponse(); final Cookie cookie = new Cookie("receiptPrinterId", ""); cookie.setPath(request.getContextPath()); response.addCookie(cookie);//w w w.j a va 2s. c om } return context.getSuccessForward(); }
From source file:de.hska.ld.core.config.security.AjaxLogoutSuccessHandler.java
@Override public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { ///* w ww . j ava 2 s . co m*/ // To delete a cookie, we need to create a cookie that has the same // name with the cookie that we want to delete. We also need to set // the max age of the cookie to 0 and then add it to the Servlet's // response method. // javax.servlet.http.Cookie cookie = new Cookie("sessionID", ""); cookie.setPath("/"); if (!"localhost".equals(env.getProperty("module.core.oidc.server.endpoint.main.domain"))) { cookie.setDomain(env.getProperty("module.core.oidc.server.endpoint.main.domain")); } cookie.setMaxAge(0); response.addCookie(cookie); // TODO destory session in etherpad response.setStatus(HttpServletResponse.SC_OK); }
From source file:org.codehaus.groovy.grails.plugins.springsecurity.facebook.FacebookLogoutHandler.java
private void cancelCookie(final String name, final String path, final HttpServletResponse response) { Cookie cookie = new Cookie(name, null); cookie.setMaxAge(0);/*from ww w . j av a2 s . c om*/ cookie.setPath(path); response.addCookie(cookie); }
From source file:com.acme.demo.web.LogoutController.java
private void handleLogOutResponse(HttpServletRequest request, HttpServletResponse response) { Cookie[] cookies = request.getCookies(); for (Cookie cookie : cookies) { cookie.setMaxAge(0);/*from w ww . jav a2 s . c o m*/ cookie.setValue(null); cookie.setPath("/"); response.addCookie(cookie); } }
From source file:com.google.acre.script.AcreCookie.java
public Cookie toServletCookie() { Cookie c = new Cookie(name, value); c.setPath(path); c.setMaxAge(max_age);//from w ww .j a v a 2s.c o m if (domain != null) c.setDomain(domain); c.setSecure(secure); return c; }
From source file:eu.trentorise.smartcampus.permissionprovider.controller.CookieCleaner.java
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { for (String s : cookieNames) { Cookie cookie = new Cookie(s, null); cookie.setPath("/"); cookie.setMaxAge(0);/*from w w w. j a v a 2s. c o m*/ response.addCookie(cookie); cookie = new Cookie(s, null); cookie.setPath(request.getContextPath() + "/eauth/"); cookie.setMaxAge(0); response.addCookie(cookie); } if (request.getCookies() != null) { for (int i = 0; i < request.getCookies().length; i++) { Cookie cookie = request.getCookies()[i]; for (String s : cookieNames) { if (cookie.getName().startsWith(s)) { cookie = new Cookie(cookie.getName(), null); cookie.setPath("/"); cookie.setMaxAge(0); response.addCookie(cookie); cookie = new Cookie(cookie.getName(), null); cookie.setPath(request.getContextPath() + "/eauth/"); cookie.setMaxAge(0); response.addCookie(cookie); } } } } request.getSession().invalidate(); if (authentication != null) authentication.setAuthenticated(false); response.sendRedirect(request.getContextPath() + redirect); }
From source file:org.craftercms.security.authentication.impl.AuthenticationCookie.java
/** * Deletes the cookies from the context's response. * * @param context the context that holds the response to where an empty cookie is written (so the cookie is * removed from the browser). */// w ww . j a v a 2s. c o m public void delete(RequestContext context) { String contextPath = context.getRequest().getContextPath(); Cookie cookie = new Cookie(COOKIE, null); cookie.setPath(StringUtils.isNotEmpty(contextPath) ? contextPath : "/"); cookie.setMaxAge(0); context.getResponse().addCookie(cookie); }
From source file:net.anthonychaves.bookmarks.web.TokenController.java
@RequestMapping(method = RequestMethod.POST) public String rememberMe(HttpSession session, HttpServletResponse response, ModelMap model) { int duration = 168; //hours to remember me for = 1 week User user = (User) session.getAttribute("user"); String tokenId = tokenService.setupNewLoginToken(user); Cookie cookie = new Cookie("loginToken", tokenId); cookie.setMaxAge(duration * 60 * 60); cookie.setPath("/bookmarks"); response.addCookie(cookie);/* w w w . j ava 2 s .c o m*/ model.addAttribute("status", "success"); return "redirect:/b/user"; }
From source file:org.craftercms.security.authentication.impl.AuthenticationCookie.java
/** * Saves the cookie in the context's response. * * @param context the context that holds the response to where the cookie is written. * @param cookieMaxAge the max age of the cookie. */// w ww . j a v a 2s.c o m public void save(RequestContext context, int cookieMaxAge) { Cookie cookie = new Cookie(COOKIE, toCookieValue()); cookie.setPath("/"); cookie.setMaxAge(cookieMaxAge); context.getResponse().addCookie(cookie); }