@Test public void successfulAuth() throws Exception { User user = User.named("username"); Cookie sessionCookie = new Cookie("session", "valid-session"); cookies.put(sessionCookie.getName(), sessionCookie); when(cookieAuthenticator.authenticate(sessionCookie)).thenReturn(Optional.of(user)); assertThat(factory.provide(request)).isEqualTo(user); }
public User provide(ContainerRequest request) { Cookie sessionCookie = request.getCookies().get(sessionCookieName); if (sessionCookie == null) { logger.warn("No session cookie in request."); throw new NotAuthorizedException("Bad session"); } try { return authenticator.authenticate(sessionCookie) .orElseThrow(() -> new NotAuthorizedException("Bad session")); } catch (AuthenticationException e) { throw Throwables.propagate(e); } }
UserAuthFactory { public User provide(ContainerRequest request) { Cookie sessionCookie = request.getCookies().get(sessionCookieName); if (sessionCookie == null) { logger.warn("No session cookie in request."); throw new NotAuthorizedException("Bad session"); } try { return authenticator.authenticate(sessionCookie) .orElseThrow(() -> new NotAuthorizedException("Bad session")); } catch (AuthenticationException e) { throw Throwables.propagate(e); } } }
UserAuthFactory { public User provide(ContainerRequest request) { Cookie sessionCookie = request.getCookies().get(sessionCookieName); if (sessionCookie == null) { logger.warn("No session cookie in request."); throw new NotAuthorizedException("Bad session"); } try { return authenticator.authenticate(sessionCookie) .orElseThrow(() -> new NotAuthorizedException("Bad session")); } catch (AuthenticationException e) { throw Throwables.propagate(e); } } @Inject  UserAuthFactory(CookieAuthenticator cookieAuthenticator,
      @SessionCookie CookieConfig cookieConfig); }
UserAuthFactory { public User provide(ContainerRequest request) { Cookie sessionCookie = request.getCookies().get(sessionCookieName); if (sessionCookie == null) { logger.warn("No session cookie in request."); throw new NotAuthorizedException("Bad session"); } try { return authenticator.authenticate(sessionCookie) .orElseThrow(() -> new NotAuthorizedException("Bad session")); } catch (AuthenticationException e) { throw Throwables.propagate(e); } } @Inject  UserAuthFactory(CookieAuthenticator cookieAuthenticator,
      @SessionCookie CookieConfig cookieConfig); User provide(ContainerRequest request); }
UserAuthFactory { public User provide(ContainerRequest request) { Cookie sessionCookie = request.getCookies().get(sessionCookieName); if (sessionCookie == null) { logger.warn("No session cookie in request."); throw new NotAuthorizedException("Bad session"); } try { return authenticator.authenticate(sessionCookie) .orElseThrow(() -> new NotAuthorizedException("Bad session")); } catch (AuthenticationException e) { throw Throwables.propagate(e); } } @Inject  UserAuthFactory(CookieAuthenticator cookieAuthenticator,
      @SessionCookie CookieConfig cookieConfig); User provide(ContainerRequest request);  }