This repository has been archived by the owner on May 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Map Entry Client Added Opt in to export to Quicktest search portal
- Loading branch information
1 parent
987cf64
commit 0cbf4d0
Showing
23 changed files
with
2,144 additions
and
35 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/app/coronawarn/quicktest/client/QuicktestMapClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package app.coronawarn.quicktest.client; | ||
|
||
import app.coronawarn.quicktest.model.map.MapCenterList; | ||
import app.coronawarn.quicktest.model.map.MapEntryResponse; | ||
import app.coronawarn.quicktest.model.map.MapEntryUploadData; | ||
import java.util.List; | ||
import javax.validation.Valid; | ||
import javax.validation.constraints.NotNull; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
|
||
@FeignClient( | ||
name = "MapServerClient", | ||
url = "${quicktest-map-server.url}", | ||
configuration = QuicktestMapClientConfig.class | ||
) | ||
public interface QuicktestMapClient { | ||
String AUTH_TOKEN = "Authorization"; | ||
@PostMapping(value = "/api/centers", | ||
consumes = MediaType.APPLICATION_JSON_VALUE, | ||
produces = MediaType.APPLICATION_JSON_VALUE | ||
) | ||
ResponseEntity<List<MapEntryResponse>> createMapEntry(@RequestHeader(AUTH_TOKEN) String bearerToken, | ||
@RequestBody @NotNull @Valid MapCenterList mapCenterList); | ||
|
||
@PostMapping(value = "/api/centers/", | ||
consumes = MediaType.APPLICATION_JSON_VALUE, | ||
produces = MediaType.APPLICATION_JSON_VALUE | ||
) | ||
ResponseEntity<List<MapEntryResponse>> updateMapEntry(@RequestHeader(AUTH_TOKEN) String bearerToken, | ||
@RequestBody @NotNull @Valid MapEntryUploadData mapEntryUploadData); | ||
|
||
|
||
@GetMapping(value = "/api/centers/reference/{userReference}", | ||
produces = MediaType.APPLICATION_JSON_VALUE | ||
) | ||
ResponseEntity<MapEntryResponse> getMapEntry(@RequestHeader(AUTH_TOKEN) String bearerToken, | ||
@PathVariable String userReference); | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/app/coronawarn/quicktest/client/QuicktestMapClientConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package app.coronawarn.quicktest.client; | ||
|
||
import app.coronawarn.quicktest.config.MapServerValuesConfig; | ||
import feign.Client; | ||
import feign.httpclient.ApacheHttpClient; | ||
import java.io.IOException; | ||
import java.security.GeneralSecurityException; | ||
import javax.net.ssl.HostnameVerifier; | ||
import javax.net.ssl.SSLContext; | ||
import lombok.RequiredArgsConstructor; | ||
import org.apache.http.HttpHost; | ||
import org.apache.http.conn.ssl.DefaultHostnameVerifier; | ||
import org.apache.http.conn.ssl.NoopHostnameVerifier; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.apache.http.ssl.SSLContextBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.util.ResourceUtils; | ||
import org.springframework.web.server.ResponseStatusException; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class QuicktestMapClientConfig { | ||
private final MapServerValuesConfig config; | ||
|
||
/** | ||
* HttpClient for connection to Map-Server. | ||
* | ||
* @return Instance of HttpClient | ||
*/ | ||
@Bean | ||
public Client mapClient() { | ||
if (config.isEnabled()) { | ||
return new ApacheHttpClient( | ||
HttpClientBuilder | ||
.create() | ||
.setSSLContext(getSslContext()) | ||
.setSSLHostnameVerifier(getSslHostnameVerifier()) | ||
.build() | ||
); | ||
} | ||
return new ApacheHttpClient(HttpClientBuilder.create() | ||
.setSSLHostnameVerifier(getSslHostnameVerifier()) | ||
.setProxy(new HttpHost("sia-lb.telekom.de",8080)) | ||
.build()); | ||
} | ||
|
||
private SSLContext getSslContext() { | ||
try { | ||
SSLContextBuilder builder = SSLContextBuilder | ||
.create(); | ||
if (config.isOneWay()) { | ||
builder.loadTrustMaterial(ResourceUtils.getFile(config.getTrustStorePath()), | ||
config.getTrustStorePassword()); | ||
} | ||
if (config.isTwoWay()) { | ||
builder.loadKeyMaterial(ResourceUtils.getFile(config.getKeyStorePath()), | ||
config.getKeyStorePassword(), | ||
config.getKeyStorePassword()); | ||
} | ||
return builder.build(); | ||
} catch (IOException | GeneralSecurityException e) { | ||
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "The SSL context could not be loaded."); | ||
} | ||
} | ||
|
||
private HostnameVerifier getSslHostnameVerifier() { | ||
return config.isHostnameVerify() ? new DefaultHostnameVerifier() : new NoopHostnameVerifier(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/app/coronawarn/quicktest/config/KeycloakMapClientConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/*- | ||
* ---license-start | ||
* Corona-Warn-App / cwa-quick-test-backend | ||
* --- | ||
* Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
* --- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ---license-end | ||
*/ | ||
|
||
package app.coronawarn.quicktest.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; | ||
import org.keycloak.admin.client.Keycloak; | ||
import org.keycloak.admin.client.KeycloakBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class KeycloakMapClientConfig { | ||
|
||
private final KeycloakMapProperties config; | ||
|
||
@Bean | ||
Keycloak mapKeycloak() { | ||
return KeycloakBuilder.builder() | ||
.grantType("password") | ||
.serverUrl(config.getAuthServerUrl()) | ||
.realm(config.getRealm()) | ||
.clientId(config.getResource()) | ||
.username(config.getCredentials().getUsername()) | ||
.password(config.getCredentials().getPassword()) | ||
.build(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/app/coronawarn/quicktest/config/KeycloakMapProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/*- | ||
* ---license-start | ||
* Corona-Warn-App / cwa-quick-test-backend | ||
* --- | ||
* Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
* --- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ---license-end | ||
*/ | ||
|
||
package app.coronawarn.quicktest.config; | ||
|
||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Getter | ||
@Setter | ||
@Configuration | ||
@ConfigurationProperties("keycloak-map") | ||
public class KeycloakMapProperties { | ||
|
||
private String realm; | ||
|
||
private String resource; | ||
|
||
private String authServerUrl; | ||
|
||
private KeycloakCredentials credentials; | ||
|
||
@Data | ||
public static class KeycloakCredentials { | ||
private String username; | ||
private String password; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/app/coronawarn/quicktest/config/MapServerValuesConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/*- | ||
* ---license-start | ||
* Corona-Warn-App / cwa-quick-test-backend | ||
* --- | ||
* Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
* --- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ---license-end | ||
*/ | ||
|
||
package app.coronawarn.quicktest.config; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Getter | ||
@Setter | ||
@Configuration | ||
@ConfigurationProperties("mapserver") | ||
public class MapServerValuesConfig { | ||
|
||
private boolean enabled; | ||
private boolean oneWay; | ||
private boolean twoWay; | ||
private boolean hostnameVerify; | ||
private String keyStorePath; | ||
private char[] keyStorePassword; | ||
private String trustStorePath; | ||
private char[] trustStorePassword; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/app/coronawarn/quicktest/model/map/MapCenterList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package app.coronawarn.quicktest.model.map; | ||
|
||
import java.util.List; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class MapCenterList { | ||
Boolean deleteAll; | ||
List<MapEntryUploadData> centers; | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/app/coronawarn/quicktest/model/map/MapEntryResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package app.coronawarn.quicktest.model.map; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class MapEntryResponse { | ||
String uuid; | ||
String name; | ||
String website; | ||
Coordinates coordinates; | ||
String logo; | ||
String marker; | ||
String address; | ||
String[] openingHours; | ||
String addressNote; | ||
String appointment; | ||
String[] testKinds; | ||
Boolean dcc; | ||
String message; | ||
String userReference; | ||
String enterDate; | ||
String leaveDate; | ||
|
||
@Data | ||
public class Coordinates { | ||
Integer longitude; | ||
Integer latitude; | ||
} | ||
} |
Oops, something went wrong.