List of usage examples for javax.servlet.http Cookie setMaxAge
public void setMaxAge(int expiry)
From source file:org.jasig.portlet.test.mvc.tests.CookieTestController.java
/** * Generates a new cookie with random name and value. * * @param response//from ww w . ja v a 2 s . c o m */ @ActionMapping(value = "randomCookieAction") protected void createRandomCookie(ActionRequest request, ActionResponse response) { final String name = RandomStringUtils.randomAlphabetic(8); final String value = RandomStringUtils.randomAlphanumeric(8); Cookie cookie = new Cookie(name, value); cookie.setComment("Random Cookie Test comment"); cookie.setMaxAge(-1); cookie.setSecure(request.isSecure()); response.addProperty(cookie); }
From source file:de.appsolve.padelcampus.utils.LoginUtil.java
public void updateLoginCookie(HttpServletRequest request, HttpServletResponse response) { Player player = sessionUtil.getUser(request); if (player != null) { UUID cookieUUID = UUID.randomUUID(); UUID cookieValue = UUID.randomUUID(); String cookieValueHash = BCrypt.hashpw(cookieValue.toString(), BCrypt.gensalt()); LoginCookie loginCookie = new LoginCookie(); loginCookie.setUUID(cookieUUID.toString()); loginCookie.setPlayerUUID(player.getUUID()); loginCookie.setLoginCookieHash(cookieValueHash); loginCookie.setValidUntil(new LocalDate().plusYears(1)); loginCookieDAO.saveOrUpdate(loginCookie); Cookie cookie = new Cookie(COOKIE_LOGIN_TOKEN, cookieUUID.toString() + ":" + cookieValue.toString()); cookie.setDomain(request.getServerName()); cookie.setMaxAge(ONE_YEAR_SECONDS); cookie.setPath("/"); response.addCookie(cookie);/* w w w . j a va 2s . co m*/ } }
From source file:org.apache.falcon.resource.admin.AdminResource.java
@GET @Path("clearuser") @Produces(MediaType.TEXT_PLAIN)//from ww w. ja v a 2s.co m public String clearUser(@Context HttpServletResponse response) { if (!SecurityUtil.isSecurityEnabled()) { Cookie cookie = new Cookie("hadoop.auth", null); cookie.setPath("/"); cookie.setMaxAge(0); cookie.setSecure(false); response.addCookie(cookie); } // Else, Do not checkin User, security is handled via Kerberos. return "ok"; }
From source file:com.glaf.core.util.RequestUtils.java
public static void setTheme(HttpServletRequest request, HttpServletResponse response, String theme) { if (StringUtils.isNotEmpty(theme)) { Cookie cookie = new Cookie(Constants.THEME_COOKIE, theme); cookie.setPath("/"); cookie.setMaxAge(-1); response.addCookie(cookie);/*from w w w .j a v a 2 s. c om*/ Cookie cookie2 = new Cookie("data-theme", "theme-" + theme); cookie2.setPath("/"); cookie2.setMaxAge(-1); response.addCookie(cookie2); } }
From source file:com.glaf.core.util.RequestUtils.java
public static void setTheme(HttpServletRequest request, HttpServletResponse response) { String theme = request.getParameter("theme"); if (StringUtils.isNotEmpty(theme)) { Cookie cookie = new Cookie(Constants.THEME_COOKIE, theme); cookie.setPath("/"); cookie.setMaxAge(-1); response.addCookie(cookie);/*www.j av a 2 s. c om*/ Cookie cookie2 = new Cookie("data-theme", "theme-" + theme); cookie2.setPath("/"); cookie2.setMaxAge(-1); response.addCookie(cookie2); } }
From source file:de.sainth.recipe.backend.security.AuthFilter.java
private Cookie createCookie(RecipeManagerAuthenticationToken authentication, boolean secure) { String newToken = Jwts.builder() // .compressWith(new GzipCompressionCodec()) .setSubject(authentication.getPrincipal().toString()) .setExpiration(/* www . java 2 s .c om*/ Date.from(LocalDateTime.now().plusMinutes(30).atZone(ZoneId.systemDefault()).toInstant())) .claim(TOKEN_ROLE, authentication.getAuthorities().get(0).getAuthority()).setIssuedAt(new Date()) .signWith(SignatureAlgorithm.HS256, key).compact(); Cookie cookie = new Cookie(COOKIE_NAME, newToken); cookie.setSecure(secure); cookie.setHttpOnly(true); cookie.setMaxAge(30 * 60); return cookie; }
From source file:com.adito.language.actions.SelectLanguageAction.java
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String referer = DAVUtilities.encodePath(CoreUtil.getRequestReferer(request), false); if (referer == null) { throw new CoreException(ErrorConstants.ERR_MISSING_REQUEST_PARAMETER, ErrorConstants.CATEGORY_NAME, "referer"); }/*from ww w.java 2 s. c om*/ String localeCode = request.getParameter("locale"); if (localeCode == null) { throw new CoreException(ErrorConstants.ERR_MISSING_REQUEST_PARAMETER, ErrorConstants.CATEGORY_NAME, "locale"); } /* Tokenize the locale parameter so we only get the first line. This prevents * a header injection exploit as the (not validated) locale gets added as * a cookie. */ StringTokenizer t = new StringTokenizer(localeCode); String locale = t.nextToken(); // Parse the locale code String country = ""; String variant = ""; String lang = locale; int idx = locale.indexOf("_"); if (idx != -1) { country = lang.substring(idx + 1); lang = lang.substring(0, idx); } idx = country.indexOf('_'); if (idx != -1) { variant = country.substring(idx + 1); country = country.substring(0, idx); } // Store the new locale in the session and set a persistant cookie Locale l = new Locale(lang, country, variant); request.getSession().setAttribute(Globals.LOCALE_KEY, l); Cookie cookie = new Cookie(SystemProperties.get("adito.cookie", "SSLX_SSESHID") + "_LANG", locale.toString()); cookie.setMaxAge(60 * 60 * 24 * 7); // a week cookie.setPath("/"); cookie.setSecure(true); response.addCookie(cookie); return referer == null ? mapping.findForward("home") : new ActionForward(referer, true); }
From source file:com.lti.system.MyLogoutFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest)) { throw new ServletException("Can only process HttpServletRequest"); }/*from ww w.ja va2 s . c o m*/ if (!(response instanceof HttpServletResponse)) { throw new ServletException("Can only process HttpServletResponse"); } HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; if (requiresLogout(httpRequest, httpResponse)) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (logger.isDebugEnabled()) { logger.debug("Logging out user '" + auth + "' and redirecting to logout page"); } for (int i = 0; i < handlers.length; i++) { handlers[i].logout(httpRequest, httpResponse, auth); } Cookie cookie = new Cookie("jforumSSOCookie", null); cookie.setMaxAge(0); cookie.setPath("/jforum"); httpResponse.addCookie(cookie); cookie = new Cookie("jforumSSOGroupCookie", null); cookie.setMaxAge(0); cookie.setPath("/jforum"); httpResponse.addCookie(cookie); request.removeAttribute("legalDate"); sendRedirect(httpRequest, httpResponse, logoutSuccessUrl); return; } chain.doFilter(request, response); }
From source file:com.hypersocket.session.json.SessionUtils.java
public void setLocale(HttpServletRequest request, HttpServletResponse response, String locale) { request.getSession().setAttribute(USER_LOCALE, locale); Cookie cookie = new Cookie(HYPERSOCKET_LOCALE, locale); cookie.setMaxAge(Integer.MAX_VALUE); cookie.setPath("/"); cookie.setSecure(request.getProtocol().equalsIgnoreCase("https")); cookie.setDomain(request.getServerName()); response.addCookie(cookie);//from w w w .j a v a2 s .co m }
From source file:com.mmj.app.common.checkcode.CheckCodeManager.java
public byte[] create(CookieManager cookieManager, CookieNameEnum maimaijunCheckcode, HttpServletResponse response) {/* w ww . java 2 s.c om*/ if (initException != null) {// ?? setup(); } CheckCodeInfo createCheckCodeInfo = CheckCodeTools.createCheckCodeInfo(); if (createCheckCodeInfo != null) { Cookie cookie = new Cookie("_cc_", EncryptBuilder.getInstance().encrypt(createCheckCodeInfo.getCode())); cookie.setMaxAge(CookieMaxAge.FOREVER); cookie.setDomain(CookieDomain.DOT_MAIMAIJUN_COM.getDomain()); cookie.setPath("/"); response.addCookie(cookie); return createCheckCodeInfo.getBytes(); } return null; }