List of usage examples for javax.servlet.http Cookie setMaxAge
public void setMaxAge(int expiry)
From source file:com.vmware.identity.openidconnect.server.LogoutRequestProcessor.java
private Cookie loggedOutSessionCookie() { Cookie cookie = new Cookie(SessionManager.getSessionCookieName(this.tenant), ""); cookie.setPath("/openidconnect"); cookie.setSecure(true);// w ww . j a v a 2 s . c o m cookie.setHttpOnly(true); cookie.setMaxAge(0); return cookie; }
From source file:com.haulmont.idp.controllers.IdpController.java
@GetMapping(value = "/") public String checkIdpSession(@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.ja v a2 s.com*/ 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)) { String serviceProviderTicket = idpService.createServiceProviderTicket(idpSessionCookie); if (serviceProviderTicket != null) { String serviceProviderRedirectUrl; try { URIBuilder uriBuilder = new URIBuilder(serviceProviderUrl); if (ResponseType.CLIENT_TICKET.getCode().equals(responseType)) { uriBuilder.setFragment(CUBA_IDP_TICKET_PARAMETER + "=" + serviceProviderTicket); } else { uriBuilder.setParameter(CUBA_IDP_TICKET_PARAMETER, serviceProviderTicket); } serviceProviderRedirectUrl = uriBuilder.build().toString(); } catch (URISyntaxException e) { log.warn("Unable to compose redirect URL", e); response.setStatus(HttpStatus.BAD_REQUEST.value()); return null; } try { response.sendRedirect(serviceProviderRedirectUrl); } catch (IOException e) { // do not log stacktrace here log.warn("Unable to send redirect to service provider URL", e.getMessage()); } log.debug("New ticket {} created for already logged in user", serviceProviderTicket); return null; } else { log.debug("IDP session {} not found, login required", 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.alibaba.dubbo.governance.web.governance.module.screen.Providers.java
/** * searchcookie?// ww w . jav a 2 s . com * ??cookie????? * @param context * @param value */ private void setSearchHistroy(Map<String, Object> context, String value) { //?cookie String separatorsB = "\\.\\.\\.\\.\\.\\."; String newCookiev = value; Cookie[] cookies = request.getCookies(); for (Cookie c : cookies) { if (c.getName().equals("HISTORY")) { String cookiev = c.getValue(); String[] values = cookiev.split(separatorsB); int count = 1; for (String v : values) { if (count <= 10) { if (!value.equals(v)) { newCookiev = newCookiev + separatorsB + v; } } count++; } break; } } Cookie _cookie = new Cookie("HISTORY", newCookiev); _cookie.setMaxAge(60 * 60 * 24 * 7); // Cookie30 _cookie.setPath("/"); response.addCookie(_cookie); // }
From source file:net.nan21.dnet.core.web.controller.ui.extjs.AbstractUiExtjsController.java
private Cookie createCookie(String name, String value, int age) { Cookie c = new Cookie(name, value); c.setMaxAge(age); return c;/*w ww .j a v a 2s . com*/ }
From source file:com.silverpeas.authentication.AuthenticationServlet.java
/** * Write connections cookie./* w w w. j a v a 2s .c o m*/ * * @param name * @param value * @param duration * @return */ private void writeCookie(HttpServletResponse response, String name, String value, int duration, boolean secure) { String cookieValue; try { cookieValue = URLEncoder.encode(value, CharEncoding.UTF_8); } catch (UnsupportedEncodingException ex) { cookieValue = value; } Cookie cookie = new Cookie(name, cookieValue); cookie.setMaxAge(duration); cookie.setPath("/"); if (secure) { cookie.setSecure(true); } response.addCookie(cookie); }
From source file:org.apache.archiva.redback.integration.util.AutoLoginCookies.java
public void setSignonCookie(String principal, HttpServletResponse httpServletResponse, HttpServletRequest httpServletRequest) { try {/* w w w. j av a 2 s. c o m*/ CookieSettings settings = securitySystem.getPolicy().getSignonCookieSettings(); int timeout = settings.getCookieTimeout(); KeyManager keyManager = securitySystem.getKeyManager(); AuthenticationKey authkey = keyManager.createKey(principal, "Signon Session Key", timeout); /* The path must remain as "/" in order for SSO to work on installations where the only * all of the servers are installed into the same web container but under different * web contexts. */ Cookie cookie = createCookie(SIGNON_KEY, authkey.getKey(), settings.getDomain(), settings.getPath(), httpServletRequest); if (timeout > 0) { cookie.setMaxAge(timeout); } httpServletResponse.addCookie(cookie); } catch (KeyManagerException e) { log.warn("Unable to set single sign on cookie."); } }
From source file:net.ymate.platform.mvc.web.support.CookieHelper.java
/** * @param key /*from www . j av a2 s . co m*/ * @param value * @param maxAge * @return ?Cookie */ public CookieHelper setCookie(String key, String value, int maxAge) { Cookie _cookie = new Cookie(WebMVC.getConfig().getCookiePrefix() + key, StringUtils.isBlank(value) ? "" : encodeValue(value)); _cookie.setMaxAge(maxAge); _cookie.setPath(WebMVC.getConfig().getCookiePath()); if (StringUtils.isNotBlank(WebMVC.getConfig().getCookieDomain())) { _cookie.setDomain(WebMVC.getConfig().getCookieDomain()); } _cookie.setSecure(__request.getServerPort() == 443 ? true : false); WebContext.getResponse().addCookie(_cookie); return this; }
From source file:com.shenit.commons.utils.HttpUtils.java
/** * cookie//from ww w . ja v a 2s. c om * * @param name * Cookie?? * @param val * * @param expiry * * @param domain * * @param path * * @param httpOnly * ??HTTPcooie * @param secure * ?SSL * @return */ public static Cookie cookie(String name, Object val, Integer expiry, String domain, String path, boolean httpOnly, boolean secure) { Cookie cookie = new Cookie(name, val == null ? null : val.toString()); if (expiry != null) cookie.setMaxAge(expiry); if (!StringUtils.isEmpty(domain)) cookie.setDomain(domain); cookie.setSecure(secure); if (!StringUtils.isEmpty(path)) cookie.setPath(path); cookie.setHttpOnly(httpOnly); return cookie; }
From source file:com.silverpeas.authentication.AuthenticationServlet.java
/** * Write session cookie./* ww w .j a va 2 s .c o m*/ * * @return */ private void writeSessionCookie(HttpServletResponse response, HttpSession session, boolean secured) { Cookie cookie = new Cookie("JSESSIONID", session.getId()); cookie.setMaxAge(-1); cookie.setPath(session.getServletContext().getContextPath()); cookie.setHttpOnly(true); if (secured) { cookie.setSecure(secured); } response.addCookie(cookie); }