Skip to content

Commit 97d49d3

Browse files
committed
Add support for token-propagation-external-service6 with OpenID Connect integration
1 parent dec81cb commit 97d49d3

File tree

9 files changed

+64
-5
lines changed

9 files changed

+64
-5
lines changed

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/wrapper/QuarkusJavaClientCodegen.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ private void replaceWithQuarkusTemplateFiles() {
7575

7676
if (enableSecurityGeneration == null || enableSecurityGeneration) {
7777
if (ProcessUtils.hasHttpBasicMethods(this.openAPI) ||
78-
ProcessUtils.hasApiKeyMethods(this.openAPI) ||
79-
ProcessUtils.hasHttpBearerMethods(this.openAPI) ||
80-
ProcessUtils.hasOAuthMethods(this.openAPI) ||
81-
ProcessUtils.hasOpenIdConnectMethods(this.openAPI)) {
78+
ProcessUtils.hasApiKeyMethods(this.openAPI) ||
79+
ProcessUtils.hasHttpBearerMethods(this.openAPI) ||
80+
ProcessUtils.hasOAuthMethods(this.openAPI) ||
81+
ProcessUtils.hasOpenIdConnectMethods(this.openAPI)) {
8282
supportingFiles.add(
8383
new SupportingFile(AUTH_PACKAGE + "/compositeAuthenticationProvider.qute",
8484
authFileFolder(),

client/integration-tests/auth-provider/src/main/java/io/quarkiverse/openapi/generator/it/auth/TokenServerResource.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public class TokenServerResource {
2020
@RestClient
2121
org.acme.externalservice5.api.DefaultApi defaultApi5;
2222

23+
@RestClient
24+
org.acme.externalservice6.api.DefaultApi defaultApi6;
25+
2326
@POST
2427
@Path("service1")
2528
public String service1() {
@@ -47,4 +50,11 @@ public String service5() {
4750
defaultApi5.executeQuery5();
4851
return "hello";
4952
}
53+
54+
@POST
55+
@Path("service6")
56+
public String service6() {
57+
defaultApi6.executeQuery6();
58+
return "hello";
59+
}
5060
}

client/integration-tests/auth-provider/src/main/resources/application.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ quarkus.oidc-client.service5_oauth2.credentials.client-secret.value=secret
4646
quarkus.oidc-client.service6_oidc.auth-server-url=${keycloak.mock.service.url}
4747
quarkus.oidc-client.service6_oidc.discovery-enabled=true
4848
quarkus.oidc-client.service6_oidc.client-id=kogito-app
49+
quarkus.oidc-client.service6_oidc.grant.type=client
50+
quarkus.oidc-client.service6_oidc.credentials.client-secret.method=basic
4951
quarkus.oidc-client.service6_oidc.credentials.client-secret.value=secret
5052

5153

client/integration-tests/auth-provider/src/test/java/io/quarkiverse/openapi/generator/it/auth/TokenExternalServicesMock.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ public Map<String, String> start() {
6060
// configured. The token will be overridden by the custom credential provider
6161
stubForExternalService("/token-external-service5/executeQuery5", KEYCLOAK_ACCESS_TOKEN + "_TEST");
6262

63+
// stub the token-external-service6 invocation with the expected token, no propagation is produced
64+
// in this case but the service must receive the token provided by Keycloak since it has oidc security
65+
// configured. The token will be overridden by the custom credential provider
66+
stubForExternalService("/token-external-service6/executeQuery6", KEYCLOAK_ACCESS_TOKEN + "_TEST");
67+
6368
return Map.of(TOKEN_EXTERNAL_SERVICE_MOCK_URL, wireMockServer.baseUrl());
6469
}
6570

client/integration-tests/auth-provider/src/test/java/io/quarkiverse/openapi/generator/it/auth/TokenWithCustomCredentialProviderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class TokenWithCustomCredentialProviderTest {
2323

2424
@ParameterizedTest
25-
@ValueSource(strings = { "service1", "service2", "service3", "service5" })
25+
@ValueSource(strings = { "service1", "service2", "service3", "service5", "service6" })
2626
void testService(String service) {
2727
Map<String, String> headers = Map.of(HttpHeaders.AUTHORIZATION, AUTHORIZATION_TOKEN);
2828

client/integration-tests/security/src/main/java/io/quarkiverse/openapi/generator/it/security/TokenPropagationResource.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public class TokenPropagationResource {
2424
@RestClient
2525
org.acme.externalservice5.api.DefaultApi defaultApi5;
2626

27+
@RestClient
28+
org.acme.externalservice6.api.DefaultApi defaultApi6;
29+
2730
@POST
2831
@Path("service1")
2932
public Response service1() {
@@ -53,4 +56,10 @@ public Response service4() {
5356
public Response service5() {
5457
return defaultApi5.executeQuery5();
5558
}
59+
60+
@POST
61+
@Path("service6")
62+
public Response service6() {
63+
return defaultApi6.executeQuery6();
64+
}
5665
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: external-service6 API
5+
version: 3.0.0-SNAPSHOT
6+
paths:
7+
/token-propagation-external-service6/executeQuery6:
8+
post:
9+
operationId: executeQuery6
10+
responses:
11+
"200":
12+
description: OK
13+
security:
14+
- service6-oidc: []
15+
components:
16+
securitySchemes:
17+
service6-oidc:
18+
type: openIdConnect
19+
description: Authentication for service6
20+
openIdConnectUrl: https://example.com/realms/master/.well-known/openid-configuration

client/integration-tests/security/src/main/resources/application.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ quarkus.oidc-client.service5_oauth2.grant.type=client
7878
quarkus.oidc-client.service5_oauth2.credentials.client-secret.method=basic
7979
quarkus.oidc-client.service5_oauth2.credentials.client-secret.value=secret
8080

81+
# Oidc client used by the token_propagation_external_service6
82+
quarkus.oidc-client.service6_oidc.auth-server-url=${keycloak.mock.service.url}
83+
quarkus.oidc-client.service6_oidc.discovery-enabled=true
84+
quarkus.oidc-client.service6_oidc.client-id=kogito-app
85+
quarkus.oidc-client.service6_oidc.grant.type=client
86+
quarkus.oidc-client.service6_oidc.credentials.client-secret.method=basic
87+
quarkus.oidc-client.service6_oidc.credentials.client-secret.value=secret
88+
8189
quarkus.keycloak.devservices.enabled=false
8290

8391
# Slack OpenAPI

client/integration-tests/security/src/test/java/io/quarkiverse/openapi/generator/it/security/TokenPropagationExternalServicesMock.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public Map<String, String> start() {
6666
// configured.
6767
stubForExternalService("/token-propagation-external-service5/executeQuery5", KEYCLOAK_ACCESS_TOKEN);
6868

69+
// stub the token-propagation-external-service6 invocation with the expected token, no propagation is produced
70+
// in this case but the service must receive the token provided by Keycloak since it has oidc security
71+
// configured.
72+
stubForExternalService("/token-propagation-external-service6/executeQuery6", KEYCLOAK_ACCESS_TOKEN);
73+
6974
return Map.of(TOKEN_PROPAGATION_EXTERNAL_SERVICE_MOCK_URL, wireMockServer.baseUrl());
7075
}
7176

0 commit comments

Comments
 (0)