From 40647e1c7b1365b4cb5785ecdd6e8dbc13b6a412 Mon Sep 17 00:00:00 2001 From: "Melzer Dennis (BCI/ESW17)" Date: Tue, 5 May 2020 11:13:35 +0200 Subject: [PATCH 1/5] Register OAuth2ClientContext as bean #6171 --- .../spring-cloud/clientConfiguration.mustache | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/clientConfiguration.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/clientConfiguration.mustache index c1feeb515990..61ac2c03a638 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/clientConfiguration.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/clientConfiguration.mustache @@ -23,6 +23,7 @@ import org.springframework.context.annotation.Configuration; {{#isOAuth}} import org.springframework.cloud.security.oauth2.client.feign.OAuth2FeignRequestInterceptor; import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; +import org.springframework.security.oauth2.client.OAuth2ClientContext; {{#isApplication}} import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; {{/isApplication}} @@ -71,8 +72,14 @@ public class ClientConfiguration { {{#isOAuth}} @Bean @ConditionalOnProperty("{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}.client-id") - public OAuth2FeignRequestInterceptor {{{name}}}RequestInterceptor() { - return new OAuth2FeignRequestInterceptor(new DefaultOAuth2ClientContext(), {{{name}}}ResourceDetails()); + public OAuth2FeignRequestInterceptor {{{name}}}RequestInterceptor(OAuth2ClientContext oAuth2ClientContext) { + return new OAuth2FeignRequestInterceptor(oAuth2ClientContext, {{{name}}}ResourceDetails()); + } + + @Bean + @ConditionalOnProperty("{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}.client-id") + public OAuth2ClientContext oAuth2ClientContext() { + return new DefaultOAuth2ClientContext(); } {{#isCode}} From 0066b168f2b3190029bc7e1103e40b37c5cf28b8 Mon Sep 17 00:00:00 2001 From: "Melzer Dennis (BCI/ESW17)" Date: Tue, 5 May 2020 11:18:58 +0200 Subject: [PATCH 2/5] Add tab #6171 --- .../libraries/spring-cloud/clientConfiguration.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/clientConfiguration.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/clientConfiguration.mustache index 61ac2c03a638..3d0ccc7d2c51 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/clientConfiguration.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/clientConfiguration.mustache @@ -79,7 +79,7 @@ public class ClientConfiguration { @Bean @ConditionalOnProperty("{{#lambda.lowercase}}{{{title}}}{{/lambda.lowercase}}.security.{{{name}}}.client-id") public OAuth2ClientContext oAuth2ClientContext() { - return new DefaultOAuth2ClientContext(); + return new DefaultOAuth2ClientContext(); } {{#isCode}} From 536ef6e0f69cc0f6300f018d9144afd38497b7a2 Mon Sep 17 00:00:00 2001 From: "Melzer Dennis (BCI/ESW17)" Date: Tue, 5 May 2020 12:31:51 +0200 Subject: [PATCH 3/5] Modify tests #6171 --- .../configuration/ClientConfiguration.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/samples/client/petstore/spring-cloud/src/main/java/org/openapitools/configuration/ClientConfiguration.java b/samples/client/petstore/spring-cloud/src/main/java/org/openapitools/configuration/ClientConfiguration.java index ae8ce0ea3f6b..0a1d55c88beb 100644 --- a/samples/client/petstore/spring-cloud/src/main/java/org/openapitools/configuration/ClientConfiguration.java +++ b/samples/client/petstore/spring-cloud/src/main/java/org/openapitools/configuration/ClientConfiguration.java @@ -25,8 +25,14 @@ public ApiKeyRequestInterceptor apiKeyRequestInterceptor() { @Bean @ConditionalOnProperty("openapipetstore.security.petstoreAuth.client-id") - public OAuth2FeignRequestInterceptor petstoreAuthRequestInterceptor() { - return new OAuth2FeignRequestInterceptor(new DefaultOAuth2ClientContext(), petstoreAuthResourceDetails()); + public OAuth2FeignRequestInterceptor petstoreAuthRequestInterceptor(OAuth2ClientContext oAuth2ClientContext) { + return new OAuth2FeignRequestInterceptor(oAuth2ClientContext, petstoreAuthResourceDetails()); + } + + @Bean + @ConditionalOnProperty("openapipetstore.security.petstoreAuth.client-id") + public OAuth2ClientContext oAuth2ClientContext() { + return new DefaultOAuth2ClientContext(); } @Bean From 89278e4d5b3e41d0b00cbdc59dbbc3a40ab1d454 Mon Sep 17 00:00:00 2001 From: "Melzer Dennis (BCI/ESW17)" Date: Tue, 5 May 2020 15:08:14 +0200 Subject: [PATCH 4/5] Add import for test #6171 --- .../java/org/openapitools/configuration/ClientConfiguration.java | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/client/petstore/spring-cloud/src/main/java/org/openapitools/configuration/ClientConfiguration.java b/samples/client/petstore/spring-cloud/src/main/java/org/openapitools/configuration/ClientConfiguration.java index 0a1d55c88beb..8f503c9cf226 100644 --- a/samples/client/petstore/spring-cloud/src/main/java/org/openapitools/configuration/ClientConfiguration.java +++ b/samples/client/petstore/spring-cloud/src/main/java/org/openapitools/configuration/ClientConfiguration.java @@ -8,6 +8,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.cloud.security.oauth2.client.feign.OAuth2FeignRequestInterceptor; import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; +import org.springframework.security.oauth2.client.OAuth2ClientContext; import org.springframework.security.oauth2.client.token.grant.implicit.ImplicitResourceDetails; @Configuration From e9654c8d9a3c000a865c5d0aea77391585d6d210 Mon Sep 17 00:00:00 2001 From: "Melzer Dennis (BCI/ESW17)" Date: Wed, 6 May 2020 08:46:03 +0200 Subject: [PATCH 5/5] Modify spring cloud async test #6171 --- .../configuration/ClientConfiguration.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/samples/client/petstore/spring-cloud-async/src/main/java/org/openapitools/configuration/ClientConfiguration.java b/samples/client/petstore/spring-cloud-async/src/main/java/org/openapitools/configuration/ClientConfiguration.java index ae8ce0ea3f6b..8f503c9cf226 100644 --- a/samples/client/petstore/spring-cloud-async/src/main/java/org/openapitools/configuration/ClientConfiguration.java +++ b/samples/client/petstore/spring-cloud-async/src/main/java/org/openapitools/configuration/ClientConfiguration.java @@ -8,6 +8,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.cloud.security.oauth2.client.feign.OAuth2FeignRequestInterceptor; import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; +import org.springframework.security.oauth2.client.OAuth2ClientContext; import org.springframework.security.oauth2.client.token.grant.implicit.ImplicitResourceDetails; @Configuration @@ -25,8 +26,14 @@ public ApiKeyRequestInterceptor apiKeyRequestInterceptor() { @Bean @ConditionalOnProperty("openapipetstore.security.petstoreAuth.client-id") - public OAuth2FeignRequestInterceptor petstoreAuthRequestInterceptor() { - return new OAuth2FeignRequestInterceptor(new DefaultOAuth2ClientContext(), petstoreAuthResourceDetails()); + public OAuth2FeignRequestInterceptor petstoreAuthRequestInterceptor(OAuth2ClientContext oAuth2ClientContext) { + return new OAuth2FeignRequestInterceptor(oAuth2ClientContext, petstoreAuthResourceDetails()); + } + + @Bean + @ConditionalOnProperty("openapipetstore.security.petstoreAuth.client-id") + public OAuth2ClientContext oAuth2ClientContext() { + return new DefaultOAuth2ClientContext(); } @Bean