List of usage examples for javax.servlet.http HttpServletResponse addCookie
public void addCookie(Cookie cookie);
From source file:fr.mby.portal.coreimpl.aggregator.HeaderAggregator.java
@Override public void aggregate(final HttpServletResponse response, final IInternalReply reply) { // Add cookies final Collection<Cookie> cookies = reply.getCookies(); if (!CollectionUtils.isEmpty(cookies)) { for (final Cookie cookie : cookies) { response.addCookie(cookie); }//from www . j a v a 2s. co m } // Add headers final Map<String, String> headers = reply.getHeaders(); if (!CollectionUtils.isEmpty(headers)) { for (final Entry<String, String> header : headers.entrySet()) { response.addHeader(header.getKey(), header.getValue()); } } }
From source file:com.ms.commons.summer.security.web.DefaultSecurityFormResolver.java
/** * ?tokenCookie//w w w . j av a 2 s . co m * * @param request * @param str */ public void renderSessionTokenInput(final HttpServletRequest request, final HttpServletResponse response, final StringBuilder str) { String token = createToken(); Cookie cookie = new Cookie(FORM_RESUBMIT_TOKEN, token); cookie.setPath("/"); response.addCookie(cookie); str.append("<input type=\"hidden\" name=\"").append(FORM_RESUBMIT_TOKEN).append("\" value=\"").append(token) .append("\"/>"); if (logger.isDebugEnabled()) { logger.debug("render session token value = " + token); } }
From source file:com.music.web.SocialSignInAdapter.java
public void addPermanentCookies(User user, HttpServletResponse response) { Cookie authTokenCookie = new Cookie(AUTH_TOKEN_COOKIE_NAME, user.getLoginToken()); authTokenCookie.setMaxAge(COOKIE_AGE); authTokenCookie.setPath("/"); authTokenCookie.setDomain(".computoser.com"); response.addCookie(authTokenCookie); Cookie seriesCookie = new Cookie(AUTH_TOKEN_SERIES_COOKIE_NAME, user.getLoginSeries()); seriesCookie.setMaxAge(COOKIE_AGE);/* w ww .j a v a 2s .c o m*/ seriesCookie.setPath("/"); seriesCookie.setDomain(".computoser.com"); response.addCookie(seriesCookie); }
From source file:am.ik.categolj2.app.authentication.AuthenticationHelper.java
void removeCookie(String cookieName, HttpServletResponse response) throws UnsupportedEncodingException { Cookie cookie = new Cookie(cookieName, URLEncoder.encode("", "UTF-8")); cookie.setMaxAge(0);/*w ww. j a v a2 s . c o m*/ response.addCookie(cookie); }
From source file:org.chos.transaction.passport.HttpContextSessionManager.java
private Session openSession0(Session session, HttpServletResponse response) { Cookie cookie = new Cookie(USER_TOKEN, session.getToken()); // cookie.setSecure(true); cookie.setPath("/"); cookie.setHttpOnly(true);/*from w w w . j av a2 s . co m*/ response.addCookie(cookie); return session; }
From source file:com.edgenius.wiki.integration.client.Authentication.java
private void setCookie(String[] tokens, int maxAge, String targetWebContext, HttpServletRequest request, HttpServletResponse response) { String cookieValue = encodeCookie(tokens); Cookie cookie = new Cookie(WsContants.REMEMBER_ME_COOKIE_NAME, cookieValue); cookie.setMaxAge(maxAge);//from ww w . j a va2 s . co m cookie.setPath(targetWebContext); response.addCookie(cookie); }
From source file:com.vmware.identity.openidconnect.protocol.HttpResponse.java
public void applyTo(HttpServletResponse httpServletResponse) throws IOException { Validate.notNull(httpServletResponse, "httpServletResponse"); for (Cookie cookie : this.cookies) { httpServletResponse.addCookie(cookie); }/*from www .j av a 2 s. c o m*/ for (Header header : this.headers) { httpServletResponse.addHeader(header.getName(), header.getValue()); } if (this.errorObject != null) { httpServletResponse.sendError(this.errorObject.getStatusCode().getValue(), this.errorObject.getErrorCode().getValue() + ": " + this.errorObject.getDescription()); } else if (this.redirectTarget != null) { httpServletResponse.sendRedirect(this.redirectTarget.toString()); } else if (this.htmlContent != null) { httpServletResponse.setStatus(this.statusCode.getValue()); httpServletResponse.setHeader("Cache-Control", "no-cache, no-store"); httpServletResponse.setHeader("Pragma", "no-cache"); httpServletResponse.setContentType("text/html;charset=UTF-8"); PrintWriter writer = httpServletResponse.getWriter(); writer.print(this.htmlContent); writer.close(); } else if (this.jsonContent != null) { httpServletResponse.setStatus(this.statusCode.getValue()); httpServletResponse.setHeader("Cache-Control", "no-store"); httpServletResponse.setHeader("Pragma", "no-cache"); httpServletResponse.setContentType("application/json;charset=UTF-8"); PrintWriter writer = httpServletResponse.getWriter(); writer.print(this.jsonContent.toString()); writer.close(); } else { throw new IllegalStateException("unexpected"); } }
From source file:csns.web.controller.IndexController.java
@RequestMapping({ "/department/{dept}/", "/department/{dept}" }) public String index(@PathVariable String dept, ModelMap models, HttpServletResponse response) { Department department = departmentDao.getDepartment(dept); if (department == null) return "redirect:/"; Cookie cookie = new Cookie("default-dept", dept); cookie.setPath("/"); cookie.setMaxAge(100000000);// w w w.j a va 2 s.c o m response.addCookie(cookie); models.addAttribute("department", department); models.addAttribute("newses", newsDao.getNews(department)); return "department/index"; }
From source file:com.erudika.para.utils.Utils.java
/** * Sets a cookie.// w ww. j a va 2 s . com * @param name the name * @param value the value * @param req HTTP request * @param res HTTP response * @param httpOnly HTTP only flag * @param maxAge max age */ public static void setRawCookie(String name, String value, HttpServletRequest req, HttpServletResponse res, boolean httpOnly, int maxAge) { if (StringUtils.isBlank(name) || StringUtils.isBlank(value) || req == null || res == null) { return; } Cookie cookie = new Cookie(name, value); cookie.setHttpOnly(httpOnly); cookie.setMaxAge(maxAge < 0 ? Config.SESSION_TIMEOUT_SEC.intValue() : maxAge); cookie.setPath("/"); cookie.setSecure(req.isSecure()); res.addCookie(cookie); }
From source file:org.apereo.portal.url.UrlCanonicalizingFilter.java
protected void clearRedirectCount(HttpServletRequest request, HttpServletResponse response) { final Cookie cookie = new Cookie(COOKIE_NAME, ""); cookie.setPath(request.getContextPath()); cookie.setMaxAge(0);/* w ww. j av a 2 s .c o m*/ response.addCookie(cookie); }