List of usage examples for javax.servlet.http Cookie setDomain
public void setDomain(String domain)
From source file:de.hska.ld.core.config.security.AjaxLogoutSuccessHandler.java
@Override public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { ///*from w w w . j a va2 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.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 a v a 2s . com*/ */ 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); }
From source file:org.piwik.ResponseData.java
public List<Cookie> getCookies() { List<Cookie> cookies = new ArrayList<Cookie>(); for (String key : headerData.keySet()) { List<String> headerParts = headerData.get(key); StringBuilder cookieInfo = new StringBuilder(); for (String part : headerParts) { cookieInfo.append(part);/*from ww w.j a v a2 s . c o m*/ } if (key == null && cookieInfo.toString().equals("")) { LOGGER.debug("No more headers, not proceeding"); return null; } if (key == null) { LOGGER.debug("The header value contains the server's HTTP version, not proceeding"); } else if (key.equals("Set-Cookie")) { List<HttpCookie> httpCookies = HttpCookie.parse(cookieInfo.toString()); for (HttpCookie h : httpCookies) { Cookie c = new Cookie(h.getName(), h.getValue()); c.setComment(h.getComment()); if (h.getDomain() != null) { c.setDomain(h.getDomain()); } c.setMaxAge(Long.valueOf(h.getMaxAge()).intValue()); c.setPath(h.getPath()); c.setSecure(h.getSecure()); c.setVersion(h.getVersion()); cookies.add(c); } } else { LOGGER.debug("The provided key (" + key + ") with value (" + cookieInfo + ") were not processed because the key is unknown"); } } return cookies; }
From source file:org.craftercms.commons.http.CookieManager.java
/** * Add a new cookie, using the configured domain, path and max age, to the response. * * @param name the name of the cookie//from ww w .j a v a 2 s. c o m * @param value the value of the cookie */ public void addCookie(String name, String value, HttpServletResponse response) { Cookie cookie = new Cookie(name, value); cookie.setHttpOnly(httpOnly); cookie.setSecure(secure); if (StringUtils.isNotEmpty(domain)) { cookie.setDomain(domain); } if (StringUtils.isNotEmpty(path)) { cookie.setPath(path); } if (maxAge != null) { cookie.setMaxAge(maxAge); } response.addCookie(cookie); logger.debug(LOG_KEY_ADDED_COOKIE, name); }
From source file:com.wavemaker.spinup.web.SpinupController.java
/** * Postback method from the login form. Will either re-direct back to the form (in the case of errors) or redirect * to start the spinup process.//ww w .ja v a 2 s.c o m * * @param credentials User credentials * @param bindingResult the binding result from the form * @param request the HTTP request * @param response the HTTP response * @return the response (either a redirect to the form or a redirect to the spinup process) */ @RequestMapping(value = "/login", method = RequestMethod.POST) public ModelAndView processLogin(@Valid LoginCredentialsBean credentials, BindingResult bindingResult, HttpServletRequest request, HttpServletResponse response) { Assert.state(isAjaxRequest(request), "Unable to handle non AJAX post"); // If we have binding errors, re-render the page if (bindingResult.hasErrors()) { return new ModelAndView(); } try { // Login, add the cookie and redirect to start the spinup process this.logger.debug("Starting WaveMaker spinup"); SharedSecret secret = getSecret(request); TransportToken transportToken = this.spinupService.login(secret, credentials); this.logger.debug("Login complete"); String url = performSpinup(credentials, secret, transportToken, response); this.logger.debug("Perform spinup complete"); Cookie cookie = new Cookie(COOKIE_NAME, transportToken.encode()); cookie.setMaxAge(COOKIE_MAX_AGE); cookie.setDomain(this.spinupService.getDomain()); response.addCookie(cookie); response.setHeader("X-Ajax-Redirect", url); response.setStatus(HttpStatus.NO_CONTENT.value()); this.logger.debug("Wavemake spinup complete"); return null; } catch (InvalidLoginCredentialsException e) { // On invalid login redirect with a message in flash scope return new ModelAndView().addObject("message", "Unable to login, please check your credentials"); } }
From source file:com.mawujun.util.web.CookieGenerator.java
/** * Create a cookie with the given value, using the cookie descriptor * settings of this generator (except for "cookieMaxAge"). * @param cookieValue the value of the cookie to crate * @return the cookie/*from ww w. j a v a 2 s .c o m*/ * @see #setCookieName * @see #setCookieDomain * @see #setCookiePath */ protected Cookie createCookie(String cookieValue) { Cookie cookie = new Cookie(getCookieName(), cookieValue); if (getCookieDomain() != null) { cookie.setDomain(getCookieDomain()); } cookie.setPath(getCookiePath()); return cookie; }
From source file:com.swdouglass.joid.consumer.OpenIdFilter.java
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { // basically just check for openId parameters HttpServletRequest request = (HttpServletRequest) servletRequest; if (servletRequest.getParameter(OPENID_ATTRIBUTE) != null && !ignored(request)) { try {/* ww w . j av a 2 s .c o m*/ @SuppressWarnings("unchecked") AuthenticationResult result = joid .authenticate(convertToStringValueMap(servletRequest.getParameterMap())); String identity = result.getIdentity(); if (identity != null) { HttpServletRequest req = (HttpServletRequest) servletRequest; req.getSession(true).setAttribute(OpenIdFilter.OPENID_ATTRIBUTE, identity); HttpServletResponse resp = (HttpServletResponse) servletResponse; // could check this before setting Cookie cookie = new Cookie(OPENID_ATTRIBUTE, identity); if (cookieDomain != null) { cookie.setDomain(cookieDomain); } if (cookieMaxAge != null) { cookie.setMaxAge(cookieMaxAge); } resp.addCookie(cookie); // redirect to get rid of the long url resp.sendRedirect(result.getResponse().getReturnTo()); return; } } catch (AuthenticationException e) { e.printStackTrace(); log.info("auth failed: " + e.getMessage()); // should this be handled differently? } catch (Exception e) { e.printStackTrace(); } } filterChain.doFilter(servletRequest, servletResponse); }
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);/*ww w .jav a2 s. c o m*/ 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:com.mmj.app.common.checkcode.CheckCodeManager.java
public byte[] create(CookieManager cookieManager, CookieNameEnum maimaijunCheckcode, HttpServletResponse response) {/*from w ww . j ava 2 s .co m*/ 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; }
From source file:org.jasig.portal.portlet.container.services.SessionOnlyPortletCookieImpl.java
@Override public Cookie toCookie() { Cookie cookie = new Cookie(name, value); cookie.setComment(comment);/*from w w w . j ava 2 s . c o m*/ if (domain != null) { cookie.setDomain(domain); } cookie.setMaxAge(getMaxAge()); cookie.setPath(path); cookie.setSecure(secure); cookie.setVersion(version); return cookie; }