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 2023/11/13 04:04:15 UTC

(james-project) branch postgresql updated (94635f6a2f -> 753e8f6d3a)

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

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


    from 94635f6a2f JAMES-2586 postgres mailbox - drop JPAStreamingMailboxMessage, JPAEncryptedMailboxMessage, JPAMailboxMessageWithAttachmentStorage
     new 005cbd5a90 JAMES-2586 Use prepared statements by default
     new 690c513e2a JAMES-2586 Polish code style: PostgresSubscriptionMapper
     new 84ec3363b5 JAMES-2586 Merge PostgresSubscriptionTable and PostgresSubscriptionModule
     new 5207decc0d JAMES-2586 Drop Spring files for mailbox-postgres
     new d8d18a1709 JAMES-2586 Drop reporting-site.xml
     new 9a75315d5e JAMES-2586 Drop unused class: EncryptDecryptHelper
     new f8d1c60eef JAMES-2586 Drop unused class: JPASubscription
     new 553d0f0c5e JAMES-2586 Implement (failing) tests for Row Level Security applied on Subscriptions
     new 2cfbef2089 JAMES-2586 Document (link) varchar underlying maximum lengths
     new e74e0f6eee JAMES-2586 PostgresExtension: favor factory methods to constructor
     new 753e8f6d3a JAMES-2586 Small codestyle refactorings

The 11 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../backends/postgres/PostgresConfiguration.java   |  62 +++++-----
 .../james/backends/postgres/PostgresTable.java     |  24 ++--
 .../backends/postgres/PostgresTableManager.java    |  51 ++++----
 .../backends/postgres/utils/PostgresExecutor.java  |   4 +-
 .../postgres/ConnectionThreadSafetyTest.java       |   2 +-
 .../postgres/PostgresConfigurationTest.java        |   6 +-
 .../james/backends/postgres/PostgresExtension.java |  32 ++---
 .../backends/postgres/PostgresExtensionTest.java   |   6 +-
 .../postgres/PostgresTableManagerTest.java         |  26 ++--
 .../SimpleJamesPostgresConnectionFactoryTest.java  |   2 +-
 .../mail/model/openjpa/EncryptDecryptHelper.java   |  66 ----------
 .../postgres/user/PostgresSubscriptionDAO.java     |   6 +-
 .../postgres/user/PostgresSubscriptionMapper.java  |   7 +-
 .../postgres/user/PostgresSubscriptionModule.java  |  19 ++-
 .../postgres/user/PostgresSubscriptionTable.java   |  34 ------
 .../postgres/user/model/JPASubscription.java       | 136 ---------------------
 .../main/resources/META-INF/spring/mailbox-jpa.xml | 109 -----------------
 mailbox/postgres/src/reporting-site/site.xml       |  29 -----
 .../james/mailbox/postgres/JPAMailboxFixture.java  |   3 -
 .../mailbox/postgres/JPAMailboxManagerTest.java    |   2 +-
 .../postgres/JpaMailboxManagerStressTest.java      |   2 +-
 .../postgres/PostgresSubscriptionManagerTest.java  |   2 +-
 .../task/JPARecomputeCurrentQuotasServiceTest.java |   2 +-
 ...gresSubscriptionMapperRowLevelSecurityTest.java |  86 +++++++++++++
 .../user/PostgresSubscriptionMapperTest.java       |   2 +-
 .../postgres/src/test/resources/persistence.xml    |   1 -
 .../src/main/resources/META-INF/persistence.xml    |   1 -
 .../apache/james/JamesCapabilitiesServerTest.java  |   2 +-
 .../org/apache/james/PostgresJamesServerTest.java  |   2 +-
 ...WithAuthenticatedDatabaseSqlValidationTest.java |   2 +-
 ...atabaseAuthenticaticationSqlValidationTest.java |   2 +-
 .../james/PostgresWithLDAPJamesServerTest.java     |   2 +-
 32 files changed, 227 insertions(+), 505 deletions(-)
 delete mode 100644 mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/openjpa/EncryptDecryptHelper.java
 delete mode 100644 mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionTable.java
 delete mode 100644 mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/model/JPASubscription.java
 delete mode 100644 mailbox/postgres/src/main/resources/META-INF/spring/mailbox-jpa.xml
 delete mode 100644 mailbox/postgres/src/reporting-site/site.xml
 create mode 100644 mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperRowLevelSecurityTest.java


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


(james-project) 04/11: JAMES-2586 Drop Spring files for mailbox-postgres

Posted by rc...@apache.org.
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 5207decc0de90f57198e1f03bba506708cdd0d70
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Fri Nov 10 10:50:16 2023 +0100

    JAMES-2586 Drop Spring files for mailbox-postgres
---
 .../main/resources/META-INF/spring/mailbox-jpa.xml | 109 ---------------------
 1 file changed, 109 deletions(-)

diff --git a/mailbox/postgres/src/main/resources/META-INF/spring/mailbox-jpa.xml b/mailbox/postgres/src/main/resources/META-INF/spring/mailbox-jpa.xml
deleted file mode 100644
index 32b128c089..0000000000
--- a/mailbox/postgres/src/main/resources/META-INF/spring/mailbox-jpa.xml
+++ /dev/null
@@ -1,109 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one
-  or more contributor license agreements.  See the NOTICE file
-  distributed with this work for additional information
-  regarding copyright ownership.  The ASF licenses this file
-  to you under the Apache License, Version 2.0 (the
-  "License"); you may not use this file except in compliance
-  with the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing,
-  software distributed under the License is distributed on an
-  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-  KIND, either express or implied.  See the License for the
-  specific language governing permissions and limitations
-  under the License.    
--->
-
-<beans xmlns="http://www.springframework.org/schema/beans" 
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="
-          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
-
-    <!-- 
-      Mailbox JPA
-     -->
-
-    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
-
-    <bean id="jpa-mailboxIdFactory" class="org.apache.james.mailbox.postgres.JPAId.Factory" />
-
-    <bean id="jpa-mailboxmanager" class="org.apache.james.mailbox.postgres.openjpa.OpenJPAMailboxManager">
-        <constructor-arg index="0" ref="jpa-sessionMapperFactory"/>
-        <constructor-arg index="1" ref="sessionProvider"/>
-        <constructor-arg index="2" ref="messageParser"/>
-        <constructor-arg index="3" ref="messageIdFactory" />
-        <constructor-arg index="4" ref="event-bus" />
-        <constructor-arg index="5" ref="storeMailboxAnnotationManager" />
-        <constructor-arg index="6" ref="storeRightManager" />
-        <constructor-arg index="7" ref="quotaComponents" />
-        <constructor-arg index="8" ref="indexer" />
-        <constructor-arg index="9" ref="threadIdGuessingAlgorithm" />
-        <constructor-arg index="10" ref="clock" />
-    </bean>
-
-    <bean id="threadIdGuessingAlgorithm" class="org.apache.james.mailbox.store.mail.NaiveThreadIdGuessingAlgorithm" />
-    <bean id="clock" class="java.time.Clock" factory-method="systemUTC" />
-
-    <bean id ="jpa-subscriptionManager" class="org.apache.james.mailbox.store.StoreSubscriptionManager">
-        <constructor-arg index="0" ref="jpa-sessionMapperFactory"/>
-        <constructor-arg index="1" ref="jpa-sessionMapperFactory"/>
-        <constructor-arg index="2" ref="event-bus"/>
-    </bean>
-    <bean id="jpa-sessionMapperFactory" class="org.apache.james.mailbox.postgres.PostgresMailboxSessionMapperFactory">
-        <constructor-arg index="0" ref="entityManagerFactory"/>
-        <constructor-arg index="1" ref="jpa-uidProvider"/>
-        <constructor-arg index="2" ref="jpa-modSeqProvider"/>
-        <constructor-arg index="3" ref="jpa-configuration"/>
-    </bean>
-    <bean id="jpa-uidProvider" class="org.apache.james.mailbox.postgres.mail.JPAUidProvider">
-        <constructor-arg index="0" ref="entityManagerFactory"/>
-    </bean>
-    <bean id="jpa-modSeqProvider" class="org.apache.james.mailbox.postgres.mail.JPAModSeqProvider">
-        <constructor-arg index="0" ref="entityManagerFactory"/>
-    </bean>
-
-    <!-- 
-       Database DataSource
-    -->
-          
-    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
-        <property name="ignoreUnresolvablePlaceholders" value="true"/>
-        <property name ="location" value="classpath:james-database.properties"/>
-    </bean>
-    <bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
-        <property name="driverClassName" value="${database.driverClassName}" />
-        <property name="url" value="${database.url}" />
-        <property name="username" value="${database.username}" />
-        <property name="password" value="${database.password}" />
-        <property name="testOnBorrow" value="${datasource.testOnBorrow:false}" />
-        <property name="validationQueryTimeout" value="${datasource.validationQueryTimeoutSec:-1}" />
-        <property name="validationQuery" value="${datasource.validationQuery:#{null}}" />
-    </bean>
-    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
-        <property name="dataSource" ref="datasource"/>
-        <property name="jpaVendorAdapter" ref="vendorAdapter"/>
-        <property name="persistenceUnitName" value="James"/>
-    </bean>
-    <bean id="vendorAdapter" class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
-        <property name="database" value="${vendorAdapter.database}"/>
-        <!-- set this to true for debugging purposes -->
-        <property name="showSql" value="false"/>
-    </bean>
-
-    <bean id="jpa-per-user-max-quota-dao" class="org.apache.james.mailbox.postgres.quota.JPAPerUserMaxQuotaDAO">
-        <constructor-arg index="0" ref="entityManagerFactory"/>
-    </bean>
-
-    <bean id="jpaMaxQuotaManager" class="org.apache.james.mailbox.postgres.quota.JPAPerUserMaxQuotaManager">
-        <constructor-arg index="0" ref="entityManagerFactory"/>
-        <constructor-arg index="1" ref="jpa-per-user-max-quota-dao"/>
-    </bean>
-    <bean id="jpaCurrentQuotaManager" class="org.apache.james.mailbox.postgres.quota.JpaCurrentQuotaManager">
-        <constructor-arg index="0" ref="entityManagerFactory"/>
-    </bean>
-    <bean id="jpa-configuration" class="org.apache.james.backends.jpa.JPAConfiguration"/>
-</beans>


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


(james-project) 09/11: JAMES-2586 Document (link) varchar underlying maximum lengths

Posted by rc...@apache.org.
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 2cfbef2089a148f4280427b4df2ca3fd788ebfa1
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Fri Nov 10 11:27:57 2023 +0100

    JAMES-2586 Document (link) varchar underlying maximum lengths
---
 .../james/mailbox/postgres/user/PostgresSubscriptionModule.java    | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionModule.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionModule.java
index 54ce1cc49d..3f07843eab 100644
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionModule.java
+++ b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionModule.java
@@ -29,8 +29,13 @@ import org.jooq.impl.DSL;
 import org.jooq.impl.SQLDataType;
 
 public interface PostgresSubscriptionModule {
-
+    /**
+     * See {@link MailboxManager.MAX_MAILBOX_NAME_LENGTH}
+     */
     Field<String> MAILBOX = DSL.field("mailbox", SQLDataType.VARCHAR(255).notNull());
+    /**
+     * See {@link Username.MAXIMUM_MAIL_ADDRESS_LENGTH}
+     */
     Field<String> USER = DSL.field("user_name", SQLDataType.VARCHAR(255).notNull());
     Table<Record> TABLE_NAME = DSL.table("subscription");
     PostgresTable TABLE = PostgresTable.name(TABLE_NAME.getName())


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


(james-project) 11/11: JAMES-2586 Small codestyle refactorings

Posted by rc...@apache.org.
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 753e8f6d3a914b5c25328bacaff9010b7b195059
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Fri Nov 10 19:46:40 2023 +0100

    JAMES-2586 Small codestyle refactorings
---
 .../backends/postgres/PostgresConfiguration.java   | 62 +++++++++++-----------
 .../james/backends/postgres/PostgresTable.java     | 24 ++++-----
 .../backends/postgres/PostgresTableManager.java    | 51 ++++++++++--------
 .../postgres/PostgresConfigurationTest.java        |  6 +--
 .../james/backends/postgres/PostgresExtension.java |  4 +-
 .../backends/postgres/PostgresExtensionTest.java   |  4 +-
 .../postgres/PostgresTableManagerTest.java         | 24 ++++-----
 .../postgres/user/PostgresSubscriptionModule.java  |  2 +-
 8 files changed, 90 insertions(+), 87 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 73dbf36211..7ffeb8be40 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
@@ -61,7 +61,7 @@ public class PostgresConfiguration {
         private Optional<String> url = Optional.empty();
         private Optional<String> databaseName = Optional.empty();
         private Optional<String> databaseSchema = Optional.empty();
-        private Optional<Boolean> rlsEnabled = Optional.empty();
+        private Optional<Boolean> rowLevelSecurityEnabled = Optional.empty();
 
         public Builder url(String url) {
             this.url = Optional.of(url);
@@ -88,13 +88,13 @@ public class PostgresConfiguration {
             return this;
         }
 
-        public Builder rlsEnabled(boolean rlsEnabled) {
-            this.rlsEnabled = Optional.of(rlsEnabled);
+        public Builder rowLevelSecurityEnabled(boolean rlsEnabled) {
+            this.rowLevelSecurityEnabled = Optional.of(rlsEnabled);
             return this;
         }
 
-        public Builder rlsEnabled() {
-            this.rlsEnabled = Optional.of(true);
+        public Builder rowLevelSecurityEnabled() {
+            this.rowLevelSecurityEnabled = Optional.of(true);
             return this;
         }
 
@@ -106,7 +106,7 @@ public class PostgresConfiguration {
                 parseCredential(postgresURI),
                 databaseName.orElse(DATABASE_NAME_DEFAULT_VALUE),
                 databaseSchema.orElse(DATABASE_SCHEMA_DEFAULT_VALUE),
-                rlsEnabled.orElse(false));
+                rowLevelSecurityEnabled.orElse(false));
         }
 
         private Credential parseCredential(URI postgresURI) {
@@ -140,7 +140,7 @@ public class PostgresConfiguration {
             .url(propertiesConfiguration.getString(URL, null))
             .databaseName(Optional.ofNullable(propertiesConfiguration.getString(DATABASE_NAME)))
             .databaseSchema(Optional.ofNullable(propertiesConfiguration.getString(DATABASE_SCHEMA)))
-            .rlsEnabled(propertiesConfiguration.getBoolean(RLS_ENABLED, false))
+            .rowLevelSecurityEnabled(propertiesConfiguration.getBoolean(RLS_ENABLED, false))
             .build();
     }
 
@@ -148,33 +148,14 @@ public class PostgresConfiguration {
     private final Credential credential;
     private final String databaseName;
     private final String databaseSchema;
-    private final boolean rlsEnabled;
+    private final boolean rowLevelSecurityEnabled;
 
-    private PostgresConfiguration(URI uri, Credential credential, String databaseName, String databaseSchema, boolean rlsEnabled) {
+    private PostgresConfiguration(URI uri, Credential credential, String databaseName, String databaseSchema, boolean rowLevelSecurityEnabled) {
         this.uri = uri;
         this.credential = credential;
         this.databaseName = databaseName;
         this.databaseSchema = databaseSchema;
-        this.rlsEnabled = rlsEnabled;
-    }
-
-    @Override
-    public final boolean equals(Object o) {
-        if (o instanceof PostgresConfiguration) {
-            PostgresConfiguration that = (PostgresConfiguration) o;
-
-            return Objects.equals(this.rlsEnabled, that.rlsEnabled)
-                && Objects.equals(this.uri, that.uri)
-                && Objects.equals(this.credential, that.credential)
-                && Objects.equals(this.databaseName, that.databaseName)
-                && Objects.equals(this.databaseSchema, that.databaseSchema);
-        }
-        return false;
-    }
-
-    @Override
-    public final int hashCode() {
-        return Objects.hash(uri, credential, databaseName, databaseSchema, rlsEnabled);
+        this.rowLevelSecurityEnabled = rowLevelSecurityEnabled;
     }
 
     public URI getUri() {
@@ -193,7 +174,26 @@ public class PostgresConfiguration {
         return databaseSchema;
     }
 
-    public boolean rlsEnabled() {
-        return rlsEnabled;
+    public boolean rowLevelSecurityEnabled() {
+        return rowLevelSecurityEnabled;
+    }
+
+    @Override
+    public final boolean equals(Object o) {
+        if (o instanceof PostgresConfiguration) {
+            PostgresConfiguration that = (PostgresConfiguration) o;
+
+            return Objects.equals(this.rowLevelSecurityEnabled, that.rowLevelSecurityEnabled)
+                && Objects.equals(this.uri, that.uri)
+                && Objects.equals(this.credential, that.credential)
+                && Objects.equals(this.databaseName, that.databaseName)
+                && Objects.equals(this.databaseSchema, that.databaseSchema);
+        }
+        return false;
+    }
+
+    @Override
+    public final int hashCode() {
+        return Objects.hash(uri, credential, databaseName, databaseSchema, rowLevelSecurityEnabled);
     }
 }
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 1956d3c5e8..933a7810df 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
@@ -27,13 +27,11 @@ import org.jooq.DSLContext;
 import com.google.common.base.Preconditions;
 
 public class PostgresTable {
-
     @FunctionalInterface
     public interface RequireCreateTableStep {
         RequireRowLevelSecurity createTableStep(CreateTableFunction createTableFunction);
     }
 
-
     @FunctionalInterface
     public interface CreateTableFunction {
         DDLQuery createTable(DSLContext dsl, String tableName);
@@ -41,30 +39,30 @@ public class PostgresTable {
 
     @FunctionalInterface
     public interface RequireRowLevelSecurity {
-        PostgresTable enableRowLevelSecurity(boolean enableRowLevelSecurity);
+        PostgresTable supportsRowLevelSecurity(boolean rowLevelSecurityEnabled);
 
-        default PostgresTable noRLS() {
-            return enableRowLevelSecurity(false);
+        default PostgresTable disableRowLevelSecurity() {
+            return supportsRowLevelSecurity(false);
         }
 
-        default PostgresTable enableRowLevelSecurity() {
-            return enableRowLevelSecurity(true);
+        default PostgresTable supportsRowLevelSecurity() {
+            return supportsRowLevelSecurity(true);
         }
     }
 
     public static RequireCreateTableStep name(String tableName) {
         Preconditions.checkNotNull(tableName);
 
-        return createTableFunction -> enableRowLevelSecurity -> new PostgresTable(tableName, enableRowLevelSecurity, dsl -> createTableFunction.createTable(dsl, tableName));
+        return createTableFunction -> supportsRowLevelSecurity -> new PostgresTable(tableName, supportsRowLevelSecurity, dsl -> createTableFunction.createTable(dsl, tableName));
     }
 
     private final String name;
-    private final boolean enableRowLevelSecurity;
+    private final boolean supportsRowLevelSecurity;
     private final Function<DSLContext, DDLQuery> createTableStepFunction;
 
-    private PostgresTable(String name, boolean enableRowLevelSecurity, Function<DSLContext, DDLQuery> createTableStepFunction) {
+    private PostgresTable(String name, boolean supportsRowLevelSecurity, Function<DSLContext, DDLQuery> createTableStepFunction) {
         this.name = name;
-        this.enableRowLevelSecurity = enableRowLevelSecurity;
+        this.supportsRowLevelSecurity = supportsRowLevelSecurity;
         this.createTableStepFunction = createTableStepFunction;
     }
 
@@ -77,7 +75,7 @@ public class PostgresTable {
         return createTableStepFunction;
     }
 
-    public boolean isEnableRowLevelSecurity() {
-        return enableRowLevelSecurity;
+    public boolean supportsRowLevelSecurity() {
+        return supportsRowLevelSecurity;
     }
 }
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 78eb5170f6..eaa4aa7994 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
@@ -40,7 +40,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 rlsEnabled;
+    private final boolean rowLevelSecurityEnabled;
 
     @Inject
     public PostgresTableManager(JamesPostgresConnectionFactory postgresConnectionFactory,
@@ -48,34 +48,36 @@ public class PostgresTableManager implements Startable {
                                 PostgresConfiguration postgresConfiguration) {
         this.postgresExecutor = new PostgresExecutor(postgresConnectionFactory.getConnection(Optional.empty()));
         this.module = module;
-        this.rlsEnabled = postgresConfiguration.rlsEnabled();
+        this.rowLevelSecurityEnabled = postgresConfiguration.rowLevelSecurityEnabled();
     }
 
     @VisibleForTesting
-    public PostgresTableManager(PostgresExecutor postgresExecutor, PostgresModule module, boolean rlsEnabled) {
+    public PostgresTableManager(PostgresExecutor postgresExecutor, PostgresModule module, boolean rowLevelSecurityEnabled) {
         this.postgresExecutor = postgresExecutor;
         this.module = module;
-        this.rlsEnabled = rlsEnabled;
+        this.rowLevelSecurityEnabled = rowLevelSecurityEnabled;
     }
 
     public Mono<Void> initializeTables() {
         return postgresExecutor.dslContext()
             .flatMap(dsl -> Flux.fromIterable(module.tables())
                 .flatMap(table -> Mono.from(table.getCreateTableStepFunction().apply(dsl))
-                    .then(alterTableEnableRLSIfNeed(table))
+                    .then(alterTableIfNeeded(table))
                     .doOnSuccess(any -> LOGGER.info("Table {} created", table.getName()))
-                    .onErrorResume(DataAccessException.class, exception -> {
-                        if (exception.getMessage().contains(String.format("\"%s\" already exists", table.getName()))) {
-                            return Mono.empty();
-                        }
-                        return Mono.error(exception);
-                    })
-                    .doOnError(e -> LOGGER.error("Error while creating table {}", table.getName(), e)))
+                    .onErrorResume(exception -> handleTableCreationException(table, exception)))
                 .then());
     }
 
-    private Mono<Void> alterTableEnableRLSIfNeed(PostgresTable table) {
-        if (rlsEnabled && table.isEnableRowLevelSecurity()) {
+    private Mono<Void> handleTableCreationException(PostgresTable table, Throwable e) {
+        if (e instanceof DataAccessException && e.getMessage().contains(String.format("\"%s\" already exists", table.getName()))) {
+            return Mono.empty();
+        }
+        LOGGER.error("Error while creating table {}", table.getName(), e);
+        return Mono.error(e);
+    }
+
+    private Mono<Void> alterTableIfNeeded(PostgresTable table) {
+        if (rowLevelSecurityEnabled && table.supportsRowLevelSecurity()) {
             return alterTableEnableRLS(table);
         }
         return Mono.empty();
@@ -83,12 +85,13 @@ public class PostgresTableManager implements Startable {
 
     public Mono<Void> alterTableEnableRLS(PostgresTable table) {
         return postgresExecutor.connection()
-            .flatMapMany(con -> con.createStatement(getAlterRLSStatement(table.getName())).execute())
+            .flatMapMany(connection -> connection.createStatement(rowLevelSecurityAlterStatement(table.getName()))
+                .execute())
             .flatMap(Result::getRowsUpdated)
             .then();
     }
 
-    private String getAlterRLSStatement(String tableName) {
+    private String rowLevelSecurityAlterStatement(String tableName) {
         return "SET app.current_domain = ''; ALTER TABLE " + tableName + " ADD DOMAIN varchar(255) not null DEFAULT current_setting('app.current_domain')::text;" +
             "ALTER TABLE " + tableName + " ENABLE ROW LEVEL SECURITY; " +
             "CREATE POLICY DOMAIN_" + tableName + "_POLICY ON " + tableName + " USING (DOMAIN = current_setting('app.current_domain')::text);";
@@ -108,13 +111,15 @@ public class PostgresTableManager implements Startable {
             .flatMap(dsl -> Flux.fromIterable(module.tableIndexes())
                 .concatMap(index -> Mono.from(index.getCreateIndexStepFunction().apply(dsl))
                     .doOnSuccess(any -> LOGGER.info("Index {} created", index.getName()))
-                    .onErrorResume(DataAccessException.class, exception -> {
-                        if (exception.getMessage().contains(String.format("\"%s\" already exists", index.getName()))) {
-                            return Mono.empty();
-                        }
-                        return Mono.error(exception);
-                    })
-                    .doOnError(e -> LOGGER.error("Error while creating index {}", index.getName(), e)))
+                    .onErrorResume(e -> handleIndexCreationException(index, e)))
                 .then());
     }
+
+    private Mono<? extends Integer> handleIndexCreationException(PostgresIndex index, Throwable e) {
+        if (e instanceof DataAccessException && e.getMessage().contains(String.format("\"%s\" already exists", index.getName()))) {
+            return Mono.empty();
+        }
+        LOGGER.error("Error while creating index {}", index.getName(), e);
+        return Mono.error(e);
+    }
 }
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 b324ec527a..248eb0dd66 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
@@ -71,7 +71,7 @@ class PostgresConfigurationTest {
             .url("postgresql://username:password@postgreshost:5672")
             .build();
 
-        assertThat(configuration.rlsEnabled()).isFalse();
+        assertThat(configuration.rowLevelSecurityEnabled()).isFalse();
     }
 
     @Test
@@ -96,13 +96,13 @@ class PostgresConfigurationTest {
     void shouldReturnCorrespondingProperties() {
         PostgresConfiguration configuration = PostgresConfiguration.builder()
             .url("postgresql://username:password@postgreshost:5672")
-            .rlsEnabled()
+            .rowLevelSecurityEnabled()
             .databaseName("databaseName")
             .databaseSchema("databaseSchema")
             .build();
 
         SoftAssertions.assertSoftly(softly -> {
-            softly.assertThat(configuration.rlsEnabled()).isEqualTo(true);
+            softly.assertThat(configuration.rowLevelSecurityEnabled()).isEqualTo(true);
             softly.assertThat(configuration.getDatabaseName()).isEqualTo("databaseName");
             softly.assertThat(configuration.getDatabaseSchema()).isEqualTo("databaseSchema");
         });
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 682fc49696..a1ae9b9aba 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
@@ -80,7 +80,7 @@ public class PostgresExtension implements GuiceModuleTestExtension {
                 .toString())
             .databaseName(PostgresFixture.Database.DB_NAME)
             .databaseSchema(PostgresFixture.Database.SCHEMA)
-            .rlsEnabled(rlsEnabled)
+            .rowLevelSecurityEnabled(rlsEnabled)
             .build();
 
         connectionFactory = new PostgresqlConnectionFactory(PostgresqlConnectionConfiguration.builder()
@@ -149,7 +149,7 @@ public class PostgresExtension implements GuiceModuleTestExtension {
     }
 
     private void initTablesAndIndexes() {
-        PostgresTableManager postgresTableManager = new PostgresTableManager(postgresExecutor, postgresModule, postgresConfiguration.rlsEnabled());
+        PostgresTableManager postgresTableManager = new PostgresTableManager(postgresExecutor, postgresModule, postgresConfiguration.rowLevelSecurityEnabled());
         postgresTableManager.initializeTables().block();
         postgresTableManager.initializeTableIndexes().block();
     }
diff --git a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtensionTest.java b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtensionTest.java
index 406ba4b6bc..ca3a641ead 100644
--- a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtensionTest.java
+++ b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtensionTest.java
@@ -38,7 +38,7 @@ class PostgresExtensionTest {
             .column("column1", SQLDataType.UUID.notNull())
             .column("column2", SQLDataType.INTEGER)
             .column("column3", SQLDataType.VARCHAR(255).notNull()))
-        .noRLS();
+        .disableRowLevelSecurity();
 
     static PostgresIndex INDEX_1 = PostgresIndex.name("index1")
         .createIndexStep((dslContext, indexName) -> dslContext.createIndex(indexName)
@@ -47,7 +47,7 @@ class PostgresExtensionTest {
     static PostgresTable TABLE_2 = PostgresTable.name("table2")
         .createTableStep((dslContext, tableName) -> dslContext.createTable(tableName)
             .column("column1", SQLDataType.INTEGER))
-        .noRLS();
+        .disableRowLevelSecurity();
 
     static PostgresIndex INDEX_2 = PostgresIndex.name("index2")
         .createIndexStep((dslContext, indexName) -> dslContext.createIndex(indexName)
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 c7d98cb915..ac5d73c2d7 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
@@ -53,7 +53,7 @@ class PostgresTableManagerTest {
                 .column("colum1", SQLDataType.UUID.notNull())
                 .column("colum2", SQLDataType.INTEGER)
                 .column("colum3", SQLDataType.VARCHAR(255).notNull()))
-            .noRLS();
+            .disableRowLevelSecurity();
 
         PostgresModule module = PostgresModule.table(table);
 
@@ -75,12 +75,12 @@ class PostgresTableManagerTest {
 
         PostgresTable table1 = PostgresTable.name(tableName1)
             .createTableStep((dsl, tbn) -> dsl.createTable(tbn)
-                .column("columA", SQLDataType.UUID.notNull())).noRLS();
+                .column("columA", SQLDataType.UUID.notNull())).disableRowLevelSecurity();
 
         String tableName2 = "tableName2";
         PostgresTable table2 = PostgresTable.name(tableName2)
             .createTableStep((dsl, tbn) -> dsl.createTable(tbn)
-                .column("columB", SQLDataType.INTEGER)).noRLS();
+                .column("columB", SQLDataType.INTEGER)).disableRowLevelSecurity();
 
         PostgresTableManager testee = tableManagerFactory.apply(PostgresModule.table(table1, table2));
 
@@ -101,7 +101,7 @@ class PostgresTableManagerTest {
 
         PostgresTable table1 = PostgresTable.name(tableName1)
             .createTableStep((dsl, tbn) -> dsl.createTable(tbn)
-                .column("columA", SQLDataType.UUID.notNull())).noRLS();
+                .column("columA", SQLDataType.UUID.notNull())).disableRowLevelSecurity();
 
         PostgresTableManager testee = tableManagerFactory.apply(PostgresModule.table(table1));
 
@@ -117,7 +117,7 @@ class PostgresTableManagerTest {
         String tableName1 = "tableName1";
         PostgresTable table1 = PostgresTable.name(tableName1)
             .createTableStep((dsl, tbn) -> dsl.createTable(tbn)
-                .column("columA", SQLDataType.UUID.notNull())).noRLS();
+                .column("columA", SQLDataType.UUID.notNull())).disableRowLevelSecurity();
 
         tableManagerFactory.apply(PostgresModule.table(table1))
             .initializeTables()
@@ -125,7 +125,7 @@ class PostgresTableManagerTest {
 
         PostgresTable table1Changed = PostgresTable.name(tableName1)
             .createTableStep((dsl, tbn) -> dsl.createTable(tbn)
-                .column("columB", SQLDataType.INTEGER)).noRLS();
+                .column("columB", SQLDataType.INTEGER)).disableRowLevelSecurity();
 
         tableManagerFactory.apply(PostgresModule.table(table1Changed))
             .initializeTables()
@@ -145,7 +145,7 @@ class PostgresTableManagerTest {
                 .column("colum1", SQLDataType.UUID.notNull())
                 .column("colum2", SQLDataType.INTEGER)
                 .column("colum3", SQLDataType.VARCHAR(255).notNull()))
-            .noRLS();
+            .disableRowLevelSecurity();
 
         String indexName = "idx_test_1";
         PostgresIndex index = PostgresIndex.name(indexName)
@@ -178,7 +178,7 @@ class PostgresTableManagerTest {
                 .column("colum1", SQLDataType.UUID.notNull())
                 .column("colum2", SQLDataType.INTEGER)
                 .column("colum3", SQLDataType.VARCHAR(255).notNull()))
-            .noRLS();
+            .disableRowLevelSecurity();
 
         String indexName1 = "idx_test_1";
         PostgresIndex index1 = PostgresIndex.name(indexName1)
@@ -216,7 +216,7 @@ class PostgresTableManagerTest {
                 .column("colum1", SQLDataType.UUID.notNull())
                 .column("colum2", SQLDataType.INTEGER)
                 .column("colum3", SQLDataType.VARCHAR(255).notNull()))
-            .noRLS();
+            .disableRowLevelSecurity();
 
         String indexName = "idx_test_1";
         PostgresIndex index = PostgresIndex.name(indexName)
@@ -244,7 +244,7 @@ class PostgresTableManagerTest {
         String tableName1 = "tbn1";
         PostgresTable table1 = PostgresTable.name(tableName1)
             .createTableStep((dsl, tbn) -> dsl.createTable(tbn)
-                .column("column1", SQLDataType.INTEGER.notNull())).noRLS();
+                .column("column1", SQLDataType.INTEGER.notNull())).disableRowLevelSecurity();
 
         PostgresTableManager testee = tableManagerFactory.apply(PostgresModule.table(table1));
         testee.initializeTables()
@@ -286,7 +286,7 @@ class PostgresTableManagerTest {
             .createTableStep((dsl, tbn) -> dsl.createTable(tbn)
                 .column("clm1", SQLDataType.UUID.notNull())
                 .column("clm2", SQLDataType.VARCHAR(255).notNull()))
-            .enableRowLevelSecurity();
+            .supportsRowLevelSecurity();
 
         PostgresModule module = PostgresModule.table(table);
 
@@ -326,7 +326,7 @@ class PostgresTableManagerTest {
             .createTableStep((dsl, tbn) -> dsl.createTable(tbn)
                 .column("clm1", SQLDataType.UUID.notNull())
                 .column("clm2", SQLDataType.VARCHAR(255).notNull()))
-            .enableRowLevelSecurity();
+            .supportsRowLevelSecurity();
 
         PostgresModule module = PostgresModule.table(table);
         boolean disabledRLS = false;
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionModule.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionModule.java
index 3f07843eab..68c8eca1d0 100644
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionModule.java
+++ b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionModule.java
@@ -43,7 +43,7 @@ public interface PostgresSubscriptionModule {
             .column(MAILBOX)
             .column(USER)
             .constraint(DSL.unique(MAILBOX, USER))))
-        .enableRowLevelSecurity();
+        .supportsRowLevelSecurity();
     PostgresIndex INDEX = PostgresIndex.name("subscription_user_index")
         .createIndexStep((dsl, indexName) -> dsl.createIndex(indexName)
             .on(TABLE_NAME, USER));


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


(james-project) 03/11: JAMES-2586 Merge PostgresSubscriptionTable and PostgresSubscriptionModule

Posted by rc...@apache.org.
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 84ec3363b537736e5cf2676f054d81f7c42ad3d4
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Fri Nov 10 10:44:59 2023 +0100

    JAMES-2586 Merge PostgresSubscriptionTable and PostgresSubscriptionModule
---
 .../postgres/user/PostgresSubscriptionDAO.java     |  6 ++--
 .../postgres/user/PostgresSubscriptionModule.java  | 12 +++++---
 .../postgres/user/PostgresSubscriptionTable.java   | 34 ----------------------
 3 files changed, 11 insertions(+), 41 deletions(-)

diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionDAO.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionDAO.java
index 9bce0047d0..91b4baa2fe 100644
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionDAO.java
+++ b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionDAO.java
@@ -19,9 +19,9 @@
 
 package org.apache.james.mailbox.postgres.user;
 
-import static org.apache.james.mailbox.postgres.user.PostgresSubscriptionTable.MAILBOX;
-import static org.apache.james.mailbox.postgres.user.PostgresSubscriptionTable.TABLE_NAME;
-import static org.apache.james.mailbox.postgres.user.PostgresSubscriptionTable.USER;
+import static org.apache.james.mailbox.postgres.user.PostgresSubscriptionModule.MAILBOX;
+import static org.apache.james.mailbox.postgres.user.PostgresSubscriptionModule.TABLE_NAME;
+import static org.apache.james.mailbox.postgres.user.PostgresSubscriptionModule.USER;
 
 import org.apache.james.backends.postgres.utils.PostgresExecutor;
 
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionModule.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionModule.java
index 11ea9a2f3e..54ce1cc49d 100644
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionModule.java
+++ b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionModule.java
@@ -19,16 +19,20 @@
 
 package org.apache.james.mailbox.postgres.user;
 
-import static org.apache.james.mailbox.postgres.user.PostgresSubscriptionTable.MAILBOX;
-import static org.apache.james.mailbox.postgres.user.PostgresSubscriptionTable.TABLE_NAME;
-import static org.apache.james.mailbox.postgres.user.PostgresSubscriptionTable.USER;
-
 import org.apache.james.backends.postgres.PostgresIndex;
 import org.apache.james.backends.postgres.PostgresModule;
 import org.apache.james.backends.postgres.PostgresTable;
+import org.jooq.Field;
+import org.jooq.Record;
+import org.jooq.Table;
 import org.jooq.impl.DSL;
+import org.jooq.impl.SQLDataType;
 
 public interface PostgresSubscriptionModule {
+
+    Field<String> MAILBOX = DSL.field("mailbox", SQLDataType.VARCHAR(255).notNull());
+    Field<String> USER = DSL.field("user_name", SQLDataType.VARCHAR(255).notNull());
+    Table<Record> TABLE_NAME = DSL.table("subscription");
     PostgresTable TABLE = PostgresTable.name(TABLE_NAME.getName())
         .createTableStep(((dsl, tableName) -> dsl.createTable(tableName)
             .column(MAILBOX)
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionTable.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionTable.java
deleted file mode 100644
index ad703e4d26..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionTable.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mailbox.postgres.user;
-
-import org.jooq.Field;
-import org.jooq.Record;
-import org.jooq.Table;
-import org.jooq.impl.DSL;
-import org.jooq.impl.SQLDataType;
-
-public interface PostgresSubscriptionTable {
-
-    Field<String> MAILBOX = DSL.field("mailbox", SQLDataType.VARCHAR(255).notNull());
-    Field<String> USER = DSL.field("user_name", SQLDataType.VARCHAR(255).notNull());
-    Table<Record> TABLE_NAME = DSL.table("subscription");
-
-}


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


(james-project) 06/11: JAMES-2586 Drop unused class: EncryptDecryptHelper

Posted by rc...@apache.org.
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 9a75315d5e9008c5734098745a7f18c17cc75e56
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Fri Nov 10 10:53:24 2023 +0100

    JAMES-2586 Drop unused class: EncryptDecryptHelper
---
 .../mail/model/openjpa/EncryptDecryptHelper.java   | 66 ----------------------
 1 file changed, 66 deletions(-)

diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/openjpa/EncryptDecryptHelper.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/openjpa/EncryptDecryptHelper.java
deleted file mode 100644
index ef8eb9c403..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/openjpa/EncryptDecryptHelper.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-package org.apache.james.mailbox.postgres.mail.model.openjpa;
-
-import org.jasypt.encryption.pbe.StandardPBEByteEncryptor;
-
-/**
- * Helper class for encrypt and de-crypt data
- * 
- *
- */
-public class EncryptDecryptHelper {    
-
-    // Use one static instance as it is thread safe
-    private static final StandardPBEByteEncryptor encryptor = new StandardPBEByteEncryptor();
-    
-    
-    /**
-     * Set the password for encrypt / de-crypt. This MUST be done before
-     * the usage of {@link #getDecrypted(byte[])} and {@link #getEncrypted(byte[])}.
-     * 
-     * So to be safe its the best to call this in a constructor
-     * 
-     * @param pass
-     */
-    public static void init(String pass) {
-        encryptor.setPassword(pass);
-    }
-
-    /**
-     * Encrypt the given array and return the encrypted one
-     * 
-     * @param array
-     * @return enc-array
-     */
-    public static byte[] getEncrypted(byte[] array) {
-        return encryptor.encrypt(array);
-    }
-
-    /**
-     * Decrypt the given array and return the de-crypted one
-     * 
-     * @param array
-     * @return dec-array
-     */
-    public static byte[] getDecrypted(byte[] array) {
-        return encryptor.decrypt(array);
-    }
-
-}


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


(james-project) 08/11: JAMES-2586 Implement (failing) tests for Row Level Security applied on Subscriptions

Posted by rc...@apache.org.
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 553d0f0c5ecf6bac0976bf1ee0777cbda10fc734
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Fri Nov 10 11:13:30 2023 +0100

    JAMES-2586 Implement (failing) tests for Row Level Security applied on Subscriptions
---
 ...gresSubscriptionMapperRowLevelSecurityTest.java | 86 ++++++++++++++++++++++
 1 file changed, 86 insertions(+)

diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperRowLevelSecurityTest.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperRowLevelSecurityTest.java
new file mode 100644
index 0000000000..7f6618933c
--- /dev/null
+++ b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperRowLevelSecurityTest.java
@@ -0,0 +1,86 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.postgres.user;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.backends.postgres.PostgresExtension;
+import org.apache.james.backends.postgres.utils.JamesPostgresConnectionFactory;
+import org.apache.james.backends.postgres.utils.PostgresExecutor;
+import org.apache.james.backends.postgres.utils.SimpleJamesPostgresConnectionFactory;
+import org.apache.james.core.Username;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MailboxSessionUtil;
+import org.apache.james.mailbox.exception.SubscriptionException;
+import org.apache.james.mailbox.store.user.SubscriptionMapper;
+import org.apache.james.mailbox.store.user.SubscriptionMapperFactory;
+import org.apache.james.mailbox.store.user.SubscriptionMapperTest;
+import org.apache.james.mailbox.store.user.model.Subscription;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+public class PostgresSubscriptionMapperRowLevelSecurityTest {
+    @RegisterExtension
+    static PostgresExtension postgresExtension = new PostgresExtension(PostgresSubscriptionModule.MODULE, true);
+
+    private SubscriptionMapperFactory subscriptionMapperFactory;
+
+    @BeforeEach
+    public void setUp() {
+        subscriptionMapperFactory = session -> new PostgresSubscriptionMapper(new PostgresSubscriptionDAO(new PostgresExecutor(
+            new SimpleJamesPostgresConnectionFactory(postgresExtension.getConnectionFactory())
+                .getConnection(session.getUser().getDomainPart()))));
+    }
+
+    @Test
+    void subscriptionsCanBeAccessedAtTheDataLevelByMembersOfTheSameDomain() throws Exception {
+        Username username = Username.of("bob@domain1");
+        Username username2 = Username.of("alice@domain1");
+        MailboxSession session = MailboxSessionUtil.create(username);
+        MailboxSession session2 = MailboxSessionUtil.create(username2);
+
+        Subscription subscription = new Subscription(username, "mailbox1");
+        subscriptionMapperFactory.getSubscriptionMapper(session)
+            .save(subscription);
+
+        assertThat(subscriptionMapperFactory.getSubscriptionMapper(session2)
+            .findSubscriptionsForUser(username))
+            .containsOnly(subscription);
+    }
+
+    @Disabled("Row level security for subscriptions is not implemented correctly")
+    @Test
+    void subscriptionsShouldBeIsolatedByDomain() throws Exception {
+        Username username = Username.of("bob@domain1");
+        Username username2 = Username.of("alice@domain2");
+        MailboxSession session = MailboxSessionUtil.create(username);
+        MailboxSession session2 = MailboxSessionUtil.create(username2);
+
+        Subscription subscription = new Subscription(username, "mailbox1");
+        subscriptionMapperFactory.getSubscriptionMapper(session)
+            .save(subscription);
+
+        assertThat(subscriptionMapperFactory.getSubscriptionMapper(session2)
+            .findSubscriptionsForUser(username))
+            .isEmpty();
+    }
+}


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


(james-project) 05/11: JAMES-2586 Drop reporting-site.xml

Posted by rc...@apache.org.
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 d8d18a1709fef40d291d1e90d0c4a77f0ab5e493
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Fri Nov 10 10:50:48 2023 +0100

    JAMES-2586 Drop reporting-site.xml
---
 mailbox/postgres/src/reporting-site/site.xml | 29 ----------------------------
 1 file changed, 29 deletions(-)

diff --git a/mailbox/postgres/src/reporting-site/site.xml b/mailbox/postgres/src/reporting-site/site.xml
deleted file mode 100644
index d919164490..0000000000
--- a/mailbox/postgres/src/reporting-site/site.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
-    Licensed to the Apache Software Foundation (ASF) under one
-    or more contributor license agreements.  See the NOTICE file
-    distributed with this work for additional information
-    regarding copyright ownership.  The ASF licenses this file
-    to you under the Apache License, Version 2.0 (the
-    "License"); you may not use this file except in compliance
-    with the License.  You may obtain a copy of the License at
-    
-    http://www.apache.org/licenses/LICENSE-2.0
-    
-    Unless required by applicable law or agreed to in writing,
-    software distributed under the License is distributed on an
-    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-    KIND, either express or implied.  See the License for the
-    specific language governing permissions and limitations
-    under the License.    
--->
-<project name="${project.name}">
-
-    <body>
-
-        <menu ref="parent" />
-        <menu ref="reports" />
-
-    </body>
-
-</project>


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


(james-project) 02/11: JAMES-2586 Polish code style: PostgresSubscriptionMapper

Posted by rc...@apache.org.
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 690c513e2aa5eced11059dab79b7605a3961e21b
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Fri Nov 10 10:38:05 2023 +0100

    JAMES-2586 Polish code style: PostgresSubscriptionMapper
---
 .../james/mailbox/postgres/user/PostgresSubscriptionMapper.java    | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapper.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapper.java
index 1b3182a66e..e9d06e1660 100644
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapper.java
+++ b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapper.java
@@ -22,7 +22,6 @@ package org.apache.james.mailbox.postgres.user;
 import java.util.List;
 
 import org.apache.james.core.Username;
-import org.apache.james.mailbox.exception.SubscriptionException;
 import org.apache.james.mailbox.store.user.SubscriptionMapper;
 import org.apache.james.mailbox.store.user.model.Subscription;
 
@@ -38,17 +37,17 @@ public class PostgresSubscriptionMapper implements SubscriptionMapper {
     }
 
     @Override
-    public void save(Subscription subscription) throws SubscriptionException {
+    public void save(Subscription subscription) {
         saveReactive(subscription).block();
     }
 
     @Override
-    public List<Subscription> findSubscriptionsForUser(Username user) throws SubscriptionException {
+    public List<Subscription> findSubscriptionsForUser(Username user) {
         return findSubscriptionsForUserReactive(user).collectList().block();
     }
 
     @Override
-    public void delete(Subscription subscription) throws SubscriptionException {
+    public void delete(Subscription subscription) {
         deleteReactive(subscription).block();
     }
 


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


(james-project) 10/11: JAMES-2586 PostgresExtension: favor factory methods to constructor

Posted by rc...@apache.org.
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 e74e0f6eeeab19b7f1c12bf7a7d7883709b7ce34
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Fri Nov 10 13:40:58 2023 +0100

    JAMES-2586 PostgresExtension: favor factory methods to constructor
---
 .../postgres/ConnectionThreadSafetyTest.java       |  2 +-
 .../james/backends/postgres/PostgresExtension.java | 28 ++++++++++++----------
 .../backends/postgres/PostgresExtensionTest.java   |  2 +-
 .../postgres/PostgresTableManagerTest.java         |  2 +-
 .../SimpleJamesPostgresConnectionFactoryTest.java  |  2 +-
 .../mailbox/postgres/JPAMailboxManagerTest.java    |  2 +-
 .../postgres/JpaMailboxManagerStressTest.java      |  2 +-
 .../postgres/PostgresSubscriptionManagerTest.java  |  2 +-
 .../task/JPARecomputeCurrentQuotasServiceTest.java |  2 +-
 ...gresSubscriptionMapperRowLevelSecurityTest.java |  2 +-
 .../user/PostgresSubscriptionMapperTest.java       |  2 +-
 .../apache/james/JamesCapabilitiesServerTest.java  |  2 +-
 .../org/apache/james/PostgresJamesServerTest.java  |  2 +-
 ...WithAuthenticatedDatabaseSqlValidationTest.java |  2 +-
 ...atabaseAuthenticaticationSqlValidationTest.java |  2 +-
 .../james/PostgresWithLDAPJamesServerTest.java     |  2 +-
 16 files changed, 30 insertions(+), 28 deletions(-)

diff --git a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/ConnectionThreadSafetyTest.java b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/ConnectionThreadSafetyTest.java
index 20eedcee4d..80b927a5a2 100644
--- a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/ConnectionThreadSafetyTest.java
+++ b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/ConnectionThreadSafetyTest.java
@@ -57,7 +57,7 @@ public class ConnectionThreadSafetyTest {
         ");";
 
     @RegisterExtension
-    static PostgresExtension postgresExtension = new PostgresExtension();
+    static PostgresExtension postgresExtension = PostgresExtension.empty();
 
     private static PostgresqlConnection postgresqlConnection;
     private static SimpleJamesPostgresConnectionFactory jamesPostgresConnectionFactory;
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 086080b84f..682fc49696 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
@@ -36,29 +36,31 @@ import io.r2dbc.spi.ConnectionFactory;
 import reactor.core.publisher.Mono;
 
 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);
+    }
+
+    public static PostgresExtension withoutRowLevelSecurity(PostgresModule module) {
+        return new PostgresExtension(module, !ROW_LEVEL_SECURITY_ENABLED);
+    }
+
+    public static PostgresExtension empty() {
+        return withoutRowLevelSecurity(PostgresModule.EMPTY_MODULE);
+    }
+
     private final PostgresModule postgresModule;
     private final boolean rlsEnabled;
     private PostgresConfiguration postgresConfiguration;
     private PostgresExecutor postgresExecutor;
     private PostgresqlConnectionFactory connectionFactory;
 
-    public PostgresExtension(PostgresModule postgresModule, boolean rlsEnabled) {
+    private PostgresExtension(PostgresModule postgresModule, boolean rlsEnabled) {
         this.postgresModule = postgresModule;
         this.rlsEnabled = rlsEnabled;
     }
 
-    public PostgresExtension(PostgresModule postgresModule) {
-        this(postgresModule, false);
-    }
-
-    public PostgresExtension(boolean rlsEnabled) {
-        this(PostgresModule.EMPTY_MODULE, rlsEnabled);
-    }
-
-    public PostgresExtension() {
-        this(false);
-    }
-
     @Override
     public void beforeAll(ExtensionContext extensionContext) throws Exception {
         if (!DockerPostgresSingleton.SINGLETON.isRunning()) {
diff --git a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtensionTest.java b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtensionTest.java
index f1593fef21..406ba4b6bc 100644
--- a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtensionTest.java
+++ b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtensionTest.java
@@ -59,7 +59,7 @@ class PostgresExtensionTest {
         .build();
 
     @RegisterExtension
-    static PostgresExtension postgresExtension = new PostgresExtension(POSTGRES_MODULE);
+    static PostgresExtension postgresExtension = PostgresExtension.withoutRowLevelSecurity(POSTGRES_MODULE);
 
     @Test
     void postgresExtensionShouldProvisionTablesAndIndexes() {
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 2805c62930..c7d98cb915 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
@@ -39,7 +39,7 @@ import reactor.core.publisher.Mono;
 class PostgresTableManagerTest {
 
     @RegisterExtension
-    static PostgresExtension postgresExtension = new PostgresExtension();
+    static PostgresExtension postgresExtension = PostgresExtension.empty();
 
     Function<PostgresModule, PostgresTableManager> tableManagerFactory =
         module -> new PostgresTableManager(new PostgresExecutor(postgresExtension.getConnection()), module, true);
diff --git a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/SimpleJamesPostgresConnectionFactoryTest.java b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/SimpleJamesPostgresConnectionFactoryTest.java
index 962599473f..cfe457db34 100644
--- a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/SimpleJamesPostgresConnectionFactoryTest.java
+++ b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/SimpleJamesPostgresConnectionFactoryTest.java
@@ -46,7 +46,7 @@ import reactor.core.publisher.Mono;
 
 public class SimpleJamesPostgresConnectionFactoryTest extends JamesPostgresConnectionFactoryTest {
     @RegisterExtension
-    static PostgresExtension postgresExtension = new PostgresExtension();
+    static PostgresExtension postgresExtension = PostgresExtension.empty();
 
     private PostgresqlConnection postgresqlConnection;
     private SimpleJamesPostgresConnectionFactory jamesPostgresConnectionFactory;
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxManagerTest.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxManagerTest.java
index b6f2db2243..53871f68f8 100644
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxManagerTest.java
+++ b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxManagerTest.java
@@ -43,7 +43,7 @@ class JPAMailboxManagerTest extends MailboxManagerTest<OpenJPAMailboxManager> {
     }
 
     @RegisterExtension
-    static PostgresExtension postgresExtension = new PostgresExtension(PostgresSubscriptionModule.MODULE);
+    static PostgresExtension postgresExtension = PostgresExtension.withoutRowLevelSecurity(PostgresSubscriptionModule.MODULE);
 
     static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES);
     Optional<OpenJPAMailboxManager> openJPAMailboxManager = Optional.empty();
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerStressTest.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerStressTest.java
index 8f2b2b8e52..2abd96da33 100644
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerStressTest.java
+++ b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerStressTest.java
@@ -34,7 +34,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 class JpaMailboxManagerStressTest implements MailboxManagerStressContract<OpenJPAMailboxManager> {
 
     @RegisterExtension
-    static PostgresExtension postgresExtension = new PostgresExtension(PostgresSubscriptionModule.MODULE);
+    static PostgresExtension postgresExtension = PostgresExtension.withoutRowLevelSecurity(PostgresSubscriptionModule.MODULE);
 
     static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES);
     Optional<OpenJPAMailboxManager> openJPAMailboxManager = Optional.empty();
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresSubscriptionManagerTest.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresSubscriptionManagerTest.java
index 83b9074aa9..39343b7b1a 100644
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresSubscriptionManagerTest.java
+++ b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresSubscriptionManagerTest.java
@@ -42,7 +42,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 class PostgresSubscriptionManagerTest implements SubscriptionManagerContract {
 
     @RegisterExtension
-    static PostgresExtension postgresExtension = new PostgresExtension(PostgresSubscriptionModule.MODULE);
+    static PostgresExtension postgresExtension = PostgresExtension.withoutRowLevelSecurity(PostgresSubscriptionModule.MODULE);
 
     static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES);
 
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/task/JPARecomputeCurrentQuotasServiceTest.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/task/JPARecomputeCurrentQuotasServiceTest.java
index 41032b719e..10a76bae46 100644
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/task/JPARecomputeCurrentQuotasServiceTest.java
+++ b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/task/JPARecomputeCurrentQuotasServiceTest.java
@@ -58,7 +58,7 @@ import com.google.common.collect.ImmutableSet;
 class JPARecomputeCurrentQuotasServiceTest implements RecomputeCurrentQuotasServiceContract {
 
     @RegisterExtension
-    static PostgresExtension postgresExtension = new PostgresExtension(PostgresSubscriptionModule.MODULE);
+    static PostgresExtension postgresExtension = PostgresExtension.withoutRowLevelSecurity(PostgresSubscriptionModule.MODULE);
 
     static final DomainList NO_DOMAIN_LIST = null;
 
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperRowLevelSecurityTest.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperRowLevelSecurityTest.java
index 7f6618933c..9505cd473e 100644
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperRowLevelSecurityTest.java
+++ b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperRowLevelSecurityTest.java
@@ -40,7 +40,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 
 public class PostgresSubscriptionMapperRowLevelSecurityTest {
     @RegisterExtension
-    static PostgresExtension postgresExtension = new PostgresExtension(PostgresSubscriptionModule.MODULE, true);
+    static PostgresExtension postgresExtension = PostgresExtension.withRowLevelSecurity(PostgresSubscriptionModule.MODULE);
 
     private SubscriptionMapperFactory subscriptionMapperFactory;
 
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperTest.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperTest.java
index ac693c9c99..5d05795398 100644
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperTest.java
+++ b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperTest.java
@@ -30,7 +30,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 public class PostgresSubscriptionMapperTest extends SubscriptionMapperTest {
 
     @RegisterExtension
-    static PostgresExtension postgresExtension = new PostgresExtension(PostgresSubscriptionModule.MODULE);
+    static PostgresExtension postgresExtension = PostgresExtension.withoutRowLevelSecurity(PostgresSubscriptionModule.MODULE);
 
     @Override
     protected SubscriptionMapper createSubscriptionMapper() {
diff --git a/server/apps/postgres-app/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java b/server/apps/postgres-app/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
index f73e46c337..16568dc900 100644
--- a/server/apps/postgres-app/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
+++ b/server/apps/postgres-app/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
@@ -51,7 +51,7 @@ class JamesCapabilitiesServerTest {
         .server(configuration -> PostgresJamesServerMain.createServer(configuration)
             .overrideWith(new TestJPAConfigurationModule())
             .overrideWith(binder -> binder.bind(MailboxManager.class).toInstance(mailboxManager())))
-        .extension(new PostgresExtension())
+        .extension(PostgresExtension.empty())
         .build();
     
     @Test
diff --git a/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerTest.java b/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerTest.java
index a17e8560f7..52654ba7b6 100644
--- a/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerTest.java
+++ b/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerTest.java
@@ -50,7 +50,7 @@ class PostgresJamesServerTest implements JamesServerConcreteContract {
             .build())
         .server(configuration -> PostgresJamesServerMain.createServer(configuration)
             .overrideWith(new TestJPAConfigurationModule()))
-        .extension(new PostgresExtension())
+        .extension(PostgresExtension.empty())
         .lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
         .build();
 
diff --git a/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerWithAuthenticatedDatabaseSqlValidationTest.java b/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerWithAuthenticatedDatabaseSqlValidationTest.java
index 2f005078e0..55fd090c49 100644
--- a/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerWithAuthenticatedDatabaseSqlValidationTest.java
+++ b/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerWithAuthenticatedDatabaseSqlValidationTest.java
@@ -35,7 +35,7 @@ class PostgresJamesServerWithAuthenticatedDatabaseSqlValidationTest extends Post
             .build())
         .server(configuration -> PostgresJamesServerMain.createServer(configuration)
             .overrideWith(new TestJPAConfigurationModuleWithSqlValidation.WithDatabaseAuthentication()))
-        .extension(new PostgresExtension())
+        .extension(PostgresExtension.empty())
         .lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
         .build();
 }
diff --git a/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerWithNoDatabaseAuthenticaticationSqlValidationTest.java b/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerWithNoDatabaseAuthenticaticationSqlValidationTest.java
index 19fb866d24..44f9620748 100644
--- a/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerWithNoDatabaseAuthenticaticationSqlValidationTest.java
+++ b/server/apps/postgres-app/src/test/java/org/apache/james/PostgresJamesServerWithNoDatabaseAuthenticaticationSqlValidationTest.java
@@ -34,7 +34,7 @@ class PostgresJamesServerWithNoDatabaseAuthenticaticationSqlValidationTest exten
             .build())
         .server(configuration -> PostgresJamesServerMain.createServer(configuration)
             .overrideWith(new TestJPAConfigurationModuleWithSqlValidation.NoDatabaseAuthentication()))
-        .extension(new PostgresExtension())
+        .extension(PostgresExtension.empty())
         .lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
         .build();
 }
diff --git a/server/apps/postgres-app/src/test/java/org/apache/james/PostgresWithLDAPJamesServerTest.java b/server/apps/postgres-app/src/test/java/org/apache/james/PostgresWithLDAPJamesServerTest.java
index 66e4b6fb88..6bc0e02a95 100644
--- a/server/apps/postgres-app/src/test/java/org/apache/james/PostgresWithLDAPJamesServerTest.java
+++ b/server/apps/postgres-app/src/test/java/org/apache/james/PostgresWithLDAPJamesServerTest.java
@@ -45,7 +45,7 @@ class PostgresWithLDAPJamesServerTest {
             .overrideWith(new TestJPAConfigurationModule()))
         .lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
         .extension(new LdapTestExtension())
-        .extension(new PostgresExtension())
+        .extension(PostgresExtension.empty())
         .build();
 
 


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


(james-project) 07/11: JAMES-2586 Drop unused class: JPASubscription

Posted by rc...@apache.org.
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 f8d1c60eefb988af123ce2b6e49328d54d790920
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Fri Nov 10 10:56:36 2023 +0100

    JAMES-2586 Drop unused class: JPASubscription
---
 .../postgres/user/model/JPASubscription.java       | 136 ---------------------
 .../james/mailbox/postgres/JPAMailboxFixture.java  |   3 -
 .../postgres/src/test/resources/persistence.xml    |   1 -
 .../src/main/resources/META-INF/persistence.xml    |   1 -
 4 files changed, 141 deletions(-)

diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/model/JPASubscription.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/model/JPASubscription.java
deleted file mode 100644
index 3873871cfa..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/user/model/JPASubscription.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-package org.apache.james.mailbox.postgres.user.model;
-
-import java.util.Objects;
-
-import javax.persistence.Basic;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.NamedQueries;
-import javax.persistence.NamedQuery;
-import javax.persistence.Table;
-import javax.persistence.UniqueConstraint;
-
-import org.apache.james.core.Username;
-import org.apache.james.mailbox.store.user.model.Subscription;
-
-/**
- * A subscription to a mailbox by a user.
- */
-@Entity(name = "Subscription")
-@Table(
-    name = "JAMES_SUBSCRIPTION",
-    uniqueConstraints = 
-        @UniqueConstraint(
-                columnNames = {
-                        "USER_NAME", 
-                        "MAILBOX_NAME"})
-)
-@NamedQueries({
-    @NamedQuery(name = JPASubscription.FIND_MAILBOX_SUBSCRIPTION_FOR_USER,
-        query = "SELECT subscription FROM Subscription subscription WHERE subscription.username = :userParam AND subscription.mailbox = :mailboxParam"),          
-    @NamedQuery(name = JPASubscription.FIND_SUBSCRIPTIONS_FOR_USER,
-        query = "SELECT subscription FROM Subscription subscription WHERE subscription.username = :userParam"),
-    @NamedQuery(name = JPASubscription.DELETE_SUBSCRIPTION,
-        query = "DELETE subscription FROM Subscription subscription WHERE subscription.username = :userParam AND subscription.mailbox = :mailboxParam")
-})
-public class JPASubscription {
-    public static final String DELETE_SUBSCRIPTION = "deleteSubscription";
-    public static final String FIND_SUBSCRIPTIONS_FOR_USER = "findSubscriptionsForUser";
-    public static final String FIND_MAILBOX_SUBSCRIPTION_FOR_USER = "findFindMailboxSubscriptionForUser";
-
-    private static final String TO_STRING_SEPARATOR = "  ";
-
-    /** Primary key */
-    @GeneratedValue
-    @Id 
-    @Column(name = "SUBSCRIPTION_ID")
-    private long id;
-    
-    /** Name of the subscribed user */
-    @Basic(optional = false)
-    @Column(name = "USER_NAME", nullable = false, length = 100)
-    private String username;
-    
-    /** Subscribed mailbox */
-    @Basic(optional = false) 
-    @Column(name = "MAILBOX_NAME", nullable = false, length = 100)
-    private String mailbox;
-    
-    /**
-     * Used by JPA
-     */
-    @Deprecated
-    public JPASubscription() {
-
-    }
-    
-    /**
-     * Constructs a user subscription.
-     */
-    public JPASubscription(Subscription subscription) {
-        super();
-        this.username = subscription.getUser().asString();
-        this.mailbox = subscription.getMailbox();
-    }
-
-    public String getMailbox() {
-        return mailbox;
-    }
-
-    public Username getUser() {
-        return Username.of(username);
-    }
-
-    public Subscription toSubscription() {
-        return new Subscription(Username.of(username), mailbox);
-    }
-
-    @Override
-    public final boolean equals(Object o) {
-        if (o instanceof JPASubscription) {
-            JPASubscription that = (JPASubscription) o;
-
-            return Objects.equals(this.id, that.id);
-        }
-        return false;
-    }
-
-    @Override
-    public final int hashCode() {
-        return Objects.hash(id);
-    }
-
-    /**
-     * Renders output suitable for debugging.
-     *
-     * @return output suitable for debugging
-     */
-    public String toString() {
-        return "Subscription ( "
-            + "id = " + this.id + TO_STRING_SEPARATOR
-            + "user = " + this.username + TO_STRING_SEPARATOR
-            + "mailbox = " + this.mailbox + TO_STRING_SEPARATOR
-            + " )";
-    }
-    
-}
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxFixture.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxFixture.java
index 3262f4ec7c..c254cc88d8 100644
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxFixture.java
+++ b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxFixture.java
@@ -35,7 +35,6 @@ import org.apache.james.mailbox.postgres.quota.model.MaxGlobalMessageCount;
 import org.apache.james.mailbox.postgres.quota.model.MaxGlobalStorage;
 import org.apache.james.mailbox.postgres.quota.model.MaxUserMessageCount;
 import org.apache.james.mailbox.postgres.quota.model.MaxUserStorage;
-import org.apache.james.mailbox.postgres.user.model.JPASubscription;
 
 import com.google.common.collect.ImmutableList;
 
@@ -48,7 +47,6 @@ public interface JPAMailboxFixture {
         JPAProperty.class,
         JPAUserFlag.class,
         JPAMailboxAnnotation.class,
-        JPASubscription.class,
         JPAAttachment.class
     );
 
@@ -68,7 +66,6 @@ public interface JPAMailboxFixture {
         "JAMES_MAILBOX_ANNOTATION",
         "JAMES_MAILBOX",
         "JAMES_MAIL",
-        "JAMES_SUBSCRIPTION",
         "JAMES_ATTACHMENT");
 
     List<String> QUOTA_TABLES_NAMES = ImmutableList.of(
diff --git a/mailbox/postgres/src/test/resources/persistence.xml b/mailbox/postgres/src/test/resources/persistence.xml
index 31f7a7a761..83201af526 100644
--- a/mailbox/postgres/src/test/resources/persistence.xml
+++ b/mailbox/postgres/src/test/resources/persistence.xml
@@ -30,7 +30,6 @@
         <class>org.apache.james.mailbox.postgres.mail.model.openjpa.JPAMailboxMessage</class>
         <class>org.apache.james.mailbox.postgres.mail.model.JPAAttachment</class>
         <class>org.apache.james.mailbox.postgres.mail.model.JPAProperty</class>
-        <class>org.apache.james.mailbox.postgres.user.model.JPASubscription</class>
         <class>org.apache.james.mailbox.postgres.quota.model.MaxDomainMessageCount</class>
         <class>org.apache.james.mailbox.postgres.quota.model.MaxDomainStorage</class>
         <class>org.apache.james.mailbox.postgres.quota.model.MaxGlobalMessageCount</class>
diff --git a/server/apps/postgres-app/src/main/resources/META-INF/persistence.xml b/server/apps/postgres-app/src/main/resources/META-INF/persistence.xml
index bd9ae808b6..d9e49513f3 100644
--- a/server/apps/postgres-app/src/main/resources/META-INF/persistence.xml
+++ b/server/apps/postgres-app/src/main/resources/META-INF/persistence.xml
@@ -29,7 +29,6 @@
         <class>org.apache.james.mailbox.postgres.mail.model.openjpa.AbstractJPAMailboxMessage</class>
         <class>org.apache.james.mailbox.postgres.mail.model.openjpa.JPAMailboxMessage</class>
         <class>org.apache.james.mailbox.postgres.mail.model.JPAProperty</class>
-        <class>org.apache.james.mailbox.postgres.user.model.JPASubscription</class>
 
         <class>org.apache.james.domainlist.jpa.model.JPADomain</class>
         <class>org.apache.james.mailrepository.jpa.model.JPAUrl</class>


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


(james-project) 01/11: JAMES-2586 Use prepared statements by default

Posted by rc...@apache.org.
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 005cbd5a908c5a2fb92e5c3432bbb66e210909db
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Fri Nov 10 10:36:43 2023 +0100

    JAMES-2586 Use prepared statements by default
---
 .../org/apache/james/backends/postgres/utils/PostgresExecutor.java    | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/utils/PostgresExecutor.java b/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/utils/PostgresExecutor.java
index 43b5efa4e1..1c92abc197 100644
--- a/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/utils/PostgresExecutor.java
+++ b/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/utils/PostgresExecutor.java
@@ -27,6 +27,7 @@ import org.jooq.DSLContext;
 import org.jooq.Record;
 import org.jooq.SQLDialect;
 import org.jooq.conf.Settings;
+import org.jooq.conf.StatementType;
 import org.jooq.impl.DSL;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -39,7 +40,8 @@ public class PostgresExecutor {
 
     private static final SQLDialect PGSQL_DIALECT = SQLDialect.POSTGRES;
     private static final Settings SETTINGS = new Settings()
-        .withRenderFormatted(true);
+        .withRenderFormatted(true)
+        .withStatementType(StatementType.PREPARED_STATEMENT);
     private final Mono<Connection> connection;
 
     @Inject


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