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

ilgrosso pushed a commit to branch 4_0_X
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/4_0_X by this push:
     new eb93cbefbe [SYNCOPE-1991] Excluding binary and encrypted attributes 
from Elasticsearch and OpenSearch indexing
eb93cbefbe is described below

commit eb93cbefbe39c7ece2b4cbd642ab2b4dbf67192c
Author: Francesco Chicchiriccò <[email protected]>
AuthorDate: Thu Aug 27 09:56:32 2026 +0200

    [SYNCOPE-1991] Excluding binary and encrypted attributes from Elasticsearch 
and OpenSearch indexing
---
 .../client/ElasticsearchClientContext.java         |  4 +-
 .../elasticsearch/client/ElasticsearchUtils.java   | 64 +++++++++++++---------
 .../opensearch/client/OpenSearchClientContext.java |  4 +-
 .../ext/opensearch/client/OpenSearchUtils.java     | 64 +++++++++++++---------
 4 files changed, 84 insertions(+), 52 deletions(-)

diff --git 
a/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchClientContext.java
 
b/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchClientContext.java
index b26c904300..41366da7a6 100644
--- 
a/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchClientContext.java
+++ 
b/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchClientContext.java
@@ -24,6 +24,7 @@ import java.util.Objects;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO;
 import org.apache.syncope.core.persistence.api.dao.GroupDAO;
+import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
 import org.apache.syncope.core.persistence.api.dao.UserDAO;
 import org.identityconnectors.common.CollectionUtil;
 import org.slf4j.Logger;
@@ -58,11 +59,12 @@ public class ElasticsearchClientContext {
     @ConditionalOnMissingBean
     @Bean
     public ElasticsearchUtils elasticsearchUtils(
+            final @Lazy PlainSchemaDAO plainSchemaDAO,
             final @Lazy UserDAO userDAO,
             final @Lazy GroupDAO groupDAO,
             final @Lazy AnyObjectDAO anyObjectDAO) {
 
-        return new ElasticsearchUtils(userDAO, groupDAO, anyObjectDAO);
+        return new ElasticsearchUtils(plainSchemaDAO, userDAO, groupDAO, 
anyObjectDAO);
     }
 
     @ConditionalOnMissingBean
diff --git 
a/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchUtils.java
 
b/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchUtils.java
index 7b9250fd97..e93d855c2b 100644
--- 
a/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchUtils.java
+++ 
b/ext/elasticsearch/client-elasticsearch/src/main/java/org/apache/syncope/ext/elasticsearch/client/ElasticsearchUtils.java
@@ -28,8 +28,10 @@ import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Collectors;
 import org.apache.syncope.common.lib.types.AnyTypeKind;
+import org.apache.syncope.common.lib.types.AttrSchemaType;
 import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO;
 import org.apache.syncope.core.persistence.api.dao.GroupDAO;
+import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
 import org.apache.syncope.core.persistence.api.dao.UserDAO;
 import org.apache.syncope.core.persistence.api.entity.Any;
 import org.apache.syncope.core.persistence.api.entity.AnyTypeClass;
@@ -64,6 +66,8 @@ public class ElasticsearchUtils {
         return domain.toLowerCase() + "_audit";
     }
 
+    protected final PlainSchemaDAO plainSchemaDAO;
+
     protected final UserDAO userDAO;
 
     protected final GroupDAO groupDAO;
@@ -71,10 +75,12 @@ public class ElasticsearchUtils {
     protected final AnyObjectDAO anyObjectDAO;
 
     public ElasticsearchUtils(
+            final PlainSchemaDAO plainSchemaDAO,
             final UserDAO userDAO,
             final GroupDAO groupDAO,
             final AnyObjectDAO anyObjectDAO) {
 
+        this.plainSchemaDAO = plainSchemaDAO;
         this.userDAO = userDAO;
         this.groupDAO = groupDAO;
         this.anyObjectDAO = anyObjectDAO;
@@ -91,15 +97,19 @@ public class ElasticsearchUtils {
         builder.put("relationshipTypes", relationshipTypes);
     }
 
-    protected void addPlainAttr(final Map<String, Object> builder, final 
List<PlainAttr> plainAttrs) {
-        for (PlainAttr plainAttr : plainAttrs) {
-            List<Object> values = plainAttr.getValues().stream().
-                    map(PlainAttrValue::getValue).collect(Collectors.toList());
+    protected void plainAttrs(final Map<String, Object> builder, final 
List<PlainAttr> plainAttrs) {
+        plainAttrs.stream().
+                filter(plainAttr -> 
plainSchemaDAO.findById(plainAttr.getSchema()).
+                        map(s -> s.getType() != AttrSchemaType.Binary && 
s.getType() != AttrSchemaType.Encrypted).
+                        orElse(false)).
+                forEach(plainAttr -> {
+                    List<Object> values = plainAttr.getValues().stream().
+                            
map(PlainAttrValue::getValue).collect(Collectors.toList());
 
-            Optional.ofNullable(plainAttr.getUniqueValue()).ifPresent(v -> 
values.add(v.getValue()));
+                    
Optional.ofNullable(plainAttr.getUniqueValue()).ifPresent(v -> 
values.add(v.getValue()));
 
-            builder.put(plainAttr.getSchema(), values.size() == 1 ? 
values.getFirst() : values);
-        }
+                    builder.put(plainAttr.getSchema(), values.size() == 1 ? 
values.getFirst() : values);
+                });
     }
 
     /**
@@ -182,25 +192,29 @@ public class ElasticsearchUtils {
             }
         }
 
-        addPlainAttr(builder, any.getPlainAttrs());
+        plainAttrs(builder, any.getPlainAttrs());
 
-        // add also flattened membership attributes
+        // add flattened membership attributes
         if (any instanceof Groupable<?, ?, ?> groupable) {
-            groupable.getMemberships().forEach(m -> 
groupable.getPlainAttrs(m).forEach(mAttr -> {
-                List<Object> values = mAttr.getValues().stream().
-                        
map(PlainAttrValue::getValue).collect(Collectors.toList());
-
-                Optional.ofNullable(mAttr.getUniqueValue()).ifPresent(v -> 
values.add(v.getValue()));
-
-                Object attr = builder.computeIfAbsent(mAttr.getSchema(), k -> 
new HashSet<>());
-                // also support case in which there is also an existing 
attribute set previously
-                if (attr instanceof Collection) {
-                    ((Collection<Object>) attr).addAll(values);
-                } else {
-                    values.add(attr);
-                    builder.put(mAttr.getSchema(), values.size() == 1 ? 
values.getFirst() : values);
-                }
-            }));
+            groupable.getMemberships().forEach(m -> 
groupable.getPlainAttrs(m).stream().
+                    filter(plainAttr -> 
plainSchemaDAO.findById(plainAttr.getSchema()).
+                            map(s -> s.getType() != AttrSchemaType.Binary && 
s.getType() != AttrSchemaType.Encrypted).
+                            orElse(false)).
+                    forEach(plainAttr -> {
+                        List<Object> values = plainAttr.getValues().stream().
+                                
map(PlainAttrValue::getValue).collect(Collectors.toList());
+
+                        
Optional.ofNullable(plainAttr.getUniqueValue()).ifPresent(v -> 
values.add(v.getValue()));
+
+                        Object attr = 
builder.computeIfAbsent(plainAttr.getSchema(), k -> new HashSet<>());
+                        // support case in which there is also an existing 
attribute set previously
+                        if (attr instanceof Collection) {
+                            ((Collection<Object>) attr).addAll(values);
+                        } else {
+                            values.add(attr);
+                            builder.put(plainAttr.getSchema(), values.size() 
== 1 ? values.getFirst() : values);
+                        }
+                    }));
         }
 
         return builder;
@@ -222,7 +236,7 @@ public class ElasticsearchUtils {
         builder.put("fullPath", realm.getFullPath());
         builder.put("auxClasses", 
realm.getAnyTypeClasses().stream().map(AnyTypeClass::getKey).toList());
         builder.put("resources", 
realm.getResources().stream().map(Entity::getKey).toList());
-        addPlainAttr(builder, realm.getPlainAttrs());
+        plainAttrs(builder, realm.getPlainAttrs());
 
         customizeDocument(builder, realm);
 
diff --git 
a/ext/opensearch/client-opensearch/src/main/java/org/apache/syncope/ext/opensearch/client/OpenSearchClientContext.java
 
b/ext/opensearch/client-opensearch/src/main/java/org/apache/syncope/ext/opensearch/client/OpenSearchClientContext.java
index 3a36aaf107..a50b631d71 100644
--- 
a/ext/opensearch/client-opensearch/src/main/java/org/apache/syncope/ext/opensearch/client/OpenSearchClientContext.java
+++ 
b/ext/opensearch/client-opensearch/src/main/java/org/apache/syncope/ext/opensearch/client/OpenSearchClientContext.java
@@ -23,6 +23,7 @@ import java.util.Objects;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO;
 import org.apache.syncope.core.persistence.api.dao.GroupDAO;
+import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
 import org.apache.syncope.core.persistence.api.dao.UserDAO;
 import org.identityconnectors.common.CollectionUtil;
 import org.opensearch.client.opensearch.OpenSearchClient;
@@ -58,11 +59,12 @@ public class OpenSearchClientContext {
     @ConditionalOnMissingBean
     @Bean
     public OpenSearchUtils openSearchUtils(
+            final @Lazy PlainSchemaDAO plainSchemaDAO,
             final @Lazy UserDAO userDAO,
             final @Lazy GroupDAO groupDAO,
             final @Lazy AnyObjectDAO anyObjectDAO) {
 
-        return new OpenSearchUtils(userDAO, groupDAO, anyObjectDAO);
+        return new OpenSearchUtils(plainSchemaDAO, userDAO, groupDAO, 
anyObjectDAO);
     }
 
     @ConditionalOnMissingBean
diff --git 
a/ext/opensearch/client-opensearch/src/main/java/org/apache/syncope/ext/opensearch/client/OpenSearchUtils.java
 
b/ext/opensearch/client-opensearch/src/main/java/org/apache/syncope/ext/opensearch/client/OpenSearchUtils.java
index 2aab06fc3a..d802afb9d0 100644
--- 
a/ext/opensearch/client-opensearch/src/main/java/org/apache/syncope/ext/opensearch/client/OpenSearchUtils.java
+++ 
b/ext/opensearch/client-opensearch/src/main/java/org/apache/syncope/ext/opensearch/client/OpenSearchUtils.java
@@ -28,8 +28,10 @@ import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Collectors;
 import org.apache.syncope.common.lib.types.AnyTypeKind;
+import org.apache.syncope.common.lib.types.AttrSchemaType;
 import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO;
 import org.apache.syncope.core.persistence.api.dao.GroupDAO;
+import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
 import org.apache.syncope.core.persistence.api.dao.UserDAO;
 import org.apache.syncope.core.persistence.api.entity.Any;
 import org.apache.syncope.core.persistence.api.entity.AnyTypeClass;
@@ -64,6 +66,8 @@ public class OpenSearchUtils {
         return domain.toLowerCase() + "_audit";
     }
 
+    protected final PlainSchemaDAO plainSchemaDAO;
+
     protected final UserDAO userDAO;
 
     protected final GroupDAO groupDAO;
@@ -71,10 +75,12 @@ public class OpenSearchUtils {
     protected final AnyObjectDAO anyObjectDAO;
 
     public OpenSearchUtils(
+            final PlainSchemaDAO plainSchemaDAO,
             final UserDAO userDAO,
             final GroupDAO groupDAO,
             final AnyObjectDAO anyObjectDAO) {
 
+        this.plainSchemaDAO = plainSchemaDAO;
         this.userDAO = userDAO;
         this.groupDAO = groupDAO;
         this.anyObjectDAO = anyObjectDAO;
@@ -91,15 +97,19 @@ public class OpenSearchUtils {
         builder.put("relationshipTypes", relationshipTypes);
     }
 
-    protected void addPlainAttr(final Map<String, Object> builder, final 
List<PlainAttr> plainAttrs) {
-        for (PlainAttr plainAttr : plainAttrs) {
-            List<Object> values = plainAttr.getValues().stream().
-                    map(PlainAttrValue::getValue).collect(Collectors.toList());
+    protected void plainAttrs(final Map<String, Object> builder, final 
List<PlainAttr> plainAttrs) {
+        plainAttrs.stream().
+                filter(plainAttr -> 
plainSchemaDAO.findById(plainAttr.getSchema()).
+                        map(s -> s.getType() != AttrSchemaType.Binary && 
s.getType() != AttrSchemaType.Encrypted).
+                        orElse(false)).
+                forEach(plainAttr -> {
+                    List<Object> values = plainAttr.getValues().stream().
+                            
map(PlainAttrValue::getValue).collect(Collectors.toList());
 
-            Optional.ofNullable(plainAttr.getUniqueValue()).ifPresent(v -> 
values.add(v.getValue()));
+                    
Optional.ofNullable(plainAttr.getUniqueValue()).ifPresent(v -> 
values.add(v.getValue()));
 
-            builder.put(plainAttr.getSchema(), values.size() == 1 ? 
values.getFirst() : values);
-        }
+                    builder.put(plainAttr.getSchema(), values.size() == 1 ? 
values.getFirst() : values);
+                });
     }
 
     /**
@@ -182,25 +192,29 @@ public class OpenSearchUtils {
             }
         }
 
-        addPlainAttr(builder, any.getPlainAttrs());
+        plainAttrs(builder, any.getPlainAttrs());
 
-        // add also flattened membership attributes
+        // add flattened membership attributes
         if (any instanceof Groupable<?, ?, ?> groupable) {
-            groupable.getMemberships().forEach(m -> 
groupable.getPlainAttrs(m).forEach(mAttr -> {
-                List<Object> values = mAttr.getValues().stream().
-                        
map(PlainAttrValue::getValue).collect(Collectors.toList());
-
-                Optional.ofNullable(mAttr.getUniqueValue()).ifPresent(v -> 
values.add(v.getValue()));
-
-                Object attr = builder.computeIfAbsent(mAttr.getSchema(), k -> 
new HashSet<>());
-                // also support case in which there is also an existing 
attribute set previously
-                if (attr instanceof Collection) {
-                    ((Collection<Object>) attr).addAll(values);
-                } else {
-                    values.add(attr);
-                    builder.put(mAttr.getSchema(), values.size() == 1 ? 
values.getFirst() : values);
-                }
-            }));
+            groupable.getMemberships().forEach(m -> 
groupable.getPlainAttrs(m).stream().
+                    filter(plainAttr -> 
plainSchemaDAO.findById(plainAttr.getSchema()).
+                            map(s -> s.getType() != AttrSchemaType.Binary && 
s.getType() != AttrSchemaType.Encrypted).
+                            orElse(false)).
+                    forEach(plainAttr -> {
+                        List<Object> values = plainAttr.getValues().stream().
+                                
map(PlainAttrValue::getValue).collect(Collectors.toList());
+
+                        
Optional.ofNullable(plainAttr.getUniqueValue()).ifPresent(v -> 
values.add(v.getValue()));
+
+                        Object attr = 
builder.computeIfAbsent(plainAttr.getSchema(), k -> new HashSet<>());
+                        // support case in which there is also an existing 
attribute set previously
+                        if (attr instanceof Collection) {
+                            ((Collection<Object>) attr).addAll(values);
+                        } else {
+                            values.add(attr);
+                            builder.put(plainAttr.getSchema(), values.size() 
== 1 ? values.getFirst() : values);
+                        }
+                    }));
         }
 
         return builder;
@@ -222,7 +236,7 @@ public class OpenSearchUtils {
         builder.put("fullPath", realm.getFullPath());
         builder.put("auxClasses", 
realm.getAnyTypeClasses().stream().map(AnyTypeClass::getKey).toList());
         builder.put("resources", 
realm.getResources().stream().map(Entity::getKey).toList());
-        addPlainAttr(builder, realm.getPlainAttrs());
+        plainAttrs(builder, realm.getPlainAttrs());
 
         customizeDocument(builder, realm);
 

Reply via email to