class CookieRenewingFilter implements ContainerResponseFilter {

  @Override public void filter(ContainerRequestContext request, ContainerResponseContext response)
      throws IOException {
    String sessionCookieName = sessionCookieConfig.getName();
    // If the response will be setting a session cookie, don't overwrite it; just let it go.
    if (response.getCookies().containsKey(sessionCookieName)) {
      return;
    }

    // If the request doesn't have a session cookie, we're not going to renew one.
    if (!request.getCookies().containsKey(sessionCookieName)) {
      return;
    }

    Cookie requestCookie = request.getCookies().get(sessionCookieName);
    Optional<User> optionalUser = authenticator.authenticate(requestCookie);
    if (optionalUser.isPresent()) {
      sessionLoginResource.cookiesForUser(optionalUser.get())
          .forEach(c -> response.getHeaders().add(HttpHeaders.SET_COOKIE, c));
    }
  }

  @Inject public  CookieRenewingFilter(@SessionCookie CookieConfig sessionCookieConfig,
      CookieAuthenticator authenticator, SessionLoginResource sessionLoginResource);

}