Compare commits

...

1 Commits

Author SHA1 Message Date
Ali Oezyetimoglu
ce55284d13 RED-7297: set password policy in a simple way 2023-08-18 09:49:51 +02:00

View File

@ -10,7 +10,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.sql.DataSource;
@ -65,6 +64,8 @@ public class TenantManagementService implements TenantProvider {
private static final Set<String> SUPPORTED_DATABASES = Set.of("postgresql");
private static final String PASSWORD = "**********";
// private final KeycloakSession session;
private final EncryptionDecryptionService encryptionService;
private final TenantRepository tenantRepository;
private final TenantPersistenceService tenantPersistenceService;
@ -83,7 +84,7 @@ public class TenantManagementService implements TenantProvider {
@SneakyThrows
public TenantResponse createTenant(TenantRequest tenantRequest) {
log.info("Tenants are: {}", tenantRepository.findAll().stream().map(TenantEntity::getTenantId).collect(Collectors.toList()));
log.info("Tenants are: {}", tenantRepository.findAll().stream().map(TenantEntity::getTenantId).toList());
log.info("Requested to create tenant for: {}", tenantRequest.getTenantId());
try {
@ -295,7 +296,11 @@ public class TenantManagementService implements TenantProvider {
rolesRepresentation.setRealm(roles);
realm.setRoles(rolesRepresentation);
realm.setUsers(users.stream().map(this::toUserRepresentation).collect(Collectors.toList()));
realm.setUsers(users.stream().map(this::toUserRepresentation).toList());
var policyString = "digits and length and lowerCase and notEmail and notUsername and specialChars and upperCase";
// PasswordPolicy passwordPolicy = PasswordPolicy.parse(session, policyString);
realm.setPasswordPolicy(policyString);
keycloak.getAdminClient().realms().create(realm);
}
@ -442,9 +447,10 @@ public class TenantManagementService implements TenantProvider {
public List<TenantResponse> getTenants() {
return tenantRepository.findAll().stream().map(this::convert).collect(Collectors.toList());
return tenantRepository.findAll().stream().map(this::convert).toList();
}
public TenantResponse removePasswords(TenantResponse tenantResponse) {
if (tenantResponse.getDatabaseConnection() != null) {
@ -459,7 +465,7 @@ public class TenantManagementService implements TenantProvider {
tenantResponse.getAzureStorageConnection().setConnectionString(PASSWORD);
}
if (tenantResponse.getS3StorageConnection() != null){
if (tenantResponse.getS3StorageConnection() != null) {
tenantResponse.getS3StorageConnection().setSecret(PASSWORD);
}