Skip to content
Snippets Groups Projects

OZG-7232 SmartDocuments zertifikatbasierte Authentifizierung

Merged Sebastian Bergandy requested to merge OZG-7232-smart-documents-client-certificate-auth into main
5 files
+ 363
41
Compare changes
  • Side-by-side
  • Inline

Files

@@ -25,6 +25,7 @@ package de.ozgcloud.document.bescheid.smartdocuments;
@@ -25,6 +25,7 @@ package de.ozgcloud.document.bescheid.smartdocuments;
import java.io.File;
import java.io.File;
import java.io.IOException;
import java.io.IOException;
 
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collection;
import java.util.Optional;
import java.util.Optional;
@@ -34,14 +35,15 @@ import javax.xml.xpath.XPathConstants;
@@ -34,14 +35,15 @@ import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import javax.xml.xpath.XPathFactory;
 
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 
import org.springframework.http.HttpRequest;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.MediaType;
import org.springframework.http.MediaType;
 
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.BodyExtractors;
import org.springframework.web.client.RestClient;
import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.WebClient;
import org.w3c.dom.Document;
import org.w3c.dom.Document;
import org.w3c.dom.Text;
import org.w3c.dom.Text;
import org.xml.sax.SAXException;
import org.xml.sax.SAXException;
@@ -69,7 +71,6 @@ import lombok.Getter;
@@ -69,7 +71,6 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import lombok.extern.log4j.Log4j2;
import reactor.core.publisher.Mono;
@Log4j2
@Log4j2
@Service
@Service
@@ -87,7 +88,7 @@ class SmartDocumentsBescheidRemoteService implements BescheidRemoteService {
@@ -87,7 +88,7 @@ class SmartDocumentsBescheidRemoteService implements BescheidRemoteService {
private static final MediaType JSON_MEDIA_TYPE_FOR_SD = MediaType.APPLICATION_JSON_UTF8;
private static final MediaType JSON_MEDIA_TYPE_FOR_SD = MediaType.APPLICATION_JSON_UTF8;
@Qualifier("smartDocuments")
@Qualifier("smartDocuments")
private final WebClient smartDocumentsWebClient;
private final RestClient smartDocumentsRestClient;
private final SmartDocumentsProperties properties;
private final SmartDocumentsProperties properties;
@@ -96,19 +97,24 @@ class SmartDocumentsBescheidRemoteService implements BescheidRemoteService {
@@ -96,19 +97,24 @@ class SmartDocumentsBescheidRemoteService implements BescheidRemoteService {
var sdRequest = createRequest(request, vorgang);
var sdRequest = createRequest(request, vorgang);
LOG.debug(() -> buildLogRequest(sdRequest));
LOG.debug(() -> buildLogRequest(sdRequest));
return smartDocumentsWebClient.post().accept(MediaType.APPLICATION_JSON)
var response = smartDocumentsRestClient.post().accept(MediaType.APPLICATION_JSON)
.contentType(JSON_MEDIA_TYPE_FOR_SD)
.contentType(JSON_MEDIA_TYPE_FOR_SD)
.bodyValue(sdRequest)
.body(sdRequest)
.retrieve()
.retrieve()
.onStatus(HttpStatusCode::is4xxClientError, this::handleClientError)
.onStatus(HttpStatusCode::is4xxClientError, this::handleClientError)
.bodyToMono(SmartDocumentsResponse.class)
.toEntity(SmartDocumentsResponse.class)
.map(response -> buildBescheid(request, response))
.getBody();
.block();
return buildBescheid(request, response);
 
}
}
Mono<Throwable> handleClientError(ClientResponse response) {
void handleClientError(HttpRequest request, ClientHttpResponse response) {
return response.body(BodyExtractors.toMono(String.class))
try {
.map(content -> new TechnicalException("Client-Error: " + content));
var responseBody = IOUtils.toString(response.getBody(), StandardCharsets.UTF_8);
 
throw new TechnicalException("Client-Error: " + response.getStatusCode() + " " + responseBody);
 
} catch (IOException e) {
 
throw new TechnicalException("Couldn't read response body", e);
 
}
}
}
private String buildLogRequest(SmartDocumentsRequest request) {
private String buildLogRequest(SmartDocumentsRequest request) {
Loading