List of usage examples for javax.servlet.http Cookie setMaxAge
public void setMaxAge(int expiry)
From source file:com.ctc.storefront.controllers.misc.AddToCartController.java
private void setCookie(final HttpServletResponse response, final CartData cartData) { final Cookie cookie = new Cookie("cartQuantity", String.valueOf(cartData.getTotalUnitCount())); cookie.setMaxAge(60 * 60); cookie.setPath("/"); cookie.setDomain(siteConfigService.getString(CART_COUNT_COOKIE_DOMAIN_NAME, ".ctc.com")); response.addCookie(cookie);//from w w w . j a v a 2 s .c o m }
From source file:org.exoplatform.login.openid.OpenIDConsumerServlet.java
private void processReturn(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Identifier identifier = this.verifyResponse(req); log.debug("identifier: " + identifier); if (identifier != null) { Cookie c = new Cookie(OpenIDUtils.OPENID_IDENTIFIER_TOKEN, identifier.getIdentifier()); c.setMaxAge(300); c.setPath("/"); resp.addCookie(c);//from ww w .ja v a2 s .c o m } resp.sendRedirect(this.openid_portlet_url); }
From source file:com.third.rent.user.controller.LoginController.java
@RequestMapping(value = "/user/login.do", method = RequestMethod.POST) public String login_post(@RequestParam String userId, @RequestParam String userPwd, @RequestParam(required = false) String chkSaveId, HttpServletRequest request, HttpServletResponse response, Model model) { // 1/* w w w . j a va 2 s. c om*/ logger.info("? , ? userId={} userPwd={}", userId, userPwd); logger.info("? chkSaveId={}", chkSaveId); // 2 int result = userService.loginCheck(userId, userPwd); logger.info("? , ? result={}", result); String msg = "", url = "/user/login.do"; if (result == userService.LOGIN_OK) { UserVO vo = userService.selectByUserid(userId); msg = vo.getUserName() + " ? ?."; url = "/user/index.do"; // ? HttpSession session = request.getSession(); session.setAttribute("userId", userId); session.setAttribute("userName", vo.getUserName()); session.setAttribute("userLicense", vo.getUserLicense()); // ? Cookie ck = new Cookie("ck_userId", userId); ck.setPath("/"); // ? ? if (chkSaveId != null) { ck.setMaxAge(1000 * 24 * 60 * 60); // 1000? response.addCookie(ck); } else { ck.setMaxAge(0); // response.addCookie(ck); } } else if (result == userService.ID_NONE) { msg = " ? ."; } else if (result == userService.PWD_DISAGREE) { msg = " ? "; } else { msg = "? ? "; } // 3 model.addAttribute("msg", msg); model.addAttribute("url", url); return "common/message"; }
From source file:cn.vlabs.umt.ui.servlet.LogoutServlet.java
private void removeCookie(HttpServletResponse response, String domain, String path, String name) { Cookie cookie = new Cookie(name, ""); if (!CommonUtils.isNull(domain)) { cookie.setDomain(domain);// w ww . j ava2 s . c o m } if (!CommonUtils.isNull(path)) { cookie.setPath(path); } cookie.setMaxAge(0); response.addCookie(cookie); }
From source file:com.bee_wkspace.labee_fw.app.base.AppBaseBlogic.java
/** * ??????????<br>//w ww .j ava 2s . com * ?????id???<br> * ?????5?????????<br> * ????<br> * * @param idName ID?? * @param value */ protected void addPasswdSetCookie(String idName, String value) { Cookie cookie = new Cookie(idName, value); cookie.setMaxAge(5); bean.addPasswdSetName(idName); super.addCookie(cookie); }
From source file:com.haulmont.idp.controllers.IdpController.java
@GetMapping(value = "/logout") public String logout(@RequestParam(value = "sp", defaultValue = "") String serviceProviderUrl, @RequestParam(value = "response_type", defaultValue = "server-ticket") String responseType, @CookieValue(value = CUBA_IDP_COOKIE_NAME, defaultValue = "") String idpSessionCookie, HttpServletResponse response) {/*from w w w.j av a2s . c o m*/ if (!Strings.isNullOrEmpty(serviceProviderUrl) && !idpConfig.getServiceProviderUrls().contains(serviceProviderUrl)) { log.warn("Incorrect serviceProviderUrl {} passed, will be used default", serviceProviderUrl); serviceProviderUrl = null; } if (Strings.isNullOrEmpty(serviceProviderUrl)) { if (!idpConfig.getServiceProviderUrls().isEmpty()) { serviceProviderUrl = idpConfig.getServiceProviderUrls().get(0); } else { log.error("IDP property cuba.idp.serviceProviderUrls is not set"); response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); return null; } } if (!Strings.isNullOrEmpty(idpSessionCookie)) { boolean loggedOut = idpService.logout(idpSessionCookie); if (loggedOut) { log.info("Logged out IDP session {}", idpSessionCookie); logoutCallbackInvoker.performLogoutOnServiceProviders(idpSessionCookie); } } // remove auth cookie Cookie cookie = new Cookie(CUBA_IDP_COOKIE_NAME, ""); cookie.setMaxAge(0); response.addCookie(cookie); if (ResponseType.CLIENT_TICKET.getCode().equals(responseType)) { return "redirect:login.html" + "?response_type=" + ResponseType.CLIENT_TICKET.getCode() + "&sp=" + URLEncodeUtils.encodeUtf8(serviceProviderUrl); } return "redirect:login.html?sp=" + URLEncodeUtils.encodeUtf8(serviceProviderUrl); }
From source file:com.thoughtworks.go.http.mocks.MockHttpServletResponseAssert.java
public SELF hasCookie(String path, String name, String value, int maxAge, boolean secured, boolean httpOnly) { Cookie actualCookie = actual.getCookie(name); Cookie expectedCookie = new Cookie(name, value); expectedCookie.setDomain(""); expectedCookie.setPath(path);// w w w . jav a 2 s .c om expectedCookie.setMaxAge(maxAge); expectedCookie.setSecure(secured); expectedCookie.setHttpOnly(httpOnly); if (!EqualsBuilder.reflectionEquals(expectedCookie, actualCookie)) { this.as("cookie"); throw Failures.instance().failure(info, shouldBeEqual(ReflectionToStringBuilder.toString(actualCookie, ToStringStyle.MULTI_LINE_STYLE), ReflectionToStringBuilder.toString(expectedCookie, ToStringStyle.MULTI_LINE_STYLE), info.representation())); } return myself; }
From source file:de.metas.procurement.webui.service.impl.LoginRememberMeService.java
private void createRememberMeCookie(final User user) { try {/*w w w. jav a 2 s .c om*/ final String rememberMeToken = createRememberMeToken(user); final Cookie rememberMeCookie = new Cookie(COOKIENAME_RememberMe, rememberMeToken); final int maxAge = (int) TimeUnit.SECONDS.convert(cookieMaxAgeDays, TimeUnit.DAYS); rememberMeCookie.setMaxAge(maxAge); final String path = "/"; // (VaadinService.getCurrentRequest().getContextPath()); rememberMeCookie.setPath(path); VaadinService.getCurrentResponse().addCookie(rememberMeCookie); logger.debug("Cookie added for {}: {} (maxAge={}, path={})", user, rememberMeToken, maxAge, path); } catch (final Exception e) { logger.warn("Failed creating cookie for user: {}. Skipped.", user, e); } }
From source file:net.ymate.platform.webmvc.util.CookieHelper.java
/** * @param key //from w w w. j a v a 2s. c o m * @param value * @param maxAge * @return ?Cookie */ public CookieHelper setCookie(String key, String value, int maxAge) { Cookie _cookie = new Cookie(__owner.getModuleCfg().getCookiePrefix() + key, StringUtils.isBlank(value) ? "" : encodeValue(value)); _cookie.setMaxAge(maxAge); _cookie.setPath(__owner.getModuleCfg().getCookiePath()); if (StringUtils.isNotBlank(__owner.getModuleCfg().getCookieDomain())) { _cookie.setDomain(__owner.getModuleCfg().getCookieDomain()); } _cookie.setSecure(WebContext.getRequest().isSecure()); WebContext.getResponse().addCookie(_cookie); return this; }
From source file:org.craftercms.commons.http.CookieManager.java
/** * Add a "delete" cookie to the response to indicate the that the stored cookie should be deleted. * * @param name the name of the cookie//from w w w . j ava 2 s . c o m */ public void deleteCookie(String name, HttpServletResponse response) { Cookie cookie = new Cookie(name, null); cookie.setHttpOnly(httpOnly); cookie.setSecure(secure); if (StringUtils.isNotEmpty(domain)) { cookie.setDomain(domain); } if (StringUtils.isNotEmpty(path)) { cookie.setPath(path); } cookie.setMaxAge(0); response.addCookie(cookie); logger.debug(LOG_KEY_DELETED_COOKIE, name); }