Skip to content

Commit 7574151

Browse files
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 <[email protected]> * Added missing dependencies to mvn profile Signed-off-by: Ricardo Zanini <[email protected]> --------- Signed-off-by: Ricardo Zanini <[email protected]>
1 parent 6ab80b2 commit 7574151

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/GeneratorProcessor.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,10 @@ void produceCompositeProviders(AuthenticationRecorder recorder, List<AuthProvide
128128
@BuildStep
129129
@Record(ExecutionTime.STATIC_INIT)
130130
void produceOauthAuthentication(CombinedIndexBuildItem beanArchiveBuildItem,
131-
BuildProducer<AuthProviderBuildItem> authenticationProviders, BuildProducer<SyntheticBeanBuildItem> beanProducer,
131+
BuildProducer<AuthProviderBuildItem> authenticationProviders,
132+
BuildProducer<SyntheticBeanBuildItem> beanProducer,
132133
OidcAuthenticationRecorder oidcRecorder) {
133134

134-
if (!isClassPresentAtRuntime(ABSTRACT_TOKEN_PRODUCER)) {
135-
LOGGER.debug("{} class not found in runtime, skipping OAuth bean generation", ABSTRACT_TOKEN_PRODUCER);
136-
return;
137-
}
138-
LOGGER.debug("{} class found in runtime, producing OAuth bean generation", ABSTRACT_TOKEN_PRODUCER);
139135
Collection<AnnotationInstance> authenticationMarkers = beanArchiveBuildItem.getIndex()
140136
.getAnnotationsWithRepeatable(OAUTH_AUTHENTICATION_MARKER, beanArchiveBuildItem.getIndex())
141137
.stream()
@@ -145,6 +141,24 @@ void produceOauthAuthentication(CombinedIndexBuildItem beanArchiveBuildItem,
145141
(existing, duplicate) -> existing))
146142
.values();
147143

144+
if (!isClassPresentAtRuntime(ABSTRACT_TOKEN_PRODUCER)) {
145+
if (!authenticationMarkers.isEmpty()) {
146+
throw new IllegalStateException(
147+
"OAuth2 flows detected in spec(s) " +
148+
authenticationMarkers.stream()
149+
.map(m -> m.value("openApiSpecId").asString())
150+
.distinct()
151+
.collect(Collectors.joining(", "))
152+
+
153+
" but quarkus-openapi-generator-oidc and quarkus-rest-client-oidc-filter or quarkus-oidc-client-reactive-filter are not on the classpath. "
154+
+
155+
"Please add those dependencies to your project. See https://docs.quarkiverse.io/quarkus-openapi-generator/dev/client.html#_oauth2_authentication");
156+
}
157+
LOGGER.debug("{} class not found in runtime, skipping OAuth bean generation", ABSTRACT_TOKEN_PRODUCER);
158+
return;
159+
}
160+
LOGGER.debug("{} class found in runtime, producing OAuth bean generation", ABSTRACT_TOKEN_PRODUCER);
161+
148162
Map<String, List<AnnotationInstance>> operationsBySpec = getOperationsBySpec(beanArchiveBuildItem);
149163

150164
for (AnnotationInstance authenticationMarker : authenticationMarkers) {

client/integration-tests/generation-tests/pom.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
<groupId>io.quarkiverse.openapi.generator</groupId>
1616
<artifactId>quarkus-openapi-generator</artifactId>
1717
</dependency>
18+
<dependency>
19+
<groupId>io.quarkiverse.openapi.generator</groupId>
20+
<artifactId>quarkus-openapi-generator-oidc</artifactId>
21+
</dependency>
1822
<dependency>
1923
<groupId>io.quarkiverse.openapi.generator</groupId>
2024
<artifactId>quarkus-openapi-generator-it-generation-input</artifactId>
@@ -92,5 +96,26 @@
9296
<quarkus.package.type>native</quarkus.package.type>
9397
</properties>
9498
</profile>
99+
<profile>
100+
<id>resteasy-classic</id>
101+
<activation>
102+
<activeByDefault>true</activeByDefault>
103+
</activation>
104+
<dependencies>
105+
<dependency>
106+
<groupId>io.quarkus</groupId>
107+
<artifactId>quarkus-resteasy-client-oidc-filter</artifactId>
108+
</dependency>
109+
</dependencies>
110+
</profile>
111+
<profile>
112+
<id>resteasy-reactive</id>
113+
<dependencies>
114+
<dependency>
115+
<groupId>io.quarkus</groupId>
116+
<artifactId>quarkus-rest-client-oidc-filter</artifactId>
117+
</dependency>
118+
</dependencies>
119+
</profile>
95120
</profiles>
96121
</project>

0 commit comments

Comments
 (0)