From 3fdf93ea46a13047e8c579b10ea823194f40ce98 Mon Sep 17 00:00:00 2001 From: Ricardo Zanini <1538000+ricardozanini@users.noreply.github.com> Date: Wed, 21 May 2025 08:52:40 -0300 Subject: [PATCH] Fix #1151 - Fail on scenarios where OAuth2 is required and OIDC is not in the classpath (#1152) * Fix #1151 - Fail on scenarios where OAuth2 is required and OIDC is not in the classpath Signed-off-by: Ricardo Zanini * Added missing dependencies to mvn profile Signed-off-by: Ricardo Zanini --------- Signed-off-by: Ricardo Zanini --- .../deployment/GeneratorProcessor.java | 26 ++++++++++++++----- .../generation-tests/pom.xml | 25 ++++++++++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/GeneratorProcessor.java b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/GeneratorProcessor.java index 397e43974..1d48b9849 100644 --- a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/GeneratorProcessor.java +++ b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/GeneratorProcessor.java @@ -128,14 +128,10 @@ void produceCompositeProviders(AuthenticationRecorder recorder, List authenticationProviders, BuildProducer beanProducer, + BuildProducer authenticationProviders, + BuildProducer beanProducer, OidcAuthenticationRecorder oidcRecorder) { - if (!isClassPresentAtRuntime(ABSTRACT_TOKEN_PRODUCER)) { - LOGGER.debug("{} class not found in runtime, skipping OAuth bean generation", ABSTRACT_TOKEN_PRODUCER); - return; - } - LOGGER.debug("{} class found in runtime, producing OAuth bean generation", ABSTRACT_TOKEN_PRODUCER); Collection authenticationMarkers = beanArchiveBuildItem.getIndex() .getAnnotationsWithRepeatable(OAUTH_AUTHENTICATION_MARKER, beanArchiveBuildItem.getIndex()) .stream() @@ -145,6 +141,24 @@ void produceOauthAuthentication(CombinedIndexBuildItem beanArchiveBuildItem, (existing, duplicate) -> existing)) .values(); + if (!isClassPresentAtRuntime(ABSTRACT_TOKEN_PRODUCER)) { + if (!authenticationMarkers.isEmpty()) { + throw new IllegalStateException( + "OAuth2 flows detected in spec(s) " + + authenticationMarkers.stream() + .map(m -> m.value("openApiSpecId").asString()) + .distinct() + .collect(Collectors.joining(", ")) + + + " but quarkus-openapi-generator-oidc and quarkus-rest-client-oidc-filter or quarkus-oidc-client-reactive-filter are not on the classpath. " + + + "Please add those dependencies to your project. See https://docs.quarkiverse.io/quarkus-openapi-generator/dev/client.html#_oauth2_authentication"); + } + LOGGER.debug("{} class not found in runtime, skipping OAuth bean generation", ABSTRACT_TOKEN_PRODUCER); + return; + } + LOGGER.debug("{} class found in runtime, producing OAuth bean generation", ABSTRACT_TOKEN_PRODUCER); + Map> operationsBySpec = getOperationsBySpec(beanArchiveBuildItem); for (AnnotationInstance authenticationMarker : authenticationMarkers) { diff --git a/client/integration-tests/generation-tests/pom.xml b/client/integration-tests/generation-tests/pom.xml index eaf425e01..537bbae6e 100644 --- a/client/integration-tests/generation-tests/pom.xml +++ b/client/integration-tests/generation-tests/pom.xml @@ -15,6 +15,10 @@ io.quarkiverse.openapi.generator quarkus-openapi-generator + + io.quarkiverse.openapi.generator + quarkus-openapi-generator-oidc + io.quarkiverse.openapi.generator quarkus-openapi-generator-it-generation-input @@ -92,5 +96,26 @@ native + + resteasy-classic + + true + + + + io.quarkus + quarkus-resteasy-client-oidc-filter + + + + + resteasy-reactive + + + io.quarkus + quarkus-rest-client-oidc-filter + + +