@Test public void unauthorized_invalidClient_assertion_type() throws Exception { Client client = mock(Client.class); HttpServerRequest httpServerRequest = mock(HttpServerRequest.class); when(httpServerRequest.getParam(Parameters.CLIENT_ASSERTION_TYPE)).thenReturn("unknown"); when(httpServerRequest.getParam(Parameters.CLIENT_ASSERTION)).thenReturn("dummy"); RoutingContext context = mock(RoutingContext.class); when(context.request()).thenReturn(httpServerRequest); when(context.get(CONTEXT_PATH)).thenReturn("/"); when(clientAssertionService.assertClient(any(),any(),any())).thenReturn(Maybe.error(new InvalidClientException("Unknown or unsupported assertion_type"))); CountDownLatch latch = new CountDownLatch(1); authProvider.handle(client, context, clientAsyncResult -> { latch.countDown(); Assert.assertNotNull(clientAsyncResult); Assert.assertTrue(clientAsyncResult.failed()); Assert.assertTrue(clientAsyncResult.cause() instanceof InvalidClientException); }); assertTrue(latch.await(10, TimeUnit.SECONDS)); }
@Override public void handle(Client client, RoutingContext context, Handler<AsyncResult<Client>> handler) { HttpServerRequest request = context.request(); String clientAssertionType = getClientAssertionType(request); String clientAssertion = getClientAssertion(request); String clientId = request.getParam(Parameters.CLIENT_ID); String basePath = UriBuilderRequest.resolveProxyRequest(context); clientAssertionService.assertClient(clientAssertionType, clientAssertion, basePath) .flatMap(client1 -> { if(clientId != null && !clientId.equals(client1.getClientId())) { return Maybe.error(new InvalidClientException("client_id parameter does not match with assertion")); } return Maybe.just(client1); }) .subscribe( client1 -> handler.handle(Future.succeededFuture(client1)), throwable -> { if (throwable instanceof InvalidClientException) { logger.debug("Failed to authenticate client with assertion method", throwable); handler.handle(Future.failedFuture(throwable)); } else { logger.error("Failed to authenticate client with assertion method", throwable); handler.handle(Future.failedFuture(new InvalidClientException("Invalid client: Failed to authenticate client with assertion method", throwable))); } }, () -> handler.handle(Future.failedFuture(new InvalidClientException(ClientAuthHandler.GENERIC_ERROR_MESSAGE))) ); }
ClientAssertionAuthProvider implements ClientAuthProvider { @Override public void handle(Client client, RoutingContext context, Handler<AsyncResult<Client>> handler) { HttpServerRequest request = context.request(); String clientAssertionType = getClientAssertionType(request); String clientAssertion = getClientAssertion(request); String clientId = request.getParam(Parameters.CLIENT_ID); String basePath = UriBuilderRequest.resolveProxyRequest(context); clientAssertionService.assertClient(clientAssertionType, clientAssertion, basePath) .flatMap(client1 -> { if(clientId != null && !clientId.equals(client1.getClientId())) { return Maybe.error(new InvalidClientException("client_id parameter does not match with assertion")); } return Maybe.just(client1); }) .subscribe( client1 -> handler.handle(Future.succeededFuture(client1)), throwable -> { if (throwable instanceof InvalidClientException) { logger.debug("Failed to authenticate client with assertion method", throwable); handler.handle(Future.failedFuture(throwable)); } else { logger.error("Failed to authenticate client with assertion method", throwable); handler.handle(Future.failedFuture(new InvalidClientException("Invalid client: Failed to authenticate client with assertion method", throwable))); } }, () -> handler.handle(Future.failedFuture(new InvalidClientException(ClientAuthHandler.GENERIC_ERROR_MESSAGE))) ); } }
ClientAssertionAuthProvider implements ClientAuthProvider { @Override public void handle(Client client, RoutingContext context, Handler<AsyncResult<Client>> handler) { HttpServerRequest request = context.request(); String clientAssertionType = getClientAssertionType(request); String clientAssertion = getClientAssertion(request); String clientId = request.getParam(Parameters.CLIENT_ID); String basePath = UriBuilderRequest.resolveProxyRequest(context); clientAssertionService.assertClient(clientAssertionType, clientAssertion, basePath) .flatMap(client1 -> { if(clientId != null && !clientId.equals(client1.getClientId())) { return Maybe.error(new InvalidClientException("client_id parameter does not match with assertion")); } return Maybe.just(client1); }) .subscribe( client1 -> handler.handle(Future.succeededFuture(client1)), throwable -> { if (throwable instanceof InvalidClientException) { logger.debug("Failed to authenticate client with assertion method", throwable); handler.handle(Future.failedFuture(throwable)); } else { logger.error("Failed to authenticate client with assertion method", throwable); handler.handle(Future.failedFuture(new InvalidClientException("Invalid client: Failed to authenticate client with assertion method", throwable))); } }, () -> handler.handle(Future.failedFuture(new InvalidClientException(ClientAuthHandler.GENERIC_ERROR_MESSAGE))) ); } ClientAssertionAuthProvider();  ClientAssertionAuthProvider(ClientAssertionService clientAssertionService); }
ClientAssertionAuthProvider implements ClientAuthProvider { @Override public void handle(Client client, RoutingContext context, Handler<AsyncResult<Client>> handler) { HttpServerRequest request = context.request(); String clientAssertionType = getClientAssertionType(request); String clientAssertion = getClientAssertion(request); String clientId = request.getParam(Parameters.CLIENT_ID); String basePath = UriBuilderRequest.resolveProxyRequest(context); clientAssertionService.assertClient(clientAssertionType, clientAssertion, basePath) .flatMap(client1 -> { if(clientId != null && !clientId.equals(client1.getClientId())) { return Maybe.error(new InvalidClientException("client_id parameter does not match with assertion")); } return Maybe.just(client1); }) .subscribe( client1 -> handler.handle(Future.succeededFuture(client1)), throwable -> { if (throwable instanceof InvalidClientException) { logger.debug("Failed to authenticate client with assertion method", throwable); handler.handle(Future.failedFuture(throwable)); } else { logger.error("Failed to authenticate client with assertion method", throwable); handler.handle(Future.failedFuture(new InvalidClientException("Invalid client: Failed to authenticate client with assertion method", throwable))); } }, () -> handler.handle(Future.failedFuture(new InvalidClientException(ClientAuthHandler.GENERIC_ERROR_MESSAGE))) ); } ClientAssertionAuthProvider();  ClientAssertionAuthProvider(ClientAssertionService clientAssertionService); @Override boolean canHandle(Client client, RoutingContext context); @Override void handle(Client client, RoutingContext context, Handler<AsyncResult<Client>> handler); void setClientAssertionService(ClientAssertionService clientAssertionService); }
ClientAssertionAuthProvider implements ClientAuthProvider { @Override public void handle(Client client, RoutingContext context, Handler<AsyncResult<Client>> handler) { HttpServerRequest request = context.request(); String clientAssertionType = getClientAssertionType(request); String clientAssertion = getClientAssertion(request); String clientId = request.getParam(Parameters.CLIENT_ID); String basePath = UriBuilderRequest.resolveProxyRequest(context); clientAssertionService.assertClient(clientAssertionType, clientAssertion, basePath) .flatMap(client1 -> { if(clientId != null && !clientId.equals(client1.getClientId())) { return Maybe.error(new InvalidClientException("client_id parameter does not match with assertion")); } return Maybe.just(client1); }) .subscribe( client1 -> handler.handle(Future.succeededFuture(client1)), throwable -> { if (throwable instanceof InvalidClientException) { logger.debug("Failed to authenticate client with assertion method", throwable); handler.handle(Future.failedFuture(throwable)); } else { logger.error("Failed to authenticate client with assertion method", throwable); handler.handle(Future.failedFuture(new InvalidClientException("Invalid client: Failed to authenticate client with assertion method", throwable))); } }, () -> handler.handle(Future.failedFuture(new InvalidClientException(ClientAuthHandler.GENERIC_ERROR_MESSAGE))) ); } ClientAssertionAuthProvider();  ClientAssertionAuthProvider(ClientAssertionService clientAssertionService); @Override boolean canHandle(Client client, RoutingContext context); @Override void handle(Client client, RoutingContext context, Handler<AsyncResult<Client>> handler); void setClientAssertionService(ClientAssertionService clientAssertionService);  }