Java Code Examples for org.eclipse.jetty.server.Response#addCookie()

The following examples show how to use org.eclipse.jetty.server.Response#addCookie() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuthenticatedEncryptedCookieFactory.java    From keywhiz with Apache License 2.0 5 votes vote down vote up
/**
 * Produces a cookie string for a given value and expiration.
 *
 * @param value value of new cookie.
 * @param expiration expiration time of cookie.
 * @return serialized cookie with given value and expiration.
 */
public NewCookie cookieFor(String value, ZonedDateTime expiration) {
  long maxAge = Duration.between(ZonedDateTime.now(clock), expiration).getSeconds();

  HttpCookie cookie = new HttpCookie(config.getName(), value, config.getDomain(),
      config.getPath(), maxAge, config.isHttpOnly(), config.isSecure());

  Response response = newResponse();
  response.addCookie(cookie);
  return NewCookie.valueOf(response.getHttpFields().get(HttpHeader.SET_COOKIE));
}
 
Example 2
Source File: AuthenticatedEncryptedCookieFactory.java    From keywhiz with Apache License 2.0 5 votes vote down vote up
/**
 * Produces an expired cookie string, used to update/overwrite an existing cookie.
 *
 * @return serialized expired cookie with matching parameters to authenticating cookie.
 */
public NewCookie getExpiredSessionCookie() {
  HttpCookie cookie = new HttpCookie(config.getName(), "expired", config.getDomain(), config.getPath(),
      0, config.isHttpOnly(), config.isSecure());

  Response response = newResponse();
  response.addCookie(cookie);
  return NewCookie.valueOf(response.getHttpFields().get(HttpHeader.SET_COOKIE));
}