You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2024/06/25 01:54:37 UTC

(james-project) 04/04: JAMES-2586 Change boolean rlsEnabled to enum RowLevelSecurity

This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch postgresql
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit f65808e81d3a6a7c69382aadde74b38d490e7a33
Author: hung phan <hp...@linagora.com>
AuthorDate: Fri Jun 21 16:12:04 2024 +0700

    JAMES-2586 Change boolean rlsEnabled to enum RowLevelSecurity
---
 .../backends/postgres/PostgresConfiguration.java   | 16 +++++------
 .../james/backends/postgres/PostgresTable.java     | 12 ++++----
 .../backends/postgres/PostgresTableManager.java    | 12 ++++----
 .../james/backends/postgres/RowLevelSecurity.java} | 19 +++++++------
 .../utils/PoolBackedPostgresConnectionFactory.java | 14 ++++++----
 .../PoolBackedPostgresConnectionFactoryTest.java   |  2 +-
 .../postgres/PostgresConfigurationTest.java        |  4 +--
 .../james/backends/postgres/PostgresExtension.java | 32 ++++++++++------------
 .../postgres/PostgresTableManagerTest.java         | 15 ++++------
 .../PostgresMailboxSessionMapperFactory.java       |  7 +++--
 .../RLSSupportPostgresMailboxMapperACLTest.java    |  4 +--
 .../apache/james/PostgresJamesConfiguration.java   |  4 ++-
 .../james/modules/data/PostgresCommonModule.java   |  8 +++---
 13 files changed, 75 insertions(+), 74 deletions(-)

diff --git a/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/PostgresConfiguration.java b/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/PostgresConfiguration.java
index e66e452a00..29e5d90476 100644
--- a/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/PostgresConfiguration.java
+++ b/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/PostgresConfiguration.java
@@ -256,7 +256,7 @@ public class PostgresConfiguration {
                 databaseSchema.orElse(DATABASE_SCHEMA_DEFAULT_VALUE),
                 new Credential(username.get(), password.get()),
                 new Credential(byPassRLSUser.orElse(username.get()), byPassRLSPassword.orElse(password.get())),
-                rowLevelSecurityEnabled.orElse(false),
+                    rowLevelSecurityEnabled.filter(rlsEnabled -> rlsEnabled).map(rlsEnabled -> RowLevelSecurity.ENABLED).orElse(RowLevelSecurity.DISABLED),
                 poolInitialSize.orElse(POOL_INITIAL_SIZE_DEFAULT_VALUE),
                 poolMaxSize.orElse(POOL_MAX_SIZE_DEFAULT_VALUE),
                 byPassRLSPoolInitialSize.orElse(BY_PASS_RLS_POOL_INITIAL_SIZE_DEFAULT_VALUE),
@@ -297,7 +297,7 @@ public class PostgresConfiguration {
     private final String databaseSchema;
     private final Credential defaultCredential;
     private final Credential byPassRLSCredential;
-    private final boolean rowLevelSecurityEnabled;
+    private final RowLevelSecurity rowLevelSecurity;
     private final Integer poolInitialSize;
     private final Integer poolMaxSize;
     private final Integer byPassRLSPoolInitialSize;
@@ -306,7 +306,7 @@ public class PostgresConfiguration {
     private final Duration jooqReactiveTimeout;
 
     private PostgresConfiguration(String host, int port, String databaseName, String databaseSchema,
-                                  Credential defaultCredential, Credential byPassRLSCredential, boolean rowLevelSecurityEnabled,
+                                  Credential defaultCredential, Credential byPassRLSCredential, RowLevelSecurity rowLevelSecurity,
                                   Integer poolInitialSize, Integer poolMaxSize,
                                   Integer byPassRLSPoolInitialSize, Integer byPassRLSPoolMaxSize,
                                   SSLMode sslMode, Duration jooqReactiveTimeout) {
@@ -316,7 +316,7 @@ public class PostgresConfiguration {
         this.databaseSchema = databaseSchema;
         this.defaultCredential = defaultCredential;
         this.byPassRLSCredential = byPassRLSCredential;
-        this.rowLevelSecurityEnabled = rowLevelSecurityEnabled;
+        this.rowLevelSecurity = rowLevelSecurity;
         this.poolInitialSize = poolInitialSize;
         this.poolMaxSize = poolMaxSize;
         this.byPassRLSPoolInitialSize = byPassRLSPoolInitialSize;
@@ -349,8 +349,8 @@ public class PostgresConfiguration {
         return byPassRLSCredential;
     }
 
-    public boolean rowLevelSecurityEnabled() {
-        return rowLevelSecurityEnabled;
+    public RowLevelSecurity getRowLevelSecurity() {
+        return rowLevelSecurity;
     }
 
     public Integer poolInitialSize() {
@@ -379,7 +379,7 @@ public class PostgresConfiguration {
 
     @Override
     public final int hashCode() {
-        return Objects.hash(host, port, databaseName, databaseSchema, defaultCredential, byPassRLSCredential, rowLevelSecurityEnabled, poolInitialSize, poolMaxSize, sslMode, jooqReactiveTimeout);
+        return Objects.hash(host, port, databaseName, databaseSchema, defaultCredential, byPassRLSCredential, rowLevelSecurity, poolInitialSize, poolMaxSize, sslMode, jooqReactiveTimeout);
     }
 
     @Override
@@ -387,7 +387,7 @@ public class PostgresConfiguration {
         if (o instanceof PostgresConfiguration) {
             PostgresConfiguration that = (PostgresConfiguration) o;
 
-            return Objects.equals(this.rowLevelSecurityEnabled, that.rowLevelSecurityEnabled)
+            return Objects.equals(this.rowLevelSecurity, that.rowLevelSecurity)
                 && Objects.equals(this.host, that.host)
                 && Objects.equals(this.port, that.port)
                 && Objects.equals(this.defaultCredential, that.defaultCredential)
diff --git a/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/PostgresTable.java b/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/PostgresTable.java
index 0333f6b650..f9bd1308c9 100644
--- a/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/PostgresTable.java
+++ b/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/PostgresTable.java
@@ -60,7 +60,7 @@ public class PostgresTable {
             this.query = query;
         }
 
-        abstract boolean shouldBeApplied(boolean rowLevelSecurityEnabled);
+        abstract boolean shouldBeApplied(RowLevelSecurity rowLevelSecurity);
 
         public String getQuery() {
             return query;
@@ -73,8 +73,8 @@ public class PostgresTable {
         }
 
         @Override
-        boolean shouldBeApplied(boolean rowLevelSecurityEnabled) {
-            return rowLevelSecurityEnabled;
+        boolean shouldBeApplied(RowLevelSecurity rowLevelSecurity) {
+            return rowLevelSecurity.isRowLevelSecurityEnabled();
         }
     }
 
@@ -84,8 +84,8 @@ public class PostgresTable {
         }
 
         @Override
-        boolean shouldBeApplied(boolean rowLevelSecurityEnabled) {
-            return !rowLevelSecurityEnabled;
+        boolean shouldBeApplied(RowLevelSecurity rowLevelSecurity) {
+            return !rowLevelSecurity.isRowLevelSecurityEnabled();
         }
     }
 
@@ -95,7 +95,7 @@ public class PostgresTable {
         }
 
         @Override
-        boolean shouldBeApplied(boolean rowLevelSecurityEnabled) {
+        boolean shouldBeApplied(RowLevelSecurity rowLevelSecurity) {
             return true;
         }
     }
diff --git a/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/PostgresTableManager.java b/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/PostgresTableManager.java
index 7df62d890f..ffb8849768 100644
--- a/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/PostgresTableManager.java
+++ b/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/PostgresTableManager.java
@@ -43,7 +43,7 @@ public class PostgresTableManager implements Startable {
     private static final Logger LOGGER = LoggerFactory.getLogger(PostgresTableManager.class);
     private final PostgresExecutor postgresExecutor;
     private final PostgresModule module;
-    private final boolean rowLevelSecurityEnabled;
+    private final RowLevelSecurity rowLevelSecurity;
 
     @Inject
     public PostgresTableManager(PostgresExecutor postgresExecutor,
@@ -51,14 +51,14 @@ public class PostgresTableManager implements Startable {
                                 PostgresConfiguration postgresConfiguration) {
         this.postgresExecutor = postgresExecutor;
         this.module = module;
-        this.rowLevelSecurityEnabled = postgresConfiguration.rowLevelSecurityEnabled();
+        this.rowLevelSecurity = postgresConfiguration.getRowLevelSecurity();
     }
 
     @VisibleForTesting
-    public PostgresTableManager(PostgresExecutor postgresExecutor, PostgresModule module, boolean rowLevelSecurityEnabled) {
+    public PostgresTableManager(PostgresExecutor postgresExecutor, PostgresModule module, RowLevelSecurity rowLevelSecurity) {
         this.postgresExecutor = postgresExecutor;
         this.module = module;
-        this.rowLevelSecurityEnabled = rowLevelSecurityEnabled;
+        this.rowLevelSecurity = rowLevelSecurity;
     }
 
     public void initPostgres() {
@@ -123,7 +123,7 @@ public class PostgresTableManager implements Startable {
 
     private Mono<Void> executeAdditionalAlterQueries(PostgresTable table, Connection connection) {
         return Flux.fromIterable(table.getAdditionalAlterQueries())
-            .filter(additionalAlterQuery -> additionalAlterQuery.shouldBeApplied(rowLevelSecurityEnabled))
+            .filter(additionalAlterQuery -> additionalAlterQuery.shouldBeApplied(rowLevelSecurity))
             .map(PostgresTable.AdditionalAlterQuery::getQuery)
             .concatMap(alterSQLQuery -> Mono.just(connection)
                 .flatMapMany(pgConnection -> pgConnection.createStatement(alterSQLQuery)
@@ -141,7 +141,7 @@ public class PostgresTableManager implements Startable {
     }
 
     private Mono<Void> enableRLSIfNeeded(PostgresTable table, Connection connection) {
-        if (rowLevelSecurityEnabled && table.supportsRowLevelSecurity()) {
+        if (rowLevelSecurity.isRowLevelSecurityEnabled() && table.supportsRowLevelSecurity()) {
             return alterTableEnableRLS(table, connection);
         }
         return Mono.empty();
diff --git a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PoolBackedPostgresConnectionFactoryTest.java b/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/RowLevelSecurity.java
similarity index 67%
copy from backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PoolBackedPostgresConnectionFactoryTest.java
copy to backends-common/postgres/src/main/java/org/apache/james/backends/postgres/RowLevelSecurity.java
index 31bd7afc46..2f806b6c74 100644
--- a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PoolBackedPostgresConnectionFactoryTest.java
+++ b/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/RowLevelSecurity.java
@@ -19,16 +19,17 @@
 
 package org.apache.james.backends.postgres;
 
-import org.apache.james.backends.postgres.utils.JamesPostgresConnectionFactory;
-import org.apache.james.backends.postgres.utils.PoolBackedPostgresConnectionFactory;
-import org.junit.jupiter.api.extension.RegisterExtension;
+public enum RowLevelSecurity {
+    ENABLED(true),
+    DISABLED(false);
 
-public class PoolBackedPostgresConnectionFactoryTest extends JamesPostgresConnectionFactoryTest {
-    @RegisterExtension
-    static PostgresExtension postgresExtension = PostgresExtension.empty();
+    private boolean rowLevelSecurityEnabled;
 
-    @Override
-    JamesPostgresConnectionFactory jamesPostgresConnectionFactory() {
-        return new PoolBackedPostgresConnectionFactory(true, postgresExtension.getConnectionFactory());
+    RowLevelSecurity(boolean rowLevelSecurityEnabled) {
+        this.rowLevelSecurityEnabled = rowLevelSecurityEnabled;
+    }
+
+    public boolean isRowLevelSecurityEnabled() {
+        return rowLevelSecurityEnabled;
     }
 }
diff --git a/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/utils/PoolBackedPostgresConnectionFactory.java b/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/utils/PoolBackedPostgresConnectionFactory.java
index 02af49b468..465f93a1c3 100644
--- a/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/utils/PoolBackedPostgresConnectionFactory.java
+++ b/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/utils/PoolBackedPostgresConnectionFactory.java
@@ -19,6 +19,7 @@
 
 package org.apache.james.backends.postgres.utils;
 
+import org.apache.james.backends.postgres.RowLevelSecurity;
 import org.apache.james.core.Domain;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -33,11 +34,12 @@ public class PoolBackedPostgresConnectionFactory implements JamesPostgresConnect
     private static final Logger LOGGER = LoggerFactory.getLogger(PoolBackedPostgresConnectionFactory.class);
     private static final int DEFAULT_INITIAL_SIZE = 10;
     private static final int DEFAULT_MAX_SIZE = 20;
-    private final boolean rowLevelSecurityEnabled;
+
+    private final RowLevelSecurity rowLevelSecurity;
     private final ConnectionPool pool;
 
-    public PoolBackedPostgresConnectionFactory(boolean rowLevelSecurityEnabled, int initialSize, int maxSize, ConnectionFactory connectionFactory) {
-        this.rowLevelSecurityEnabled = rowLevelSecurityEnabled;
+    public PoolBackedPostgresConnectionFactory(RowLevelSecurity rowLevelSecurity, int initialSize, int maxSize, ConnectionFactory connectionFactory) {
+        this.rowLevelSecurity = rowLevelSecurity;
         ConnectionPoolConfiguration configuration = ConnectionPoolConfiguration.builder(connectionFactory)
             .initialSize(initialSize)
             .maxSize(maxSize)
@@ -46,13 +48,13 @@ public class PoolBackedPostgresConnectionFactory implements JamesPostgresConnect
         pool = new ConnectionPool(configuration);
     }
 
-    public PoolBackedPostgresConnectionFactory(boolean rowLevelSecurityEnabled, ConnectionFactory connectionFactory) {
-        this(rowLevelSecurityEnabled, DEFAULT_INITIAL_SIZE, DEFAULT_MAX_SIZE, connectionFactory);
+    public PoolBackedPostgresConnectionFactory(RowLevelSecurity rowLevelSecurity, ConnectionFactory connectionFactory) {
+        this(rowLevelSecurity, DEFAULT_INITIAL_SIZE, DEFAULT_MAX_SIZE, connectionFactory);
     }
 
     @Override
     public Mono<Connection> getConnection(Domain domain) {
-        if (rowLevelSecurityEnabled) {
+        if (rowLevelSecurity.isRowLevelSecurityEnabled()) {
             return pool.create().flatMap(connection -> setDomainAttributeForConnection(domain.asString(), connection));
         } else {
             return pool.create();
diff --git a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PoolBackedPostgresConnectionFactoryTest.java b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PoolBackedPostgresConnectionFactoryTest.java
index 31bd7afc46..4e4cb45b7f 100644
--- a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PoolBackedPostgresConnectionFactoryTest.java
+++ b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PoolBackedPostgresConnectionFactoryTest.java
@@ -29,6 +29,6 @@ public class PoolBackedPostgresConnectionFactoryTest extends JamesPostgresConnec
 
     @Override
     JamesPostgresConnectionFactory jamesPostgresConnectionFactory() {
-        return new PoolBackedPostgresConnectionFactory(true, postgresExtension.getConnectionFactory());
+        return new PoolBackedPostgresConnectionFactory(RowLevelSecurity.ENABLED, postgresExtension.getConnectionFactory());
     }
 }
diff --git a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresConfigurationTest.java b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresConfigurationTest.java
index 75cc50513d..08d76a2356 100644
--- a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresConfigurationTest.java
+++ b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresConfigurationTest.java
@@ -51,7 +51,7 @@ class PostgresConfigurationTest {
         assertThat(configuration.getDefaultCredential().getPassword()).isEqualTo("1");
         assertThat(configuration.getByPassRLSCredential().getUsername()).isEqualTo("bypassrlsjames");
         assertThat(configuration.getByPassRLSCredential().getPassword()).isEqualTo("2");
-        assertThat(configuration.rowLevelSecurityEnabled()).isEqualTo(true);
+        assertThat(configuration.getRowLevelSecurity()).isEqualTo(RowLevelSecurity.ENABLED);
         assertThat(configuration.getSslMode()).isEqualTo(SSLMode.REQUIRE);
     }
 
@@ -68,7 +68,7 @@ class PostgresConfigurationTest {
         assertThat(configuration.getDatabaseSchema()).isEqualTo(PostgresConfiguration.DATABASE_SCHEMA_DEFAULT_VALUE);
         assertThat(configuration.getByPassRLSCredential().getUsername()).isEqualTo("james");
         assertThat(configuration.getByPassRLSCredential().getPassword()).isEqualTo("1");
-        assertThat(configuration.rowLevelSecurityEnabled()).isEqualTo(false);
+        assertThat(configuration.getRowLevelSecurity()).isEqualTo(RowLevelSecurity.DISABLED);
         assertThat(configuration.getSslMode()).isEqualTo(SSLMode.ALLOW);
     }
 
diff --git a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtension.java b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtension.java
index e527ee1925..dc304746f6 100644
--- a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtension.java
+++ b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtension.java
@@ -70,10 +70,8 @@ public class PostgresExtension implements GuiceModuleTestExtension {
         }
     }
 
-    private static final boolean ROW_LEVEL_SECURITY_ENABLED = true;
-
     public static PostgresExtension withRowLevelSecurity(PostgresModule module) {
-        return new PostgresExtension(module, ROW_LEVEL_SECURITY_ENABLED);
+        return new PostgresExtension(module, RowLevelSecurity.ENABLED);
     }
 
     public static PostgresExtension withoutRowLevelSecurity(PostgresModule module) {
@@ -81,7 +79,7 @@ public class PostgresExtension implements GuiceModuleTestExtension {
     }
 
     public static PostgresExtension withoutRowLevelSecurity(PostgresModule module, PoolSize poolSize) {
-        return new PostgresExtension(module, !ROW_LEVEL_SECURITY_ENABLED, Optional.of(poolSize));
+        return new PostgresExtension(module, RowLevelSecurity.DISABLED, Optional.of(poolSize));
     }
 
     public static PostgresExtension empty() {
@@ -91,7 +89,7 @@ public class PostgresExtension implements GuiceModuleTestExtension {
     public static final PoolSize DEFAULT_POOL_SIZE = PoolSize.SMALL;
     public static PostgreSQLContainer<?> PG_CONTAINER = DockerPostgresSingleton.SINGLETON;
     private final PostgresModule postgresModule;
-    private final boolean rlsEnabled;
+    private final RowLevelSecurity rowLevelSecurity;
     private final PostgresFixture.Database selectedDatabase;
     private PoolSize poolSize;
     private PostgresConfiguration postgresConfiguration;
@@ -112,14 +110,14 @@ public class PostgresExtension implements GuiceModuleTestExtension {
             .exec();
     }
 
-    private PostgresExtension(PostgresModule postgresModule, boolean rlsEnabled) {
-        this(postgresModule, rlsEnabled, Optional.empty());
+    private PostgresExtension(PostgresModule postgresModule, RowLevelSecurity rowLevelSecurity) {
+        this(postgresModule, rowLevelSecurity, Optional.empty());
     }
 
-    private PostgresExtension(PostgresModule postgresModule, boolean rlsEnabled, Optional<PoolSize> maybePoolSize) {
+    private PostgresExtension(PostgresModule postgresModule, RowLevelSecurity rowLevelSecurity, Optional<PoolSize> maybePoolSize) {
         this.postgresModule = postgresModule;
-        this.rlsEnabled = rlsEnabled;
-        if (rlsEnabled) {
+        this.rowLevelSecurity = rowLevelSecurity;
+        if (rowLevelSecurity.isRowLevelSecurityEnabled()) {
             this.selectedDatabase = PostgresFixture.Database.ROW_LEVEL_SECURITY_DATABASE;
         } else {
             this.selectedDatabase = DEFAULT_DATABASE;
@@ -138,7 +136,7 @@ public class PostgresExtension implements GuiceModuleTestExtension {
     }
 
     private void querySettingRowLevelSecurityIfNeed() {
-        if (rlsEnabled) {
+        if (rowLevelSecurity.isRowLevelSecurityEnabled()) {
             Throwing.runnable(() -> {
                 PG_CONTAINER.execInContainer("psql", "-U", DEFAULT_DATABASE.dbUser(), "-c", "create user " + ROW_LEVEL_SECURITY_DATABASE.dbUser() + " WITH PASSWORD '" + ROW_LEVEL_SECURITY_DATABASE.dbPassword() + "';");
                 PG_CONTAINER.execInContainer("psql", "-U", DEFAULT_DATABASE.dbUser(), "-c", "create database " + ROW_LEVEL_SECURITY_DATABASE.dbName() + ";");
@@ -162,7 +160,7 @@ public class PostgresExtension implements GuiceModuleTestExtension {
             .password(selectedDatabase.dbPassword())
             .byPassRLSUser(DEFAULT_DATABASE.dbUser())
             .byPassRLSPassword(DEFAULT_DATABASE.dbPassword())
-            .rowLevelSecurityEnabled(rlsEnabled)
+            .rowLevelSecurityEnabled(rowLevelSecurity.isRowLevelSecurityEnabled())
             .jooqReactiveTimeout(Optional.of(Duration.ofSeconds(20L)))
             .build();
 
@@ -181,7 +179,7 @@ public class PostgresExtension implements GuiceModuleTestExtension {
         connectionFactory = new PostgresqlConnectionFactory(postgresqlConnectionConfigurationFunction.apply(postgresConfiguration.getDefaultCredential()));
         defaultConnection = connectionFactory.create().block();
         executorFactory = new PostgresExecutor.Factory(
-            getJamesPostgresConnectionFactory(rlsEnabled, connectionFactory),
+            getJamesPostgresConnectionFactory(rowLevelSecurity, connectionFactory),
             postgresConfiguration,
             metricFactory);
 
@@ -190,12 +188,12 @@ public class PostgresExtension implements GuiceModuleTestExtension {
         PostgresqlConnectionFactory byPassRLSConnectionFactory = new PostgresqlConnectionFactory(postgresqlConnectionConfigurationFunction.apply(postgresConfiguration.getByPassRLSCredential()));
 
         byPassRLSPostgresExecutor = new PostgresExecutor.Factory(
-            getJamesPostgresConnectionFactory(false, byPassRLSConnectionFactory),
+            getJamesPostgresConnectionFactory(RowLevelSecurity.DISABLED, byPassRLSConnectionFactory),
             postgresConfiguration,
             metricFactory)
             .create();
 
-        this.postgresTableManager = new PostgresTableManager(defaultPostgresExecutor, postgresModule, rlsEnabled);
+        this.postgresTableManager = new PostgresTableManager(defaultPostgresExecutor, postgresModule, rowLevelSecurity);
     }
 
     @Override
@@ -284,9 +282,9 @@ public class PostgresExtension implements GuiceModuleTestExtension {
             .block();
     }
 
-    private JamesPostgresConnectionFactory getJamesPostgresConnectionFactory(boolean rlsEnabled, PostgresqlConnectionFactory connectionFactory) {
+    private JamesPostgresConnectionFactory getJamesPostgresConnectionFactory(RowLevelSecurity rowLevelSecurity, PostgresqlConnectionFactory connectionFactory) {
         return new PoolBackedPostgresConnectionFactory(
-            rlsEnabled,
+            rowLevelSecurity,
             poolSize.getMin(),
             poolSize.getMax(),
             connectionFactory);
diff --git a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresTableManagerTest.java b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresTableManagerTest.java
index 9515422930..2980885fd8 100644
--- a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresTableManagerTest.java
+++ b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresTableManagerTest.java
@@ -41,7 +41,7 @@ class PostgresTableManagerTest {
     static PostgresExtension postgresExtension = PostgresExtension.withRowLevelSecurity(PostgresModule.EMPTY_MODULE);
 
     Function<PostgresModule, PostgresTableManager> tableManagerFactory =
-        module -> new PostgresTableManager(postgresExtension.getDefaultPostgresExecutor(), module, true);
+        module -> new PostgresTableManager(postgresExtension.getDefaultPostgresExecutor(), module, RowLevelSecurity.ENABLED);
 
     @Test
     void initializeTableShouldSuccessWhenModuleHasSingleTable() {
@@ -340,10 +340,7 @@ class PostgresTableManagerTest {
             .build();
 
         PostgresModule module = PostgresModule.table(table);
-        boolean disabledRLS = false;
-
-
-        PostgresTableManager testee = new PostgresTableManager(postgresExtension.getDefaultPostgresExecutor(), module, disabledRLS);
+        PostgresTableManager testee = new PostgresTableManager(postgresExtension.getDefaultPostgresExecutor(), module, RowLevelSecurity.DISABLED);
 
         testee.initializeTables()
             .block();
@@ -383,7 +380,7 @@ class PostgresTableManagerTest {
             .addAdditionalAlterQueries("ALTER TABLE tbn1 ADD CONSTRAINT " + constraintName + " EXCLUDE (clm2 WITH =)")
             .build();
         PostgresModule module = PostgresModule.table(table);
-        PostgresTableManager testee = new PostgresTableManager(postgresExtension.getDefaultPostgresExecutor(), module, false);
+        PostgresTableManager testee = new PostgresTableManager(postgresExtension.getDefaultPostgresExecutor(), module, RowLevelSecurity.DISABLED);
 
         testee.initializeTables().block();
 
@@ -409,7 +406,7 @@ class PostgresTableManagerTest {
             .addAdditionalAlterQueries(new PostgresTable.NonRLSOnlyAdditionalAlterQuery("ALTER TABLE tbn1 ADD CONSTRAINT " + constraintName + " EXCLUDE (clm2 WITH =)"))
             .build();
         PostgresModule module = PostgresModule.table(table);
-        PostgresTableManager testee = new PostgresTableManager(postgresExtension.getPostgresExecutor(), module, false);
+        PostgresTableManager testee = new PostgresTableManager(postgresExtension.getDefaultPostgresExecutor(), module, RowLevelSecurity.DISABLED);
 
         testee.initializeTables().block();
 
@@ -435,7 +432,7 @@ class PostgresTableManagerTest {
             .addAdditionalAlterQueries(new PostgresTable.NonRLSOnlyAdditionalAlterQuery("ALTER TABLE tbn1 ADD CONSTRAINT " + constraintName + " EXCLUDE (clm2 WITH =)"))
             .build();
         PostgresModule module = PostgresModule.table(table);
-        PostgresTableManager testee = new PostgresTableManager(postgresExtension.getPostgresExecutor(), module, true);
+        PostgresTableManager testee = new PostgresTableManager(postgresExtension.getDefaultPostgresExecutor(), module, RowLevelSecurity.ENABLED);
 
         testee.initializeTables().block();
 
@@ -461,7 +458,7 @@ class PostgresTableManagerTest {
             .addAdditionalAlterQueries("ALTER TABLE tbn1 ADD CONSTRAINT " + constraintName + " EXCLUDE (clm2 WITH =)")
             .build();
         PostgresModule module = PostgresModule.table(table);
-        PostgresTableManager testee = new PostgresTableManager(postgresExtension.getDefaultPostgresExecutor(), module, false);
+        PostgresTableManager testee = new PostgresTableManager(postgresExtension.getDefaultPostgresExecutor(), module, RowLevelSecurity.DISABLED);
 
         testee.initializeTables().block();
 
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxSessionMapperFactory.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxSessionMapperFactory.java
index 5a5035f15d..8e157c514b 100644
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxSessionMapperFactory.java
+++ b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxSessionMapperFactory.java
@@ -23,6 +23,7 @@ import java.time.Clock;
 import jakarta.inject.Inject;
 
 import org.apache.james.backends.postgres.PostgresConfiguration;
+import org.apache.james.backends.postgres.RowLevelSecurity;
 import org.apache.james.backends.postgres.utils.PostgresExecutor;
 import org.apache.james.blob.api.BlobId;
 import org.apache.james.blob.api.BlobStore;
@@ -60,7 +61,7 @@ public class PostgresMailboxSessionMapperFactory extends MailboxSessionMapperFac
     private final BlobStore blobStore;
     private final BlobId.Factory blobIdFactory;
     private final Clock clock;
-    private final boolean isRLSEnabled;
+    private final RowLevelSecurity rowLevelSecurity;
 
     @Inject
     public PostgresMailboxSessionMapperFactory(PostgresExecutor.Factory executorFactory,
@@ -72,13 +73,13 @@ public class PostgresMailboxSessionMapperFactory extends MailboxSessionMapperFac
         this.blobStore = blobStore;
         this.blobIdFactory = blobIdFactory;
         this.clock = clock;
-        this.isRLSEnabled = postgresConfiguration.rowLevelSecurityEnabled();
+        this.rowLevelSecurity = postgresConfiguration.getRowLevelSecurity();
     }
 
     @Override
     public MailboxMapper createMailboxMapper(MailboxSession session) {
         PostgresMailboxDAO mailboxDAO = new PostgresMailboxDAO(executorFactory.create(session.getUser().getDomainPart()));
-        if (isRLSEnabled) {
+        if (rowLevelSecurity.isRowLevelSecurityEnabled()) {
             return new RLSSupportPostgresMailboxMapper(mailboxDAO,
                 new PostgresMailboxMemberDAO(executorFactory.create(session.getUser().getDomainPart())));
         } else {
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/RLSSupportPostgresMailboxMapperACLTest.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/RLSSupportPostgresMailboxMapperACLTest.java
index b42bc21cad..1352f0b74e 100644
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/RLSSupportPostgresMailboxMapperACLTest.java
+++ b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/RLSSupportPostgresMailboxMapperACLTest.java
@@ -33,7 +33,7 @@ class RLSSupportPostgresMailboxMapperACLTest extends MailboxMapperACLTest {
 
     @Override
     protected MailboxMapper createMailboxMapper() {
-        return new RLSSupportPostgresMailboxMapper(new PostgresMailboxDAO(postgresExtension.getPostgresExecutor()),
-            new PostgresMailboxMemberDAO(postgresExtension.getPostgresExecutor()));
+        return new RLSSupportPostgresMailboxMapper(new PostgresMailboxDAO(postgresExtension.getDefaultPostgresExecutor()),
+            new PostgresMailboxMemberDAO(postgresExtension.getDefaultPostgresExecutor()));
     }
 }
diff --git a/server/apps/postgres-app/src/main/java/org/apache/james/PostgresJamesConfiguration.java b/server/apps/postgres-app/src/main/java/org/apache/james/PostgresJamesConfiguration.java
index ba5e58516a..21b9c633c7 100644
--- a/server/apps/postgres-app/src/main/java/org/apache/james/PostgresJamesConfiguration.java
+++ b/server/apps/postgres-app/src/main/java/org/apache/james/PostgresJamesConfiguration.java
@@ -230,7 +230,9 @@ public class PostgresJamesConfiguration implements Configuration {
 
         private boolean readRLSEnabledFromFile(PropertiesProvider propertiesProvider) {
             try {
-                return PostgresConfiguration.from(propertiesProvider.getConfiguration(PostgresConfiguration.POSTGRES_CONFIGURATION_NAME)).rowLevelSecurityEnabled();
+                return PostgresConfiguration.from(propertiesProvider.getConfiguration(PostgresConfiguration.POSTGRES_CONFIGURATION_NAME))
+                    .getRowLevelSecurity()
+                    .isRowLevelSecurityEnabled();
             } catch (FileNotFoundException | ConfigurationException e) {
                 return false;
             }
diff --git a/server/container/guice/postgres-common/src/main/java/org/apache/james/modules/data/PostgresCommonModule.java b/server/container/guice/postgres-common/src/main/java/org/apache/james/modules/data/PostgresCommonModule.java
index c2b87b7018..c9c51a7ae6 100644
--- a/server/container/guice/postgres-common/src/main/java/org/apache/james/modules/data/PostgresCommonModule.java
+++ b/server/container/guice/postgres-common/src/main/java/org/apache/james/modules/data/PostgresCommonModule.java
@@ -28,6 +28,7 @@ import org.apache.commons.configuration2.ex.ConfigurationException;
 import org.apache.james.backends.postgres.PostgresConfiguration;
 import org.apache.james.backends.postgres.PostgresModule;
 import org.apache.james.backends.postgres.PostgresTableManager;
+import org.apache.james.backends.postgres.RowLevelSecurity;
 import org.apache.james.backends.postgres.utils.JamesPostgresConnectionFactory;
 import org.apache.james.backends.postgres.utils.PoolBackedPostgresConnectionFactory;
 import org.apache.james.backends.postgres.utils.PostgresConnectionClosure;
@@ -55,7 +56,6 @@ import io.r2dbc.spi.ConnectionFactory;
 
 public class PostgresCommonModule extends AbstractModule {
     private static final Logger LOGGER = LoggerFactory.getLogger("POSTGRES");
-    private static final boolean DISABLED_ROW_LEVEL_SECURITY = false;
 
     @Override
     public void configure() {
@@ -78,7 +78,7 @@ public class PostgresCommonModule extends AbstractModule {
     @Singleton
     JamesPostgresConnectionFactory provideJamesPostgresConnectionFactory(PostgresConfiguration postgresConfiguration,
                                                                          ConnectionFactory connectionFactory) {
-        return new PoolBackedPostgresConnectionFactory(postgresConfiguration.rowLevelSecurityEnabled(),
+        return new PoolBackedPostgresConnectionFactory(postgresConfiguration.getRowLevelSecurity(),
             postgresConfiguration.poolInitialSize(),
             postgresConfiguration.poolMaxSize(),
             connectionFactory);
@@ -90,10 +90,10 @@ public class PostgresCommonModule extends AbstractModule {
     JamesPostgresConnectionFactory provideJamesPostgresConnectionFactoryWithRLSBypass(PostgresConfiguration postgresConfiguration,
                                                                                       JamesPostgresConnectionFactory jamesPostgresConnectionFactory,
                                                                                       @Named(JamesPostgresConnectionFactory.BY_PASS_RLS_INJECT) ConnectionFactory connectionFactory) {
-        if (!postgresConfiguration.rowLevelSecurityEnabled()) {
+        if (!postgresConfiguration.getRowLevelSecurity().isRowLevelSecurityEnabled()) {
             return jamesPostgresConnectionFactory;
         }
-        return new PoolBackedPostgresConnectionFactory(DISABLED_ROW_LEVEL_SECURITY,
+        return new PoolBackedPostgresConnectionFactory(RowLevelSecurity.DISABLED,
             postgresConfiguration.byPassRLSPoolInitialSize(),
             postgresConfiguration.byPassRLSPoolMaxSize(),
             connectionFactory);


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org