@Test(expected = NotAuthorizedException.class) public void invalidSessionCookie() throws Exception { Cookie badSessionCookie = new Cookie("session", "bad-value"); cookies.put(badSessionCookie.getName(), badSessionCookie); when(cookieAuthenticator.authenticate(badSessionCookie)).thenReturn(Optional.empty()); factory.provide(request); }
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);  }