RED-5292: Split Tenant object into Request and Response without password
This commit is contained in:
parent
c9b91fd74e
commit
2dabbb1193
@ -9,7 +9,7 @@ import lombok.NoArgsConstructor;
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Tenant {
|
||||
public class TenantRequest {
|
||||
|
||||
private String tenantId;
|
||||
private String displayName;
|
||||
@ -0,0 +1,20 @@
|
||||
package com.iqser.red.service.persistence.service.v1.api.model.multitenancy;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class TenantResponse {
|
||||
|
||||
private String tenantId;
|
||||
private String displayName;
|
||||
private String guid;
|
||||
private String jdbcUrl;
|
||||
private String user;
|
||||
|
||||
}
|
||||
@ -11,7 +11,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.common.JSONPrimitive;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.multitenancy.Tenant;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.multitenancy.TenantRequest;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.multitenancy.TenantResponse;
|
||||
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
public interface TenantsResource {
|
||||
@ -20,11 +21,11 @@ public interface TenantsResource {
|
||||
String TENANT_ID_PATH_PARAM = "/{" + TENANT_ID_PARAM + "}";
|
||||
|
||||
@PostMapping(value = "/tenants", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
void createTenant(@RequestBody Tenant tenant);
|
||||
void createTenant(@RequestBody TenantRequest tenantRequest);
|
||||
|
||||
|
||||
@GetMapping(value = "/tenants", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
List<Tenant> getTenants();
|
||||
List<TenantResponse> getTenants();
|
||||
|
||||
@GetMapping(value = "/deploymentKey" + TENANT_ID_PATH_PARAM, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
JSONPrimitive<String> getDeploymentKey(@PathVariable(TENANT_ID_PARAM) String tenantId);
|
||||
|
||||
@ -9,7 +9,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import com.iqser.red.service.peristence.v1.server.service.DeploymentKeyService;
|
||||
import com.iqser.red.service.peristence.v1.server.service.TenantManagementService;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.common.JSONPrimitive;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.multitenancy.Tenant;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.multitenancy.TenantRequest;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.multitenancy.TenantResponse;
|
||||
import com.iqser.red.service.persistence.service.v1.api.resources.TenantsResource;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -24,13 +25,13 @@ public class TenantsController implements TenantsResource {
|
||||
|
||||
|
||||
|
||||
public void createTenant(@RequestBody Tenant tenant) {
|
||||
public void createTenant(@RequestBody TenantRequest tenantRequest) {
|
||||
|
||||
tenantManagementService.createTenant(tenant);
|
||||
tenantManagementService.createTenant(tenantRequest);
|
||||
}
|
||||
|
||||
|
||||
public List<Tenant> getTenants(){
|
||||
public List<TenantResponse> getTenants(){
|
||||
|
||||
return tenantManagementService.getTenants();
|
||||
}
|
||||
|
||||
@ -19,7 +19,8 @@ import com.iqser.red.service.persistence.management.v1.processor.exception.NotFo
|
||||
import com.iqser.red.service.persistence.management.v1.processor.multitenancy.entity.TenantEntity;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.EncryptionDecryptionService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.mulitenancy.repository.TenantRepository;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.multitenancy.Tenant;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.multitenancy.TenantRequest;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.multitenancy.TenantResponse;
|
||||
|
||||
import liquibase.exception.LiquibaseException;
|
||||
import liquibase.integration.spring.SpringLiquibase;
|
||||
@ -38,7 +39,8 @@ public class TenantManagementService {
|
||||
|
||||
public TenantManagementService(EncryptionDecryptionService encryptionService,
|
||||
@Qualifier("tenantLiquibaseProperties") LiquibaseProperties liquibaseProperties,
|
||||
ResourceLoader resourceLoader, TenantRepository tenantRepository) {
|
||||
ResourceLoader resourceLoader,
|
||||
TenantRepository tenantRepository) {
|
||||
|
||||
this.encryptionService = encryptionService;
|
||||
this.liquibaseProperties = liquibaseProperties;
|
||||
@ -49,23 +51,23 @@ public class TenantManagementService {
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
public void createTenant(Tenant tenant) {
|
||||
public void createTenant(TenantRequest tenantRequest) {
|
||||
|
||||
if (!tenantRepository.findById(tenant.getTenantId()).isPresent()) {
|
||||
if (tenantRepository.findById(tenantRequest.getTenantId()).isEmpty()) {
|
||||
|
||||
String encryptedPassword = encryptionService.encrypt(tenant.getPassword());
|
||||
String encryptedPassword = encryptionService.encrypt(tenantRequest.getPassword());
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(tenant.getJdbcUrl(), tenant.getUser(), tenant.getPassword())) {
|
||||
try (Connection connection = DriverManager.getConnection(tenantRequest.getJdbcUrl(), tenantRequest.getUser(), tenantRequest.getPassword())) {
|
||||
DataSource tenantDataSource = new SingleConnectionDataSource(connection, false);
|
||||
runLiquibase(tenantDataSource);
|
||||
}
|
||||
|
||||
TenantEntity tenantEntity = TenantEntity.builder()
|
||||
.tenantId(tenant.getTenantId())
|
||||
.displayName(tenant.getDisplayName())
|
||||
.tenantId(tenantRequest.getTenantId())
|
||||
.displayName(tenantRequest.getDisplayName())
|
||||
.guid(UUID.randomUUID().toString())
|
||||
.username(tenant.getUser())
|
||||
.jdbcUrl(tenant.getJdbcUrl())
|
||||
.username(tenantRequest.getUser())
|
||||
.jdbcUrl(tenantRequest.getJdbcUrl())
|
||||
.password(encryptedPassword)
|
||||
.build();
|
||||
tenantRepository.save(tenantEntity);
|
||||
@ -73,28 +75,27 @@ public class TenantManagementService {
|
||||
}
|
||||
|
||||
|
||||
public List<Tenant> getTenants() {
|
||||
public List<TenantResponse> getTenants() {
|
||||
|
||||
return tenantRepository.findAll().stream().map(this::convert).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
public Tenant getTenant(String tenantId) {
|
||||
public TenantResponse getTenant(String tenantId) {
|
||||
|
||||
return tenantRepository.findById(tenantId).map(this::convert).orElseThrow(() -> new NotFoundException("Tenant does not exist"));
|
||||
}
|
||||
|
||||
|
||||
private Tenant convert(TenantEntity entity) {
|
||||
private TenantResponse convert(TenantEntity entity) {
|
||||
|
||||
return Tenant.builder()
|
||||
.tenantId(entity.getTenantId())
|
||||
.displayName(entity.getDisplayName())
|
||||
.guid(entity.getGuid())
|
||||
.jdbcUrl(entity.getJdbcUrl())
|
||||
.password(encryptionService.decrypt(entity.getPassword()))
|
||||
.user(entity.getUsername())
|
||||
.build();
|
||||
return TenantResponse.builder()
|
||||
.tenantId(entity.getTenantId())
|
||||
.displayName(entity.getDisplayName())
|
||||
.guid(entity.getGuid())
|
||||
.jdbcUrl(entity.getJdbcUrl())
|
||||
.user(entity.getUsername())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -83,7 +83,7 @@ import com.iqser.red.service.persistence.management.v1.processor.service.persist
|
||||
import com.iqser.red.service.persistence.management.v1.processor.utils.multitenancy.TenantContext;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.configuration.ApplicationConfig;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileType;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.multitenancy.Tenant;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.multitenancy.TenantRequest;
|
||||
import com.iqser.red.service.redaction.v1.model.RedactionLog;
|
||||
import com.iqser.red.service.redaction.v1.model.RedactionResult;
|
||||
import com.iqser.red.storage.commons.StorageAutoConfiguration;
|
||||
@ -254,7 +254,7 @@ public abstract class AbstractPersistenceServerServiceTest {
|
||||
createDatabase("redaction", "redaction");
|
||||
createSchema(jdbcUrl, "redaction", "redaction");
|
||||
|
||||
tenantsClient.createTenant(new Tenant("redaction","Redaction default", UUID.randomUUID().toString(), jdbcUrl, "redaction", "redaction"));
|
||||
tenantsClient.createTenant(new TenantRequest("redaction", "Redaction default", UUID.randomUUID().toString(), jdbcUrl, "redaction", "redaction"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user