Skip to content
Snippets Groups Projects
Commit 5d79aae5 authored by Jörg Bolay's avatar Jörg Bolay
Browse files

KOP-2964 umstellen von WebCLient auf RestClient

parent 558cf07f
No related branches found
No related tags found
1 merge request!10KOP-2964 umstellen von WebClient auf RestClient und entfernen von...
Pipeline #1517 failed
......@@ -42,22 +42,16 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-oauth2-client</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-security</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
......
......@@ -11,7 +11,14 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.oauth2.client.*;
import org.springframework.security.oauth2.client.endpoint.OAuth2ClientCredentialsGrantRequestEntityConverter;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
import org.springframework.security.oauth2.client.registration.ClientRegistrations;
import org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository;
import org.springframework.security.oauth2.client.web.DefaultOAuth2AuthorizedClientManager;
import org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository;
import org.springframework.security.oauth2.client.web.client.OAuth2ClientHttpRequestInterceptor;
import org.springframework.web.client.RestClient;
......@@ -20,6 +27,7 @@ import de.ozgcloud.nachrichten.postfach.osiv2.gen.api.MessageExchangeApi;
import lombok.RequiredArgsConstructor;
@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
@ConditionalOnProperty("ozgcloud.osiv2-postfach.enabled")
public class ApiClientConfiguration {
......@@ -34,6 +42,7 @@ public class ApiClientConfiguration {
@Bean
ApiClient apiClient(OAuth2AuthorizedClientManager authorizedClientManager) {
RestClient restClient = RestClient.builder()
.requestFactory(createProxyRequestFactory())
.requestInterceptor(createOAuth2Interceptor(authorizedClientManager))
......@@ -42,15 +51,15 @@ public class ApiClientConfiguration {
return new ApiClient(restClient);
}
private ClientHttpRequestFactory createProxyRequestFactory(){
var requestFactory = new HttpComponentsClientHttpRequestFactory();
if(proxyConfiguration.isEnabled()){
var credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(proxyConfiguration.getHost(), proxyConfiguration.getPort()),
new UsernamePasswordCredentials(proxyConfiguration.getUsername(), proxyConfiguration.getPassword().toCharArray())
//TODO: hier brauchen wir noch eine Ordentliche Lösung
// new UsernamePasswordCredentials(proxyConfiguration.getUsername(), proxyConfiguration.getPassword().toCharArray())
new UsernamePasswordCredentials("bla", "blub".toCharArray())
);
var httpClient = HttpClientBuilder.create()
.setProxy(new HttpHost(proxyConfiguration.getHost(), proxyConfiguration.getPort()))
......@@ -65,83 +74,4 @@ public class ApiClientConfiguration {
var interceptor = new OAuth2ClientHttpRequestInterceptor(authorizedClientManager);
return interceptor;
}
// @Bean
// ApiClient apiClient(ReactiveClientRegistrationRepository clientRegistrations) {
// return new ApiClient(osi2PostfachWebClient(clientRegistrations))
// .setBasePath(apiConfiguration.getUrl());
// }
// private WebClient osi2PostfachWebClient(
// ReactiveClientRegistrationRepository clientRegistrations) {
// return WebClient.builder()
// .clientConnector(new ReactorClientHttpConnector(httpClient()))
// .filter(serverOAuth2AuthorizedClientExchangeFilterFunction(clientRegistrations))
// .build();
// }
//
// @SuppressWarnings("ConstantConditions")
// private HttpClient httpClient() {
// var webClient = HttpClient.create();
// return proxyConfiguration.isEnabled() ? webClient
// .proxy(proxy -> proxy
// .type(ProxyProvider.Proxy.HTTP)
// .host(proxyConfiguration.getHost())
// .port(proxyConfiguration.getPort())
// .username(proxyConfiguration.getUsername())
// .password(username -> proxyConfiguration.getPassword())
// ) : webClient;
// }
//
// private ServerOAuth2AuthorizedClientExchangeFilterFunction serverOAuth2AuthorizedClientExchangeFilterFunction(
// ReactiveClientRegistrationRepository clientRegistrations) {
//
// var oauth = new ServerOAuth2AuthorizedClientExchangeFilterFunction(authorizedClientManager(clientRegistrations));
// oauth.setDefaultClientRegistrationId("osi2");
// return oauth;
// }
//
// private AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager authorizedClientManager(
// ReactiveClientRegistrationRepository clientRegistrations) {
// var clientService = new InMemoryReactiveOAuth2AuthorizedClientService(
// clientRegistrations);
// var authorizedClientManager = new AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager(
// clientRegistrations, clientService);
//
// authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider());
//
// return authorizedClientManager;
// }
//
// private ReactiveOAuth2AuthorizedClientProvider authorizedClientProvider() {
// return ReactiveOAuth2AuthorizedClientProviderBuilder.builder()
// .clientCredentials(builder ->
// builder.accessTokenResponseClient(clientCredentialsTokenResponseClient())
// )
// .build();
// }
//
// private WebClientReactiveClientCredentialsTokenResponseClient clientCredentialsTokenResponseClient() {
// var client = new WebClientReactiveClientCredentialsTokenResponseClient();
// configureHttpClientForTokenRequests(client);
// configureParametersForTokenRequests(client);
// return client;
// }
//
// private void configureHttpClientForTokenRequests(WebClientReactiveClientCredentialsTokenResponseClient client) {
// client.setWebClient(WebClient.builder()
// .clientConnector(new ReactorClientHttpConnector(httpClient()))
// .build());
// }
//
// private void configureParametersForTokenRequests(WebClientReactiveClientCredentialsTokenResponseClient client) {
// client.addParametersConverter(source -> {
// MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
// // Pass a resource indicator parameter https://datatracker.ietf.org/doc/html/rfc8707
// parameters.add("resource", apiConfiguration.getResource());
// return parameters;
// });
// }
}
spring:
main:
web-application-type: reactive
jackson:
default-property-inclusion: NON_NULL
security:
......
......@@ -43,7 +43,7 @@ import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1ReplyBehavior;
import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1ReplyMessage;
import lombok.SneakyThrows;
@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
@SpringBootTest(classes = TestApplication.class)
@ActiveProfiles("itcase")
@TestPropertySource(properties = {
"ozgcloud.osiv2-postfach.http-proxy.enabled=false",
......
......@@ -22,7 +22,7 @@ import de.ozgcloud.nachrichten.postfach.osiv2.factory.DummyStringBasedIdentifier
import de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachAddressTestFactory;
import de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachNachrichtTestFactory;
@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
@SpringBootTest(classes = TestApplication.class)
@ActiveProfiles("itcase")
@EnabledIfEnvironmentVariable(named = "SH_STAGE_CLIENT_SECRET", matches = ".+")
public class OsiPostfachRemoteServiceRemoteITCase {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment