Middlewares { public static <T> Middleware<Requested<Authenticated<Response<T>>>, SyncHandler<Response<T>>> authed( RequestAuthenticator authenticator) { return ar -> rc -> ar .apply(rc) .apply(auth(rc, authenticator)); } private  Middlewares(); static Middleware<SyncHandler<? extends Response<?>>, AsyncHandler<Response<ByteString>>> json(); static Middleware<AsyncHandler<Response<T>>, AsyncHandler<Response<T>>> clientValidator(
      Supplier<Set<String>> supplier); static Middleware<AsyncHandler<Response<T>>, AsyncHandler<Response<T>>> exceptionAndRequestIdHandler(); static Middleware<AsyncHandler<Response<T>>, AsyncHandler<Response<T>>> tracer(
      Tracer tracer, String service); static Middleware<Requested<Authenticated<Response<T>>>, SyncHandler<Response<T>>> authed(
      RequestAuthenticator authenticator); static Middleware<Authenticated<EntityResponseHandler<E, R>>, SyncHandler<Response<ByteString>>> authedEntity(
      Middleware<EntityResponseHandler<E, R>, SyncHandler<Response<ByteString>>> entityMiddleware,
      Middleware<Requested<Authenticated<Response<ByteString>>>, SyncHandler<Response<ByteString>>> authed); static Middleware<Authenticated<EntityResponseHandler<E, R>>, SyncHandler<Response<ByteString>>> authedEntity(
      RequestAuthenticator authenticator,
      Middleware<EntityResponseHandler<E, R>, SyncHandler<Response<ByteString>>> entityMiddleware); static Middleware<AsyncHandler<Response<T>>, AsyncHandler<Response<T>>> authenticator(
      RequestAuthenticator authenticator);  }
@Test public void testAuthedProvidesIdToken() { final RequestContext requestContext = mock(RequestContext.class); final Request request = Request.forUri("/", "PUT") .withPayload(ByteString.encodeUtf8("hello")) .withHeader(HttpHeaders.AUTHORIZATION, "Bearer s3cr3tp455w0rd"); when(requestContext.request()).thenReturn(request); when(authenticator.authenticate(any())).thenReturn(() -> Optional.of(idToken)); final Response<Boolean> response = Middlewares.<Boolean>authed(authenticator) .apply(rc -> ac -> Response.forPayload(ac.user().map(idToken::equals).orElse(false))) .invoke(requestContext); assertThat(response.payload(), is(Optional.of(true))); }