RED-5293: 500 for invalid tenant
This commit is contained in:
parent
3157f3a602
commit
b4ae9b7137
@ -15,6 +15,8 @@ import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.jdbc.datasource.SingleConnectionDataSource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.exception.BadRequestException;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.exception.ConflictException;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.exception.NotFoundException;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.multitenancy.entity.TenantEntity;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.EncryptionDecryptionService;
|
||||
@ -55,6 +57,10 @@ public class TenantManagementService {
|
||||
|
||||
if (tenantRepository.findById(tenantRequest.getTenantId()).isEmpty()) {
|
||||
|
||||
if (tenantRequest.getDisplayName().isEmpty() || tenantRequest.getUser().isEmpty() || tenantRequest.getPassword().isBlank()) {
|
||||
throw new BadRequestException("Bad request: fields have wrong format or required fields are empty");
|
||||
}
|
||||
|
||||
String encryptedPassword = encryptionService.encrypt(tenantRequest.getPassword());
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(tenantRequest.getJdbcUrl(), tenantRequest.getUser(), tenantRequest.getPassword())) {
|
||||
@ -71,6 +77,8 @@ public class TenantManagementService {
|
||||
.password(encryptedPassword)
|
||||
.build();
|
||||
tenantRepository.save(tenantEntity);
|
||||
} else {
|
||||
throw new ConflictException("Conflict: tenant id already exists.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user