Merge branch 'RED-7175' into 'main'
RED-7175 See merge request fforesight/tenant-user-management-service!19
This commit is contained in:
commit
1003f4a4a1
@ -82,7 +82,7 @@ tasks.named<BootBuildImage>("bootBuildImage") {
|
|||||||
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("com.knecon.fforesight:keycloak-commons:0.18.0")
|
implementation("com.knecon.fforesight:keycloak-commons:0.20.0")
|
||||||
implementation("com.knecon.fforesight:swagger-commons:0.5.0")
|
implementation("com.knecon.fforesight:swagger-commons:0.5.0")
|
||||||
implementation("org.postgresql:postgresql:42.5.4")
|
implementation("org.postgresql:postgresql:42.5.4")
|
||||||
implementation("com.google.guava:guava:31.1-jre")
|
implementation("com.google.guava:guava:31.1-jre")
|
||||||
@ -99,7 +99,7 @@ dependencies {
|
|||||||
implementation("org.apache.commons:commons-lang3:3.12.0")
|
implementation("org.apache.commons:commons-lang3:3.12.0")
|
||||||
implementation("commons-validator:commons-validator:1.7")
|
implementation("commons-validator:commons-validator:1.7")
|
||||||
implementation("org.springframework.boot:spring-boot-configuration-processor")
|
implementation("org.springframework.boot:spring-boot-configuration-processor")
|
||||||
implementation("com.iqser.red.commons:storage-commons:2.22.0")
|
implementation("com.iqser.red.commons:storage-commons:2.43.0")
|
||||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||||
testImplementation("org.springframework.cloud:spring-cloud-starter-openfeign")
|
testImplementation("org.springframework.cloud:spring-cloud-starter-openfeign")
|
||||||
testImplementation("org.projectlombok:lombok")
|
testImplementation("org.projectlombok:lombok")
|
||||||
|
|||||||
@ -81,7 +81,7 @@ public class DevTestTenantService {
|
|||||||
.username(tenantsDBName)
|
.username(tenantsDBName)
|
||||||
.password(tenantsDBPassword)
|
.password(tenantsDBPassword)
|
||||||
.build())
|
.build())
|
||||||
.searchConnection(SearchConnection.builder().hosts(Set.of("localhost")).port(9200).scheme("http").numberOfShards("1").numberOfReplicas("5").build())
|
.searchConnection(SearchConnection.builder().hosts(Set.of("localhost")).port(9200).scheme("http").numberOfShards("1").numberOfReplicas("5").indexName("indexname").build())
|
||||||
.s3StorageConnection(S3StorageConnection.builder().key("minioadmin").secret("minioadmin").bucketName("redaction").endpoint("http://localhost:9000").build())
|
.s3StorageConnection(S3StorageConnection.builder().key("minioadmin").secret("minioadmin").bucketName("redaction").endpoint("http://localhost:9000").build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|||||||
@ -34,5 +34,7 @@ public class SearchConnectionEntity {
|
|||||||
private String numberOfShards;
|
private String numberOfShards;
|
||||||
@Column(name = "search_number_of_replicas")
|
@Column(name = "search_number_of_replicas")
|
||||||
private String numberOfReplicas;
|
private String numberOfReplicas;
|
||||||
|
@Column(name = "search_index_name")
|
||||||
|
private String indexName;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import com.knecon.fforesight.tenantcommons.model.SearchConnection;
|
|||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
|
||||||
import jakarta.validation.constraints.Pattern;
|
import jakarta.validation.constraints.Pattern;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
|
|||||||
@ -113,6 +113,7 @@ public class TenantManagementService implements TenantProvider {
|
|||||||
.password(encryptionService.encrypt(tenantRequest.getSearchConnection().getPassword()))
|
.password(encryptionService.encrypt(tenantRequest.getSearchConnection().getPassword()))
|
||||||
.numberOfShards(tenantRequest.getSearchConnection().getNumberOfShards())
|
.numberOfShards(tenantRequest.getSearchConnection().getNumberOfShards())
|
||||||
.numberOfReplicas(tenantRequest.getSearchConnection().getNumberOfReplicas())
|
.numberOfReplicas(tenantRequest.getSearchConnection().getNumberOfReplicas())
|
||||||
|
.indexName(tenantRequest.getSearchConnection().getIndexName())
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@ -407,6 +408,7 @@ public class TenantManagementService implements TenantProvider {
|
|||||||
.password(encryptionService.encrypt(searchConnection.getPassword()))
|
.password(encryptionService.encrypt(searchConnection.getPassword()))
|
||||||
.numberOfShards(searchConnection.getNumberOfShards())
|
.numberOfShards(searchConnection.getNumberOfShards())
|
||||||
.numberOfReplicas(searchConnection.getNumberOfReplicas())
|
.numberOfReplicas(searchConnection.getNumberOfReplicas())
|
||||||
|
.indexName(searchConnection.getIndexName())
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -508,6 +510,7 @@ public class TenantManagementService implements TenantProvider {
|
|||||||
.numberOfShards(entity.getSearchConnection().getNumberOfShards())
|
.numberOfShards(entity.getSearchConnection().getNumberOfShards())
|
||||||
.numberOfReplicas(entity.getSearchConnection().getNumberOfReplicas())
|
.numberOfReplicas(entity.getSearchConnection().getNumberOfReplicas())
|
||||||
.password(entity.getSearchConnection().getPassword())
|
.password(entity.getSearchConnection().getPassword())
|
||||||
|
.indexName(entity.getSearchConnection().getIndexName())
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|||||||
@ -7,3 +7,5 @@ databaseChangeLog:
|
|||||||
file: db/changelog/master/4-add-unique-constraint-for-tenants-table.yaml
|
file: db/changelog/master/4-add-unique-constraint-for-tenants-table.yaml
|
||||||
- include:
|
- include:
|
||||||
file: db/changelog/master/5-add-details-column.changelog.yaml
|
file: db/changelog/master/5-add-details-column.changelog.yaml
|
||||||
|
- include:
|
||||||
|
file: db/changelog/master/6-add-index-name-column.changelog.yaml
|
||||||
|
|||||||
@ -0,0 +1,11 @@
|
|||||||
|
databaseChangeLog:
|
||||||
|
- changeSet:
|
||||||
|
id: add-index-name-column-to-tenant
|
||||||
|
author: ali
|
||||||
|
changes:
|
||||||
|
- addColumn:
|
||||||
|
tableName: tenant
|
||||||
|
columns:
|
||||||
|
- column:
|
||||||
|
name: search_index_name
|
||||||
|
type: TEXT
|
||||||
@ -1,8 +1,5 @@
|
|||||||
package com.knecon.fforesight;
|
package com.knecon.fforesight;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
@ -55,10 +52,12 @@ public class AbstractTenantUserManagementIntegrationTest {
|
|||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void createTestTenant(){
|
public void createTestTenant() {
|
||||||
|
|
||||||
testTenantService.createTestTenantIfNotExists(TEST_TENANT_ID, minioPort);
|
testTenantService.createTestTenantIfNotExists(TEST_TENANT_ID, minioPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||||
|
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import com.knecon.fforesight.tenantusermanagement.service.RealmService;
|
|||||||
import com.knecon.fforesight.utils.TestTenantService;
|
import com.knecon.fforesight.utils.TestTenantService;
|
||||||
|
|
||||||
import feign.FeignException;
|
import feign.FeignException;
|
||||||
|
import software.amazon.awssdk.regions.Region;
|
||||||
|
|
||||||
public class TenantsTest extends AbstractTenantUserManagementIntegrationTest {
|
public class TenantsTest extends AbstractTenantUserManagementIntegrationTest {
|
||||||
|
|
||||||
@ -37,7 +38,6 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RealmService realmService;
|
private RealmService realmService;
|
||||||
|
|
||||||
|
|
||||||
private static final String PASSWORD = "**********";
|
private static final String PASSWORD = "**********";
|
||||||
|
|
||||||
|
|
||||||
@ -60,6 +60,7 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateTenant() {
|
public void testUpdateTenant() {
|
||||||
|
|
||||||
@ -77,6 +78,7 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest {
|
|||||||
.port(123)
|
.port(123)
|
||||||
.username("updated_username")
|
.username("updated_username")
|
||||||
.scheme("updated_scheme")
|
.scheme("updated_scheme")
|
||||||
|
.indexName("indexname")
|
||||||
.build())
|
.build())
|
||||||
.databaseConnection(DatabaseConnection.builder()
|
.databaseConnection(DatabaseConnection.builder()
|
||||||
.database("updated_db")
|
.database("updated_db")
|
||||||
@ -92,7 +94,9 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest {
|
|||||||
.key("minioadmin")
|
.key("minioadmin")
|
||||||
.secret("minioadmin")
|
.secret("minioadmin")
|
||||||
.bucketName("redaction2")
|
.bucketName("redaction2")
|
||||||
.endpoint("http://localhost:" + minioPort).build())
|
.region(Region.AWS_GLOBAL.id())
|
||||||
|
.endpoint("http://localhost:" + minioPort)
|
||||||
|
.build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
var updatedTenant = tenantsClient.updateTenant("new_tenant", tenantRequest);
|
var updatedTenant = tenantsClient.updateTenant("new_tenant", tenantRequest);
|
||||||
@ -122,8 +126,10 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest {
|
|||||||
TenantContext.clear();
|
TenantContext.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateTenantWithIncorrectS3Storage() {
|
public void testUpdateTenantWithIncorrectS3Storage() {
|
||||||
|
|
||||||
testTenantService.createTestTenantIfNotExists("new_tenant", minioPort);
|
testTenantService.createTestTenantIfNotExists("new_tenant", minioPort);
|
||||||
TenantContext.setTenantId("new_tenant");
|
TenantContext.setTenantId("new_tenant");
|
||||||
|
|
||||||
@ -145,17 +151,16 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest {
|
|||||||
TenantContext.clear();
|
TenantContext.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateTenantWithIncorrectAzureStorage() {
|
public void testUpdateTenantWithIncorrectAzureStorage() {
|
||||||
|
|
||||||
testTenantService.createTestTenantWithoutStorageIfNotExist("new_tenant_without_storage");
|
testTenantService.createTestTenantWithoutStorageIfNotExist("new_tenant_without_storage");
|
||||||
TenantContext.setTenantId("new_tenant_without_storage");
|
TenantContext.setTenantId("new_tenant_without_storage");
|
||||||
|
|
||||||
var tenantRequest = TenantRequest.builder()
|
var tenantRequest = TenantRequest.builder()
|
||||||
.tenantId("new_tenant_without_storage")
|
.tenantId("new_tenant_without_storage")
|
||||||
.azureStorageConnection(AzureStorageConnection.builder()
|
.azureStorageConnection(AzureStorageConnection.builder().connectionString("updated_connection").containerName("updated_container").build())
|
||||||
.connectionString("updated_connection")
|
|
||||||
.containerName("updated_container")
|
|
||||||
.build())
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
var exception = assertThrows(FeignException.BadRequest.class, () -> tenantsClient.updateTenant("new_tenant_without_storage", tenantRequest));
|
var exception = assertThrows(FeignException.BadRequest.class, () -> tenantsClient.updateTenant("new_tenant_without_storage", tenantRequest));
|
||||||
@ -164,17 +169,16 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest {
|
|||||||
TenantContext.clear();
|
TenantContext.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateTenantWithBothAzureAndS3Storage() {
|
public void testUpdateTenantWithBothAzureAndS3Storage() {
|
||||||
|
|
||||||
testTenantService.createTestTenantIfNotExists("new_tenant", minioPort);
|
testTenantService.createTestTenantIfNotExists("new_tenant", minioPort);
|
||||||
TenantContext.setTenantId("new_tenant");
|
TenantContext.setTenantId("new_tenant");
|
||||||
|
|
||||||
var tenantRequest = TenantRequest.builder()
|
var tenantRequest = TenantRequest.builder()
|
||||||
.tenantId("new_tenant")
|
.tenantId("new_tenant")
|
||||||
.azureStorageConnection(AzureStorageConnection.builder()
|
.azureStorageConnection(AzureStorageConnection.builder().connectionString("updated_connection").containerName("updated_container").build())
|
||||||
.connectionString("updated_connection")
|
|
||||||
.containerName("updated_container")
|
|
||||||
.build())
|
|
||||||
.s3StorageConnection(S3StorageConnection.builder()
|
.s3StorageConnection(S3StorageConnection.builder()
|
||||||
.key("updated_key")
|
.key("updated_key")
|
||||||
.bucketName("updated_bucket")
|
.bucketName("updated_bucket")
|
||||||
@ -191,17 +195,16 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest {
|
|||||||
TenantContext.clear();
|
TenantContext.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateTenantFromS3ToAzureStorage() {
|
public void testUpdateTenantFromS3ToAzureStorage() {
|
||||||
|
|
||||||
testTenantService.createTestTenantIfNotExists("new_tenant_with_s3", minioPort);
|
testTenantService.createTestTenantIfNotExists("new_tenant_with_s3", minioPort);
|
||||||
TenantContext.setTenantId("new_tenant_with_s3");
|
TenantContext.setTenantId("new_tenant_with_s3");
|
||||||
|
|
||||||
var tenantRequest = TenantRequest.builder()
|
var tenantRequest = TenantRequest.builder()
|
||||||
.tenantId("new_tenant_with_s3")
|
.tenantId("new_tenant_with_s3")
|
||||||
.azureStorageConnection(AzureStorageConnection.builder()
|
.azureStorageConnection(AzureStorageConnection.builder().connectionString("updated_connection").containerName("updated_container").build())
|
||||||
.connectionString("updated_connection")
|
|
||||||
.containerName("updated_container")
|
|
||||||
.build())
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
var exception = assertThrows(FeignException.BadRequest.class, () -> tenantsClient.updateTenant("new_tenant_with_s3", tenantRequest));
|
var exception = assertThrows(FeignException.BadRequest.class, () -> tenantsClient.updateTenant("new_tenant_with_s3", tenantRequest));
|
||||||
@ -210,8 +213,10 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest {
|
|||||||
TenantContext.clear();
|
TenantContext.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemovePasswords() {
|
public void testRemovePasswords() {
|
||||||
|
|
||||||
testTenantService.createTestTenantIfNotExists("new_tenant_passwords", minioPort);
|
testTenantService.createTestTenantIfNotExists("new_tenant_passwords", minioPort);
|
||||||
|
|
||||||
TenantContext.setTenantId("new_tenant_passwords");
|
TenantContext.setTenantId("new_tenant_passwords");
|
||||||
@ -230,6 +235,7 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPasswordPolicy() {
|
public void testPasswordPolicy() {
|
||||||
|
|
||||||
testTenantService.createTestTenantIfNotExists("new_tenant", minioPort);
|
testTenantService.createTestTenantIfNotExists("new_tenant", minioPort);
|
||||||
|
|
||||||
TenantContext.setTenantId("new_tenant");
|
TenantContext.setTenantId("new_tenant");
|
||||||
@ -242,4 +248,5 @@ public class TenantsTest extends AbstractTenantUserManagementIntegrationTest {
|
|||||||
|
|
||||||
TenantContext.clear();
|
TenantContext.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import com.knecon.fforesight.tenantusermanagement.model.TenantUser;
|
|||||||
import com.knecon.fforesight.testcontainers.SpringPostgreSQLTestContainer;
|
import com.knecon.fforesight.testcontainers.SpringPostgreSQLTestContainer;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import software.amazon.awssdk.regions.Region;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@ -29,6 +30,7 @@ public class TestTenantService {
|
|||||||
|
|
||||||
private final TokenService tokenService;
|
private final TokenService tokenService;
|
||||||
|
|
||||||
|
|
||||||
public void createTestTenantIfNotExists(String testTenantId, int actualPort) {
|
public void createTestTenantIfNotExists(String testTenantId, int actualPort) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -42,7 +44,9 @@ public class TestTenantService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void createTestTenantWithoutStorageIfNotExist(String testTenantId) {
|
public void createTestTenantWithoutStorageIfNotExist(String testTenantId) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var tenantExists = internalTenantsResource.getTenant(testTenantId);
|
var tenantExists = internalTenantsResource.getTenant(testTenantId);
|
||||||
assertThat(tenantExists.getGuid()).isNotBlank();
|
assertThat(tenantExists.getGuid()).isNotBlank();
|
||||||
@ -53,6 +57,7 @@ public class TestTenantService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void createUser(String testTenantId, int actualPort, boolean withStorage) {
|
private void createUser(String testTenantId, int actualPort, boolean withStorage) {
|
||||||
// not found
|
// not found
|
||||||
TenantRequest tenantRequest;
|
TenantRequest tenantRequest;
|
||||||
@ -70,12 +75,16 @@ public class TestTenantService {
|
|||||||
.username(SpringPostgreSQLTestContainer.getInstance().getUsername())
|
.username(SpringPostgreSQLTestContainer.getInstance().getUsername())
|
||||||
.password(SpringPostgreSQLTestContainer.getInstance().getPassword())
|
.password(SpringPostgreSQLTestContainer.getInstance().getPassword())
|
||||||
.build())
|
.build())
|
||||||
.searchConnection(SearchConnection.builder().hosts(Set.of("localhost")).port(9200).scheme("http").numberOfShards("1").numberOfReplicas("5").build());
|
.searchConnection(SearchConnection.builder().hosts(Set.of("localhost")).port(9200).scheme("http").numberOfShards("1").numberOfReplicas("5").indexName("indexname").build());
|
||||||
|
|
||||||
if (withStorage) {
|
if (withStorage) {
|
||||||
tenantRequest = tenantRequestBuilder
|
tenantRequest = tenantRequestBuilder.s3StorageConnection(S3StorageConnection.builder()
|
||||||
.s3StorageConnection(S3StorageConnection.builder().key("minioadmin").secret("minioadmin").bucketName("redaction").endpoint("http://localhost:" + actualPort).build())
|
.key("minioadmin")
|
||||||
.build();
|
.secret("minioadmin")
|
||||||
|
.bucketName(testTenantId.replaceAll("-", "").replaceAll("_", ""))
|
||||||
|
.endpoint("http://localhost:" + actualPort)
|
||||||
|
.region(Region.AWS_GLOBAL.id())
|
||||||
|
.build()).build();
|
||||||
} else {
|
} else {
|
||||||
tenantRequest = tenantRequestBuilder.build();
|
tenantRequest = tenantRequestBuilder.build();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user