diff --git a/.gitignore b/.gitignore index f447adf..1a5cd14 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,5 @@ build/ .gradle/ gradle.properties - +gradlew +gradlew.bat diff --git a/src/main/java/com/knecon/fforesight/tenantusermanagement/DevConfiguration.java b/src/main/java/com/knecon/fforesight/tenantusermanagement/DevConfiguration.java index af215fe..5f20403 100644 --- a/src/main/java/com/knecon/fforesight/tenantusermanagement/DevConfiguration.java +++ b/src/main/java/com/knecon/fforesight/tenantusermanagement/DevConfiguration.java @@ -1,12 +1,17 @@ package com.knecon.fforesight.tenantusermanagement; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.sql.Connection; import java.sql.DriverManager; +import java.util.ArrayList; import java.util.Set; import java.util.UUID; import java.util.stream.Stream; @@ -16,6 +21,8 @@ import java.util.zip.ZipOutputStream; import javax.annotation.PostConstruct; import javax.sql.DataSource; +import org.apache.commons.io.IOUtils; +import org.checkerframework.checker.units.qual.A; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; @@ -24,11 +31,16 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.StatementCallback; import org.springframework.jdbc.datasource.SingleConnectionDataSource; +import com.fasterxml.jackson.databind.ObjectMapper; import com.knecon.fforesight.tenantcommons.model.DatabaseConnection; import com.knecon.fforesight.tenantcommons.model.S3StorageConnection; import com.knecon.fforesight.tenantcommons.model.SearchConnection; import com.knecon.fforesight.tenantusermanagement.model.TenantRequest; +import com.knecon.fforesight.tenantusermanagement.model.TenantUser; +import com.knecon.fforesight.tenantusermanagement.model.User; import com.knecon.fforesight.tenantusermanagement.properties.TenantUserManagementProperties; +import com.knecon.fforesight.tenantusermanagement.service.KeyCloakRoleManagerService; +import com.knecon.fforesight.tenantusermanagement.service.RealmService; import com.knecon.fforesight.tenantusermanagement.service.TenantManagementService; import lombok.SneakyThrows; @@ -42,16 +54,22 @@ public class DevConfiguration { @Autowired private TenantManagementService tenantManagementService; @Autowired + private KeyCloakRoleManagerService keyCloakRoleManagerService; + @Autowired private DataSource dataSource; @Value("${spring.datasource.url:}") private String masterJDBCURL; @Autowired private TenantUserManagementProperties tenantUserManagementProperties; + @Autowired + private RealmService realmService; @PostConstruct + @SneakyThrows public void postConstruct() { + var tenant = 1; try { tenantManagementService.getTenant("tenant" + tenant); diff --git a/src/main/java/com/knecon/fforesight/tenantusermanagement/service/TenantManagementService.java b/src/main/java/com/knecon/fforesight/tenantusermanagement/service/TenantManagementService.java index 4f58475..7d3a545 100644 --- a/src/main/java/com/knecon/fforesight/tenantusermanagement/service/TenantManagementService.java +++ b/src/main/java/com/knecon/fforesight/tenantusermanagement/service/TenantManagementService.java @@ -60,7 +60,7 @@ import lombok.extern.slf4j.Slf4j; public class TenantManagementService implements TenantProvider { private static final Long MAX_WAIT_TIME = 60_000L; // 60 seconds - + private static final String FRONTEND_URL_PROPERY = "frontendUrl"; private static final Set SUPPORTED_DATABASES = Set.of("postgresql"); private final EncryptionDecryptionService encryptionService; @@ -75,6 +75,8 @@ public class TenantManagementService implements TenantProvider { @Value("${fforesight.tenant-exchange.name}") private String tenantExchangeName; + @Value("${fforesight.tenant-use-management.server-url:}") + private String authServerUrl; @SneakyThrows public void createTenant(TenantRequest tenantRequest) { @@ -196,7 +198,7 @@ public class TenantManagementService implements TenantProvider { } - private void createRealm(String tenantId, List users) { + public void createRealm(String tenantId, List users) { var realm = new RealmRepresentation(); realm.setId(tenantId); @@ -208,6 +210,8 @@ public class TenantManagementService implements TenantProvider { realm.setAccessTokenLifespan(tenantUserManagementProperties.getTenantAccessTokenLifeSpan()); realm.setSsoSessionIdleTimeout(tenantUserManagementProperties.getSsoSessionIdleTimeout()); + realm.getAttributesOrEmpty().put(FRONTEND_URL_PROPERY,authServerUrl); + var applicationClient = new ClientRepresentation(); applicationClient.setEnabled(true); applicationClient.setName(tenantUserManagementProperties.getApplicationClientId()); diff --git a/src/main/resources/application-redaction.yaml b/src/main/resources/application-redaction.yaml index 388844d..082fe05 100644 --- a/src/main/resources/application-redaction.yaml +++ b/src/main/resources/application-redaction.yaml @@ -1,6 +1,4 @@ fforesight: - springdoc: - default-tenant: 'redaction' tenant-user-management: application-client-id: 'redaction' application-name: 'RedactManager' @@ -53,6 +51,5 @@ fforesight: permissions: ["fforesight-manage-user-preferences", "fforesight-read-all-users", "red-read-dossier", "red-read-app-configuration", "fforesight-read-general-configuration", "red-read-notification", "fforesight-read-users", "fforesight-update-my-profile", "red-update-notification", "fforesight-write-users", "red-read-license"] - - - + springdoc: + default-tenant: 'redaction'