Commit 92c7b2f6 authored by Enriko Käsper's avatar Enriko Käsper
Browse files

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Enriko Käsper

See merge request teis/common-api-gateway!140
parents 32d97980 e3386096
Pipeline #1090 failed
# Common API gateway
Public REST API Gateway application for TeIS common methods.
Common API Gateway application provides public REST interface for TeIS common methods.
The application:
* provides API methods for Front-end appliation
* authorizes client requests
* sends requests to Microservices via Rabbit Exchange (gw_exchange) queues.
* generates unique request ID's forwarded to microservices along with the request data.
* holds client websocket connections
## Features
## Run application
The project contains 2 modules:
1. **api-gateway** - is a Spring Boot application providing the following functionality:
* common API methods consumed by different front-end applications (public self-service and official user application).
* authorizes all client requests and checks the validity of client JWT access token issued by SSO (Keycloak).
* sends requests to microservices via Rabbit Exchange (gw_exchange) queues.
* generates unique request IDs forwarded to microservices along with the request data.
Spring Boot project can be run directly from CommonApiGateway.main() method or via executable jar file. See more info here: [Running your application](https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-running-your-application.html)
2. **api-gateway-lib** - Java library containing common Data Transfer Objects (DTO) exchanged in the
communication between gateway and microservices. All microservices consuming gateway messages depend on Common API Gateway library.
Default URL and path: http://localhost:8080/api-common
Swagger endpoint: http://localhost:8080/api-common/swagger-ui.html
## Requirements
## Environment profiles
* [OpenJDK 11](https://openjdk.java.net/projects/jdk/11/)
* [Rabbit MQ](https://www.rabbitmq.com/)
* [Keycloak (SSO)](https://www.keycloak.org/)
* [PostgreSQL](https://www.postgresql.org/)
* [Minio](https://min.io/)
### dev|test|prelive|prod
See [how to run required dependencies](../../docs/blob/master/run-requirements.md).
Development test, test, prelive and production environment profiles running in different Kubernetes cluster.
Common API Gateway depends on other TeIS libraries:
* [TeIS Gradle plugin](../../teis-gradle-plugin)
* [TeIS public commons libraries](../../commons-public)
* [TeIS commons libraries](../../commons)
## Run application
### local
Spring Boot project can be run directly from [CommonApiGateway.main()](api-gateway/src/main/java/ee/sm/ti/teis/CommonApiGateway.java)
method or via executable jar file. More info on running Spring applications: [running your application.](https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-running-your-application.html)
For local development environment in IDE or command line. NB! Do not push your application-local.yaml file to the VCS.
Visit [how to run application](../../docs/blob/master/run-application.md).
## Build and configure
Visit [how to build](../../docs/blob/master/build-configure.md) for more info.
## Default profiles
Visit [environment profiles](../../docs/blob/master/default-profiles.md) for more info.
## Additional profiles
### mockauth
The application allows to authenticate users with mocked authentication method if mockauth profile is set.
Application allows authenticating users with mocked authentication method.
### no_keycloak
The application does not use Keycloak authentication mechanism if no_keycloak profile is set.
Application will not use Keycloak authentication mechanism.
## Tests
Run [integration](api-gateway/src/integTest) and [unit tests](api-gateway/src/test) via IDE or with Gradle in command line:
```jshelllanguage
./gradlew test
```
......@@ -3,7 +3,9 @@ package ee.sm.ti.teis.commongateway.messages.message.request;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
public class DeleteMessageRequest extends AbstractDTO<String, ErrorDTO> {
import java.util.UUID;
public class DeleteMessageRequest extends AbstractDTO<UUID, ErrorDTO> {
public static final String ROUTING_KEY = "api.DeleteMessageRequest";
......
......@@ -3,7 +3,9 @@ package ee.sm.ti.teis.commongateway.messages.message.request;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
public class MessagesRequest extends AbstractDTO<String, ErrorDTO> {
import java.util.UUID;
public class MessagesRequest extends AbstractDTO<UUID, ErrorDTO> {
public static final String ROUTING_KEY = "api.MessagesRequest";
......
......@@ -6,7 +6,11 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
public class CreateProceedingInspectionDocumentPublicRequest extends AbstractDTO<CreateProceedingInspectionDocumentPublicRequest.Parameters, ErrorDTO> {
import java.util.UUID;
import static ee.sm.ti.teis.commongateway.proceedings.proceeding.request.CreateProceedingInspectionDocumentPublicRequest.Parameters;
public class CreateProceedingInspectionDocumentPublicRequest extends AbstractDTO<Parameters, ErrorDTO> {
public static final String ROUTING_KEY = "api.ProceedingInspectionDocumentsPublicRequest";
@Override
......@@ -18,7 +22,7 @@ public class CreateProceedingInspectionDocumentPublicRequest extends AbstractDTO
@AllArgsConstructor
@NoArgsConstructor
public static class Parameters {
private String proceedingId;
private UUID proceedingId;
private String documentId;
}
}
......@@ -3,7 +3,9 @@ package ee.sm.ti.teis.commongateway.proceedings.proceeding.request;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
public class ProceedingInspectionDocumentsPublicRequest extends AbstractDTO<String, ErrorDTO> {
import java.util.UUID;
public class ProceedingInspectionDocumentsPublicRequest extends AbstractDTO<UUID, ErrorDTO> {
public static final String ROUTING_KEY = "api.ProceedingInspectionDocumentsPublicRequest";
@Override
......
......@@ -2,22 +2,14 @@ package ee.sm.ti.teis.commongateway.proceedings.violation;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
public class ViolationPublicRequest extends AbstractDTO<ViolationPublicRequest.Parameters, ErrorDTO> {
import java.util.UUID;
public class ViolationPublicRequest extends AbstractDTO<UUID, ErrorDTO> {
public static final String ROUTING_KEY = "api.ViolationPublicRequest";
@Override
public String routingKey() {
return ROUTING_KEY;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class Parameters {
private String violationId;
}
}
......@@ -6,6 +6,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.UUID;
public class ViolationsPublicRequest extends AbstractDTO<ViolationsPublicRequest.Parameters, ErrorDTO> {
public static final String ROUTING_KEY = "api.ViolationsPublicRequest";
......@@ -19,7 +21,7 @@ public class ViolationsPublicRequest extends AbstractDTO<ViolationsPublicRequest
@NoArgsConstructor
public static class Parameters {
private String proceduralActId;
private String proceedingId;
private UUID proceduralActId;
private UUID proceedingId;
}
}
......@@ -7,8 +7,11 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
import java.util.UUID;
public class CreateWebLinkRequest extends AbstractDTO<CreateWebLinkRequest.Parameters, ErrorDTO> {
import static ee.sm.ti.teis.commongateway.weblink.CreateWebLinkRequest.Parameters;
public class CreateWebLinkRequest extends AbstractDTO<Parameters, ErrorDTO> {
public static final String ROUTING_KEY = "api.WebLinkRequest";
@Override
......@@ -21,6 +24,6 @@ public class CreateWebLinkRequest extends AbstractDTO<CreateWebLinkRequest.Param
@NoArgsConstructor
public static class Parameters {
private List<String> url;
private String id;
private UUID id;
}
}
......@@ -8,7 +8,9 @@ import lombok.NoArgsConstructor;
import java.util.UUID;
public class DeleteWebLinkRequest extends AbstractDTO<DeleteWebLinkRequest.Parameters, ErrorDTO> {
import static ee.sm.ti.teis.commongateway.weblink.DeleteWebLinkRequest.Parameters;
public class DeleteWebLinkRequest extends AbstractDTO<Parameters, ErrorDTO> {
public static final String ROUTING_KEY = "api.DeleteWebLinkRequest";
@Override
......
......@@ -3,7 +3,9 @@ package ee.sm.ti.teis.commongateway.weblink;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
public class WebLinksTestRequest extends AbstractDTO<String, ErrorDTO> {
import java.util.UUID;
public class WebLinksTestRequest extends AbstractDTO<UUID, ErrorDTO> {
public static final String ROUTING_KEY = "api.WebLinksTestRequest";
@Override
......
......@@ -37,4 +37,4 @@ dependencies {
}
// Define the main class for the application
mainClassName = 'ee.sm.ti.teis.commongateway.CommonApiGateway'
mainClassName = 'ee.sm.ti.teis.CommonApiGateway'
......@@ -19,9 +19,9 @@ import org.testcontainers.junit.jupiter.Testcontainers;
@ContextConfiguration(initializers = { CommonApiGatewayTestBase.Initializer.class })
public abstract class CommonApiGatewayTestBase {
private static GenericContainer rabbitMQContainer;
private static final GenericContainer rabbitMQContainer;
// to speed up tests, lets use static container, it is used in alla test classes that are executed inside one Spring Context
// to speed up tests, lets use static container, it is used in all test classes that are executed inside one Spring Context
static {
rabbitMQContainer = new GenericContainer("rabbitmq:latest").withExposedPorts(5672);
rabbitMQContainer.start();
......
......@@ -6,9 +6,8 @@ import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.UUID;
import static java.util.Collections.emptyList;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class AdminForTestingControllerTest extends CommonApiGatewayTestBase {
......@@ -16,10 +15,16 @@ public class AdminForTestingControllerTest extends CommonApiGatewayTestBase {
@Autowired
AdminForTestingController controller;
@Test
void resetMessageEmail_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.resetMessageEmail(randomUUID(), new RequestMetaDTO()));
}
@Test
void getMessages_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.createFileReferences(UUID.randomUUID(), emptyList(), new RequestMetaDTO()));
controller.createFileReferences(randomUUID(), emptyList(), new RequestMetaDTO()));
}
}
......@@ -8,8 +8,7 @@ import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.UUID;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class MessageControllerTest extends CommonApiGatewayTestBase {
......@@ -20,13 +19,13 @@ public class MessageControllerTest extends CommonApiGatewayTestBase {
@Test
void getMessages() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.getMessages("", new RequestMetaDTO()));
controller.getMessages(randomUUID(), new RequestMetaDTO()));
}
@Test
void patch() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.patch(UUID.randomUUID(), new PatchMessageDto(), new RequestMetaDTO()));
controller.patch(randomUUID(), new PatchMessageDto(), new RequestMetaDTO()));
}
@Test
......@@ -38,7 +37,7 @@ public class MessageControllerTest extends CommonApiGatewayTestBase {
@Test
void delete() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.delete(UUID.randomUUID().toString(), new RequestMetaDTO()));
controller.delete(randomUUID(), new RequestMetaDTO()));
}
@Test
......
......@@ -8,6 +8,7 @@ import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class ClaimTestControllerTest extends CommonApiGatewayTestBase {
......@@ -26,4 +27,10 @@ public class ClaimTestControllerTest extends CommonApiGatewayTestBase {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.patch(new PatchClaimDto(), new RequestMetaDTO()));
}
@Test
void delete() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.delete(randomUUID(), randomUUID(), new RequestMetaDTO()));
}
}
package ee.sm.ti.teis.commongateway.proceedings.proceeding.inspection.document;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.classifier.ClassifierItemLightDto;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class ProceedingInspectionDocumentControllerTest extends CommonApiGatewayTestBase {
@Autowired
ProceedingInspectionDocumentController controller;
@Test
void deleteWebLink_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.deleteWebLink(
randomUUID(), randomUUID(), new RequestMetaDTO()));
}
@Test
void createDocument_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.createDocument(
randomUUID(), new ClassifierItemLightDto(), new RequestMetaDTO()));
}
@Test
void createWebLinks_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.createWebLinks(
randomUUID(), List.of(""), new RequestMetaDTO()));
}
@Test
void getDocuments_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getDocuments(
randomUUID(), new RequestMetaDTO()));
}
}
package ee.sm.ti.teis.commongateway.proceedings.proceeding.inspection.document;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class ProceedingInspectionDocumentTestControllerTest extends CommonApiGatewayTestBase {
@Autowired
ProceedingInspectionDocumentTestController controller;
@Test
void getWebLinks_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getWebLinks(randomUUID(), new RequestMetaDTO()));
}
}
package ee.sm.ti.teis.commongateway.role;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
class RoleTestControllerTest extends CommonApiGatewayTestBase {
private static final RequestMetaDTO requestMetaDTO = RequestMetaDTO.builder().requestId(randomUUID().toString()).build();
@Autowired
RoleTestController controller;
@Test
void getPrivileges_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getPrivileges(List.of(randomUUID()), true, requestMetaDTO));
}
@Test
void getRoles_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getRoles("", "", "", requestMetaDTO));
}
}
package ee.sm.ti.teis.commongateway.security.auth;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.auth.UserCompanySelectionDto;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class AuthControllerTest extends CommonApiGatewayTestBase {
@Autowired
AuthController controller;
@Test
void getPersonCompanies() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.getPersonCompanies(RequestMetaDTO.builder().userId(randomUUID().toString()).build()));
}
@Test
void getSelectedCompany() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.getSelectedCompany(RequestMetaDTO.builder().userId(randomUUID().toString()).build(),
new UserCompanySelectionDto()));
}
}
package ee.sm.ti.teis.commongateway.security.auth;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.UUID;
import static ee.sm.ti.teis.commongateway.security.auth.GrantType.REFRESH_TOKEN;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class AuthPublicControllerTest extends CommonApiGatewayTestBase {
@Autowired
AuthPublicController controller;
@Test
void getAuthConfig_success() {
AuthConfig authConfig = controller.getAuthConfig();
assertThat(authConfig).isNotNull();
assertThat(authConfig.getPortalClientId()).isEqualTo("teis");
assertThat(authConfig.getOfficeClientId()).isEqualTo("teis-office");
assertThat(authConfig.getLoginScope()).isEqualTo("openid");
}
@Test
void getAccessToken_throwsIllegalArgumentException() {
TokenRequest tokenRequest = TokenRequest.builder()
.clientId(UUID.randomUUID().toString())
.grantType(REFRESH_TOKEN)
.refreshToken("test")
.code("test-code")
.scope("openid")
.redirectUri("http://eesti.ee")
.build();
assertThrows(IllegalArgumentException.class, () ->
controller.getAccessToken(tokenRequest, new RequestMetaDTO()));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment