@Test public void doesNothingWhenResponseSetsSessionCookie() throws Exception { ImmutableMap<String, NewCookie> immutableResponseCookies = ImmutableMap.of(SESSION_COOKIE, NewCookie.valueOf(cookie.getValue())); when(response.getCookies()).thenReturn(immutableResponseCookies); filter.filter(request, response); assertThat(response.getCookies()).isSameAs(immutableResponseCookies); assertThat(response.getHeaders()).doesNotContainKey(SET_COOKIE); }
@Override public void filter(ContainerRequestContext request, ContainerResponseContext response) throws IOException { String sessionCookieName = sessionCookieConfig.getName(); if (response.getCookies().containsKey(sessionCookieName)) { return; } 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)); } }
CookieRenewingFilter implements ContainerResponseFilter { @Override public void filter(ContainerRequestContext request, ContainerResponseContext response) throws IOException { String sessionCookieName = sessionCookieConfig.getName(); if (response.getCookies().containsKey(sessionCookieName)) { return; } 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)); } } }
CookieRenewingFilter implements ContainerResponseFilter { @Override public void filter(ContainerRequestContext request, ContainerResponseContext response) throws IOException { String sessionCookieName = sessionCookieConfig.getName(); if (response.getCookies().containsKey(sessionCookieName)) { return; } 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  CookieRenewingFilter(@SessionCookie CookieConfig sessionCookieConfig,
      CookieAuthenticator authenticator, SessionLoginResource sessionLoginResource); }
CookieRenewingFilter implements ContainerResponseFilter { @Override public void filter(ContainerRequestContext request, ContainerResponseContext response) throws IOException { String sessionCookieName = sessionCookieConfig.getName(); if (response.getCookies().containsKey(sessionCookieName)) { return; } 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  CookieRenewingFilter(@SessionCookie CookieConfig sessionCookieConfig,
      CookieAuthenticator authenticator, SessionLoginResource sessionLoginResource); @Override void filter(ContainerRequestContext request, ContainerResponseContext response); }
CookieRenewingFilter implements ContainerResponseFilter { @Override public void filter(ContainerRequestContext request, ContainerResponseContext response) throws IOException { String sessionCookieName = sessionCookieConfig.getName(); if (response.getCookies().containsKey(sessionCookieName)) { return; } 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  CookieRenewingFilter(@SessionCookie CookieConfig sessionCookieConfig,
      CookieAuthenticator authenticator, SessionLoginResource sessionLoginResource); @Override void filter(ContainerRequestContext request, ContainerResponseContext response);  }