Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
Added openapi docs (#185)
Browse files Browse the repository at this point in the history
Added Map Entry Client
Added Opt in to export to Quicktest search portal
  • Loading branch information
mschulte-tsi authored Sep 23, 2021
1 parent 987cf64 commit 0cbf4d0
Show file tree
Hide file tree
Showing 23 changed files with 2,144 additions and 35 deletions.
1,531 changes: 1,531 additions & 0 deletions open-api.json

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,18 @@
<emptyLineAfterHeader>true</emptyLineAfterHeader>
</configuration>
</plugin>
<plugin>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
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);
}
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();
}
}
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();
}
}
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;
}
}
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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
public static final String ROLE_TENANT_COUNTER = "ROLE_c19_quick_tenant_test_counter";

private static final String API_ROUTE = "/api/**";
private static final String CONFIG_ROUTE = "/api/config/*.json";
private static final String CONFIG_ROUTE = "/api/config/*";
private static final String SAMESITE_LAX = "Lax";
private static final String OAUTH_TOKEN_REQUEST_STATE_COOKIE = "OAuth_Token_Request_State";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@
import app.coronawarn.quicktest.config.QuickTestConfig;
import app.coronawarn.quicktest.model.keycloak.KeyCloakConfigFile;
import app.coronawarn.quicktest.model.quicktest.QuickTestContextFile;
import app.coronawarn.quicktest.service.MapEntryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.keycloak.adapters.springboot.KeycloakSpringBootProperties;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/api/config")
@RequiredArgsConstructor
Expand All @@ -46,7 +49,7 @@ public class ConfigController {
@GetMapping(value = "keycloak.json", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<KeyCloakConfigFile> getKeyCloakConfig() {
return ResponseEntity.ok(
new KeyCloakConfigFile(keycloakConfig.getAuthServerUrl()));
new KeyCloakConfigFile(keycloakConfig.getAuthServerUrl()));
}

/**
Expand All @@ -55,8 +58,8 @@ public ResponseEntity<KeyCloakConfigFile> getKeyCloakConfig() {
@GetMapping(value = "context.json", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<QuickTestContextFile> getQuickTestContextFile() {
return ResponseEntity.ok(
new QuickTestContextFile(
quickTestConfig.getFrontendContextConfig().getRulesServerUrl(),
quickTestConfig.getFrontendContextConfig().getEnvironmentName()));
new QuickTestContextFile(
quickTestConfig.getFrontendContextConfig().getRulesServerUrl(),
quickTestConfig.getFrontendContextConfig().getEnvironmentName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ public ResponseEntity<Void> createSubGroup(
GroupRepresentation userRootGroup = utils.checkUserRootGroup();

try {
keycloakService.createGroup(body.getName(), body.getPocDetails(), userRootGroup.getId());
keycloakService.createGroup(body.getName(), body.getPocDetails(), userRootGroup.getId(),
body.getSearchPortalConsent());
} catch (KeycloakService.KeycloakServiceException e) {
if (e.getReason() == KeycloakService.KeycloakServiceException.Reason.NOT_FOUND) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
Expand Down Expand Up @@ -212,7 +213,7 @@ public ResponseEntity<Void> updateSubGroupDetails(
utils.checkGroupIsInSubgroups(userRootGroup, id);

try {
keycloakService.updateGroup(id, body.getName(), body.getPocDetails());
keycloakService.updateGroup(id, body.getName(), body.getPocDetails(),body.getSearchPortalConsent());
} catch (KeycloakService.KeycloakServiceException e) {
if (e.getReason() == KeycloakService.KeycloakServiceException.Reason.NOT_FOUND) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Group not found");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ public class KeycloakGroupDetails {
@Size(max = 50)
private String pocId;

private Boolean searchPortalConsent;

}
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;
}
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;
}
}
Loading

0 comments on commit 0cbf4d0

Please sign in to comment.