github-advanced-security[bot] commented on code in PR #1258:
URL: https://github.com/apache/syncope/pull/1258#discussion_r2716621625


##########
ext/opensearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/OpenSearchReindex.java:
##########
@@ -111,129 +158,140 @@
         return indexManager.defaultAuditMapping();
     }
 
+    protected Pair<String, Long> reindexRealms(final JobExecutionContext 
context) throws IOException {
+        indexManager.createRealmIndex(AuthContextUtils.getDomain(), 
realmSettings(), realmMapping());
+
+        long count = realmDAO.count();
+        String index = 
OpenSearchUtils.getRealmIndex(AuthContextUtils.getDomain());
+        setStatus("Indexing " + count + " realms under " + index + "...");
+
+        try (BulkIngester<Void> ingester = BulkIngester.of(b -> 
b.client(client).
+                
maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE)))
 {
+
+            for (int page = 0; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE); 
page++) {

Review Comment:
   ## Comparison of narrow type with wide type in loop condition
   
   Comparison between [expression](1) of type int and [expression](2) of wider 
type long.
   
   [Show more 
details](https://github.com/apache/syncope/security/code-scanning/2506)



##########
ext/opensearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/OpenSearchReindex.java:
##########
@@ -111,129 +158,140 @@
         return indexManager.defaultAuditMapping();
     }
 
+    protected Pair<String, Long> reindexRealms(final JobExecutionContext 
context) throws IOException {
+        indexManager.createRealmIndex(AuthContextUtils.getDomain(), 
realmSettings(), realmMapping());
+
+        long count = realmDAO.count();
+        String index = 
OpenSearchUtils.getRealmIndex(AuthContextUtils.getDomain());
+        setStatus("Indexing " + count + " realms under " + index + "...");
+
+        try (BulkIngester<Void> ingester = BulkIngester.of(b -> 
b.client(client).
+                
maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE)))
 {
+
+            for (int page = 0; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE); 
page++) {
+                Pageable pageable = PageRequest.of(page, 
AnyDAO.DEFAULT_PAGE_SIZE, DAO.DEFAULT_SORT);
+                for (Realm realm : realmDAO.findAll(pageable)) {
+                    ingester.add(op -> op.index(idx -> idx.
+                            index(index).
+                            id(realm.getKey()).
+                            document(utils.document(realm))));
+                }
+            }
+        } catch (Exception e) {
+            LOG.error("Errors while ingesting index {}", index, e);
+        }
+
+        return Pair.of(index, count);
+    }
+
+    protected Pair<String, Long> reindexUsers(final JobExecutionContext 
context) throws IOException {
+        indexManager.createAnyIndex(AuthContextUtils.getDomain(), 
AnyTypeKind.USER, userSettings(), userMapping());
+
+        long count = userDAO.count();
+        String index = 
OpenSearchUtils.getAnyIndex(AuthContextUtils.getDomain(), AnyTypeKind.USER);
+        setStatus("Indexing " + count + " users under " + index + "...");
+
+        try (BulkIngester<Void> ingester = BulkIngester.of(b -> 
b.client(client).
+                
maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE)))
 {
+
+            for (int page = 0; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE); 
page++) {

Review Comment:
   ## Comparison of narrow type with wide type in loop condition
   
   Comparison between [expression](1) of type int and [expression](2) of wider 
type long.
   
   [Show more 
details](https://github.com/apache/syncope/security/code-scanning/2507)



##########
ext/opensearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/OpenSearchReindex.java:
##########
@@ -111,129 +158,140 @@
         return indexManager.defaultAuditMapping();
     }
 
+    protected Pair<String, Long> reindexRealms(final JobExecutionContext 
context) throws IOException {
+        indexManager.createRealmIndex(AuthContextUtils.getDomain(), 
realmSettings(), realmMapping());
+
+        long count = realmDAO.count();
+        String index = 
OpenSearchUtils.getRealmIndex(AuthContextUtils.getDomain());
+        setStatus("Indexing " + count + " realms under " + index + "...");
+
+        try (BulkIngester<Void> ingester = BulkIngester.of(b -> 
b.client(client).
+                
maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE)))
 {
+
+            for (int page = 0; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE); 
page++) {
+                Pageable pageable = PageRequest.of(page, 
AnyDAO.DEFAULT_PAGE_SIZE, DAO.DEFAULT_SORT);
+                for (Realm realm : realmDAO.findAll(pageable)) {
+                    ingester.add(op -> op.index(idx -> idx.
+                            index(index).
+                            id(realm.getKey()).
+                            document(utils.document(realm))));
+                }
+            }
+        } catch (Exception e) {
+            LOG.error("Errors while ingesting index {}", index, e);
+        }
+
+        return Pair.of(index, count);
+    }
+
+    protected Pair<String, Long> reindexUsers(final JobExecutionContext 
context) throws IOException {

Review Comment:
   ## Useless parameter
   
   The parameter 'context' is never used.
   
   [Show more 
details](https://github.com/apache/syncope/security/code-scanning/2515)



##########
ext/elasticsearch/persistence/src/main/java/org/apache/syncope/core/persistence/elasticsearch/dao/ElasticsearchAuditEventDAO.java:
##########
@@ -183,17 +180,15 @@
                 build();
         LOG.debug("Search request: {}", request);
 
-        List<Hit<ObjectNode>> esResult = null;
+        List<Hit<AuditEventTO>> esResult = null;
         try {
-            esResult = client.search(request, ObjectNode.class).hits().hits();
+            esResult = client.search(request, 
AuditEventTO.class).hits().hits();
         } catch (Exception e) {
-            LOG.error("While searching in Elasticsearch with request {}", 
request, e);
+            LOG.error("While searching in OpenSearch with request {}", 
request, e);
         }
 
         return CollectionUtils.isEmpty(esResult)
                 ? List.of()
-                : esResult.stream().
-                        map(hit -> POJOHelper.convertValue(hit.source(), 
AuditEventTO.class)).
-                        filter(Objects::nonNull).toList();
+                : esResult.stream().map(Hit::source).toList();

Review Comment:
   ## Dereferenced variable may be null
   
   Variable [esResult](1) may be null at this access because of [this](2) 
assignment.
   
   [Show more 
details](https://github.com/apache/syncope/security/code-scanning/2510)



##########
ext/opensearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/OpenSearchReindex.java:
##########
@@ -111,129 +158,140 @@
         return indexManager.defaultAuditMapping();
     }
 
+    protected Pair<String, Long> reindexRealms(final JobExecutionContext 
context) throws IOException {
+        indexManager.createRealmIndex(AuthContextUtils.getDomain(), 
realmSettings(), realmMapping());
+
+        long count = realmDAO.count();
+        String index = 
OpenSearchUtils.getRealmIndex(AuthContextUtils.getDomain());
+        setStatus("Indexing " + count + " realms under " + index + "...");
+
+        try (BulkIngester<Void> ingester = BulkIngester.of(b -> 
b.client(client).
+                
maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE)))
 {
+
+            for (int page = 0; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE); 
page++) {
+                Pageable pageable = PageRequest.of(page, 
AnyDAO.DEFAULT_PAGE_SIZE, DAO.DEFAULT_SORT);
+                for (Realm realm : realmDAO.findAll(pageable)) {
+                    ingester.add(op -> op.index(idx -> idx.
+                            index(index).
+                            id(realm.getKey()).
+                            document(utils.document(realm))));
+                }
+            }
+        } catch (Exception e) {
+            LOG.error("Errors while ingesting index {}", index, e);
+        }
+
+        return Pair.of(index, count);
+    }
+
+    protected Pair<String, Long> reindexUsers(final JobExecutionContext 
context) throws IOException {
+        indexManager.createAnyIndex(AuthContextUtils.getDomain(), 
AnyTypeKind.USER, userSettings(), userMapping());
+
+        long count = userDAO.count();
+        String index = 
OpenSearchUtils.getAnyIndex(AuthContextUtils.getDomain(), AnyTypeKind.USER);
+        setStatus("Indexing " + count + " users under " + index + "...");
+
+        try (BulkIngester<Void> ingester = BulkIngester.of(b -> 
b.client(client).
+                
maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE)))
 {
+
+            for (int page = 0; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE); 
page++) {
+                Pageable pageable = PageRequest.of(page, 
AnyDAO.DEFAULT_PAGE_SIZE, DAO.DEFAULT_SORT);
+                for (User user : userDAO.findAll(pageable)) {
+                    ingester.add(op -> op.index(idx -> idx.
+                            index(index).
+                            id(user.getKey()).
+                            document(utils.document(user))));
+                }
+            }
+        } catch (Exception e) {
+            LOG.error("Errors while ingesting index {}", index, e);
+        }
+
+        return Pair.of(index, count);
+    }
+
+    protected Pair<String, Long> reindexGroups(final JobExecutionContext 
context) throws IOException {
+        indexManager.createAnyIndex(AuthContextUtils.getDomain(), 
AnyTypeKind.GROUP, groupSettings(), groupMapping());
+
+        long count = groupDAO.count();
+        String index = 
OpenSearchUtils.getAnyIndex(AuthContextUtils.getDomain(), AnyTypeKind.GROUP);
+        setStatus("Indexing " + count + " groups under " + index + "...");
+
+        try (BulkIngester<Void> ingester = BulkIngester.of(b -> 
b.client(client).
+                
maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE)))
 {
+
+            for (int page = 0; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE); 
page++) {
+                Pageable pageable = PageRequest.of(page, 
AnyDAO.DEFAULT_PAGE_SIZE, DAO.DEFAULT_SORT);
+                for (Group group : groupDAO.findAll(pageable)) {
+                    ingester.add(op -> op.index(idx -> idx.
+                            index(index).
+                            id(group.getKey()).
+                            document(utils.document(group))));
+                }
+            }
+        } catch (Exception e) {
+            LOG.error("Errors while ingesting index {}", index, e);
+        }
+
+        return Pair.of(index, count);
+    }
+
+    protected Pair<String, Long> reindexAnyObjects(final JobExecutionContext 
context) throws IOException {
+        indexManager.createAnyIndex(
+                AuthContextUtils.getDomain(), AnyTypeKind.ANY_OBJECT, 
anyObjectSettings(), anyObjectMapping());
+
+        long count = anyObjectDAO.count();
+        String index = 
OpenSearchUtils.getAnyIndex(AuthContextUtils.getDomain(), 
AnyTypeKind.ANY_OBJECT);
+        setStatus("Indexing " + count + " any objects under " + index + "...");
+
+        try (BulkIngester<Void> ingester = BulkIngester.of(b -> 
b.client(client).
+                
maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE)))
 {
+
+            for (int page = 0; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE); 
page++) {
+                Pageable pageable = PageRequest.of(page, 
AnyDAO.DEFAULT_PAGE_SIZE, DAO.DEFAULT_SORT);
+                for (AnyObject anyObject : anyObjectDAO.findAll(pageable)) {
+                    ingester.add(op -> op.index(idx -> idx.
+                            index(index).
+                            id(anyObject.getKey()).
+                            document(utils.document(anyObject))));
+                }
+            }
+        } catch (Exception e) {
+            LOG.error("Errors while ingesting index {}", index, e);
+        }
+
+        return Pair.of(index, count);
+    }
+
+    protected String reindexAudit(final JobExecutionContext context) throws 
IOException {

Review Comment:
   ## Useless parameter
   
   The parameter 'context' is never used.
   
   [Show more 
details](https://github.com/apache/syncope/security/code-scanning/2512)



##########
ext/opensearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/OpenSearchReindex.java:
##########
@@ -111,129 +158,140 @@
         return indexManager.defaultAuditMapping();
     }
 
+    protected Pair<String, Long> reindexRealms(final JobExecutionContext 
context) throws IOException {
+        indexManager.createRealmIndex(AuthContextUtils.getDomain(), 
realmSettings(), realmMapping());
+
+        long count = realmDAO.count();
+        String index = 
OpenSearchUtils.getRealmIndex(AuthContextUtils.getDomain());
+        setStatus("Indexing " + count + " realms under " + index + "...");
+
+        try (BulkIngester<Void> ingester = BulkIngester.of(b -> 
b.client(client).
+                
maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE)))
 {
+
+            for (int page = 0; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE); 
page++) {
+                Pageable pageable = PageRequest.of(page, 
AnyDAO.DEFAULT_PAGE_SIZE, DAO.DEFAULT_SORT);
+                for (Realm realm : realmDAO.findAll(pageable)) {
+                    ingester.add(op -> op.index(idx -> idx.
+                            index(index).
+                            id(realm.getKey()).
+                            document(utils.document(realm))));
+                }
+            }
+        } catch (Exception e) {
+            LOG.error("Errors while ingesting index {}", index, e);
+        }
+
+        return Pair.of(index, count);
+    }
+
+    protected Pair<String, Long> reindexUsers(final JobExecutionContext 
context) throws IOException {
+        indexManager.createAnyIndex(AuthContextUtils.getDomain(), 
AnyTypeKind.USER, userSettings(), userMapping());
+
+        long count = userDAO.count();
+        String index = 
OpenSearchUtils.getAnyIndex(AuthContextUtils.getDomain(), AnyTypeKind.USER);
+        setStatus("Indexing " + count + " users under " + index + "...");
+
+        try (BulkIngester<Void> ingester = BulkIngester.of(b -> 
b.client(client).
+                
maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE)))
 {
+
+            for (int page = 0; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE); 
page++) {
+                Pageable pageable = PageRequest.of(page, 
AnyDAO.DEFAULT_PAGE_SIZE, DAO.DEFAULT_SORT);
+                for (User user : userDAO.findAll(pageable)) {
+                    ingester.add(op -> op.index(idx -> idx.
+                            index(index).
+                            id(user.getKey()).
+                            document(utils.document(user))));
+                }
+            }
+        } catch (Exception e) {
+            LOG.error("Errors while ingesting index {}", index, e);
+        }
+
+        return Pair.of(index, count);
+    }
+
+    protected Pair<String, Long> reindexGroups(final JobExecutionContext 
context) throws IOException {
+        indexManager.createAnyIndex(AuthContextUtils.getDomain(), 
AnyTypeKind.GROUP, groupSettings(), groupMapping());
+
+        long count = groupDAO.count();
+        String index = 
OpenSearchUtils.getAnyIndex(AuthContextUtils.getDomain(), AnyTypeKind.GROUP);
+        setStatus("Indexing " + count + " groups under " + index + "...");
+
+        try (BulkIngester<Void> ingester = BulkIngester.of(b -> 
b.client(client).
+                
maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE)))
 {
+
+            for (int page = 0; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE); 
page++) {
+                Pageable pageable = PageRequest.of(page, 
AnyDAO.DEFAULT_PAGE_SIZE, DAO.DEFAULT_SORT);
+                for (Group group : groupDAO.findAll(pageable)) {
+                    ingester.add(op -> op.index(idx -> idx.
+                            index(index).
+                            id(group.getKey()).
+                            document(utils.document(group))));
+                }
+            }
+        } catch (Exception e) {
+            LOG.error("Errors while ingesting index {}", index, e);
+        }
+
+        return Pair.of(index, count);
+    }
+
+    protected Pair<String, Long> reindexAnyObjects(final JobExecutionContext 
context) throws IOException {

Review Comment:
   ## Useless parameter
   
   The parameter 'context' is never used.
   
   [Show more 
details](https://github.com/apache/syncope/security/code-scanning/2513)



##########
ext/opensearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/OpenSearchReindex.java:
##########
@@ -111,129 +158,140 @@
         return indexManager.defaultAuditMapping();
     }
 
+    protected Pair<String, Long> reindexRealms(final JobExecutionContext 
context) throws IOException {
+        indexManager.createRealmIndex(AuthContextUtils.getDomain(), 
realmSettings(), realmMapping());
+
+        long count = realmDAO.count();
+        String index = 
OpenSearchUtils.getRealmIndex(AuthContextUtils.getDomain());
+        setStatus("Indexing " + count + " realms under " + index + "...");
+
+        try (BulkIngester<Void> ingester = BulkIngester.of(b -> 
b.client(client).
+                
maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE)))
 {
+
+            for (int page = 0; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE); 
page++) {
+                Pageable pageable = PageRequest.of(page, 
AnyDAO.DEFAULT_PAGE_SIZE, DAO.DEFAULT_SORT);
+                for (Realm realm : realmDAO.findAll(pageable)) {
+                    ingester.add(op -> op.index(idx -> idx.
+                            index(index).
+                            id(realm.getKey()).
+                            document(utils.document(realm))));
+                }
+            }
+        } catch (Exception e) {
+            LOG.error("Errors while ingesting index {}", index, e);
+        }
+
+        return Pair.of(index, count);
+    }
+
+    protected Pair<String, Long> reindexUsers(final JobExecutionContext 
context) throws IOException {
+        indexManager.createAnyIndex(AuthContextUtils.getDomain(), 
AnyTypeKind.USER, userSettings(), userMapping());
+
+        long count = userDAO.count();
+        String index = 
OpenSearchUtils.getAnyIndex(AuthContextUtils.getDomain(), AnyTypeKind.USER);
+        setStatus("Indexing " + count + " users under " + index + "...");
+
+        try (BulkIngester<Void> ingester = BulkIngester.of(b -> 
b.client(client).
+                
maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE)))
 {
+
+            for (int page = 0; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE); 
page++) {
+                Pageable pageable = PageRequest.of(page, 
AnyDAO.DEFAULT_PAGE_SIZE, DAO.DEFAULT_SORT);
+                for (User user : userDAO.findAll(pageable)) {
+                    ingester.add(op -> op.index(idx -> idx.
+                            index(index).
+                            id(user.getKey()).
+                            document(utils.document(user))));
+                }
+            }
+        } catch (Exception e) {
+            LOG.error("Errors while ingesting index {}", index, e);
+        }
+
+        return Pair.of(index, count);
+    }
+
+    protected Pair<String, Long> reindexGroups(final JobExecutionContext 
context) throws IOException {
+        indexManager.createAnyIndex(AuthContextUtils.getDomain(), 
AnyTypeKind.GROUP, groupSettings(), groupMapping());
+
+        long count = groupDAO.count();
+        String index = 
OpenSearchUtils.getAnyIndex(AuthContextUtils.getDomain(), AnyTypeKind.GROUP);
+        setStatus("Indexing " + count + " groups under " + index + "...");
+
+        try (BulkIngester<Void> ingester = BulkIngester.of(b -> 
b.client(client).
+                
maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE)))
 {
+
+            for (int page = 0; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE); 
page++) {

Review Comment:
   ## Comparison of narrow type with wide type in loop condition
   
   Comparison between [expression](1) of type int and [expression](2) of wider 
type long.
   
   [Show more 
details](https://github.com/apache/syncope/security/code-scanning/2508)



##########
ext/opensearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/OpenSearchReindex.java:
##########
@@ -111,129 +158,140 @@
         return indexManager.defaultAuditMapping();
     }
 
+    protected Pair<String, Long> reindexRealms(final JobExecutionContext 
context) throws IOException {
+        indexManager.createRealmIndex(AuthContextUtils.getDomain(), 
realmSettings(), realmMapping());
+
+        long count = realmDAO.count();
+        String index = 
OpenSearchUtils.getRealmIndex(AuthContextUtils.getDomain());
+        setStatus("Indexing " + count + " realms under " + index + "...");
+
+        try (BulkIngester<Void> ingester = BulkIngester.of(b -> 
b.client(client).
+                
maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE)))
 {
+
+            for (int page = 0; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE); 
page++) {
+                Pageable pageable = PageRequest.of(page, 
AnyDAO.DEFAULT_PAGE_SIZE, DAO.DEFAULT_SORT);
+                for (Realm realm : realmDAO.findAll(pageable)) {
+                    ingester.add(op -> op.index(idx -> idx.
+                            index(index).
+                            id(realm.getKey()).
+                            document(utils.document(realm))));
+                }
+            }
+        } catch (Exception e) {
+            LOG.error("Errors while ingesting index {}", index, e);
+        }
+
+        return Pair.of(index, count);
+    }
+
+    protected Pair<String, Long> reindexUsers(final JobExecutionContext 
context) throws IOException {
+        indexManager.createAnyIndex(AuthContextUtils.getDomain(), 
AnyTypeKind.USER, userSettings(), userMapping());
+
+        long count = userDAO.count();
+        String index = 
OpenSearchUtils.getAnyIndex(AuthContextUtils.getDomain(), AnyTypeKind.USER);
+        setStatus("Indexing " + count + " users under " + index + "...");
+
+        try (BulkIngester<Void> ingester = BulkIngester.of(b -> 
b.client(client).
+                
maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE)))
 {
+
+            for (int page = 0; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE); 
page++) {
+                Pageable pageable = PageRequest.of(page, 
AnyDAO.DEFAULT_PAGE_SIZE, DAO.DEFAULT_SORT);
+                for (User user : userDAO.findAll(pageable)) {
+                    ingester.add(op -> op.index(idx -> idx.
+                            index(index).
+                            id(user.getKey()).
+                            document(utils.document(user))));
+                }
+            }
+        } catch (Exception e) {
+            LOG.error("Errors while ingesting index {}", index, e);
+        }
+
+        return Pair.of(index, count);
+    }
+
+    protected Pair<String, Long> reindexGroups(final JobExecutionContext 
context) throws IOException {
+        indexManager.createAnyIndex(AuthContextUtils.getDomain(), 
AnyTypeKind.GROUP, groupSettings(), groupMapping());
+
+        long count = groupDAO.count();
+        String index = 
OpenSearchUtils.getAnyIndex(AuthContextUtils.getDomain(), AnyTypeKind.GROUP);
+        setStatus("Indexing " + count + " groups under " + index + "...");
+
+        try (BulkIngester<Void> ingester = BulkIngester.of(b -> 
b.client(client).
+                
maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE)))
 {
+
+            for (int page = 0; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE); 
page++) {
+                Pageable pageable = PageRequest.of(page, 
AnyDAO.DEFAULT_PAGE_SIZE, DAO.DEFAULT_SORT);
+                for (Group group : groupDAO.findAll(pageable)) {
+                    ingester.add(op -> op.index(idx -> idx.
+                            index(index).
+                            id(group.getKey()).
+                            document(utils.document(group))));
+                }
+            }
+        } catch (Exception e) {
+            LOG.error("Errors while ingesting index {}", index, e);
+        }
+
+        return Pair.of(index, count);
+    }
+
+    protected Pair<String, Long> reindexAnyObjects(final JobExecutionContext 
context) throws IOException {
+        indexManager.createAnyIndex(
+                AuthContextUtils.getDomain(), AnyTypeKind.ANY_OBJECT, 
anyObjectSettings(), anyObjectMapping());
+
+        long count = anyObjectDAO.count();
+        String index = 
OpenSearchUtils.getAnyIndex(AuthContextUtils.getDomain(), 
AnyTypeKind.ANY_OBJECT);
+        setStatus("Indexing " + count + " any objects under " + index + "...");
+
+        try (BulkIngester<Void> ingester = BulkIngester.of(b -> 
b.client(client).
+                
maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE)))
 {
+
+            for (int page = 0; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE); 
page++) {

Review Comment:
   ## Comparison of narrow type with wide type in loop condition
   
   Comparison between [expression](1) of type int and [expression](2) of wider 
type long.
   
   [Show more 
details](https://github.com/apache/syncope/security/code-scanning/2509)



##########
ext/opensearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/OpenSearchReindex.java:
##########
@@ -111,129 +158,140 @@
         return indexManager.defaultAuditMapping();
     }
 
+    protected Pair<String, Long> reindexRealms(final JobExecutionContext 
context) throws IOException {

Review Comment:
   ## Useless parameter
   
   The parameter 'context' is never used.
   
   [Show more 
details](https://github.com/apache/syncope/security/code-scanning/2516)



##########
ext/opensearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/OpenSearchReindex.java:
##########
@@ -111,129 +158,140 @@
         return indexManager.defaultAuditMapping();
     }
 
+    protected Pair<String, Long> reindexRealms(final JobExecutionContext 
context) throws IOException {
+        indexManager.createRealmIndex(AuthContextUtils.getDomain(), 
realmSettings(), realmMapping());
+
+        long count = realmDAO.count();
+        String index = 
OpenSearchUtils.getRealmIndex(AuthContextUtils.getDomain());
+        setStatus("Indexing " + count + " realms under " + index + "...");
+
+        try (BulkIngester<Void> ingester = BulkIngester.of(b -> 
b.client(client).
+                
maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE)))
 {
+
+            for (int page = 0; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE); 
page++) {
+                Pageable pageable = PageRequest.of(page, 
AnyDAO.DEFAULT_PAGE_SIZE, DAO.DEFAULT_SORT);
+                for (Realm realm : realmDAO.findAll(pageable)) {
+                    ingester.add(op -> op.index(idx -> idx.
+                            index(index).
+                            id(realm.getKey()).
+                            document(utils.document(realm))));
+                }
+            }
+        } catch (Exception e) {
+            LOG.error("Errors while ingesting index {}", index, e);
+        }
+
+        return Pair.of(index, count);
+    }
+
+    protected Pair<String, Long> reindexUsers(final JobExecutionContext 
context) throws IOException {
+        indexManager.createAnyIndex(AuthContextUtils.getDomain(), 
AnyTypeKind.USER, userSettings(), userMapping());
+
+        long count = userDAO.count();
+        String index = 
OpenSearchUtils.getAnyIndex(AuthContextUtils.getDomain(), AnyTypeKind.USER);
+        setStatus("Indexing " + count + " users under " + index + "...");
+
+        try (BulkIngester<Void> ingester = BulkIngester.of(b -> 
b.client(client).
+                
maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE)))
 {
+
+            for (int page = 0; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE); 
page++) {
+                Pageable pageable = PageRequest.of(page, 
AnyDAO.DEFAULT_PAGE_SIZE, DAO.DEFAULT_SORT);
+                for (User user : userDAO.findAll(pageable)) {
+                    ingester.add(op -> op.index(idx -> idx.
+                            index(index).
+                            id(user.getKey()).
+                            document(utils.document(user))));
+                }
+            }
+        } catch (Exception e) {
+            LOG.error("Errors while ingesting index {}", index, e);
+        }
+
+        return Pair.of(index, count);
+    }
+
+    protected Pair<String, Long> reindexGroups(final JobExecutionContext 
context) throws IOException {

Review Comment:
   ## Useless parameter
   
   The parameter 'context' is never used.
   
   [Show more 
details](https://github.com/apache/syncope/security/code-scanning/2514)



##########
ext/opensearch/persistence/src/main/java/org/apache/syncope/core/persistence/opensearch/dao/OpenSearchAuditEventDAO.java:
##########
@@ -182,17 +179,15 @@
                 build();
         LOG.debug("Search request: {}", request);
 
-        List<Hit<ObjectNode>> esResult = null;
+        List<Hit<AuditEventTO>> osResult = null;
         try {
-            esResult = client.search(request, ObjectNode.class).hits().hits();
+            osResult = client.search(request, 
AuditEventTO.class).hits().hits();
         } catch (Exception e) {
             LOG.error("While searching in OpenSearch with request {}", 
request, e);
         }
 
-        return CollectionUtils.isEmpty(esResult)
+        return CollectionUtils.isEmpty(osResult)
                 ? List.of()
-                : esResult.stream().
-                        map(hit -> POJOHelper.convertValue(hit.source(), 
AuditEventTO.class)).
-                        filter(Objects::nonNull).toList();
+                : osResult.stream().map(Hit::source).toList();

Review Comment:
   ## Dereferenced variable may be null
   
   Variable [osResult](1) may be null at this access because of [this](2) 
assignment.
   
   [Show more 
details](https://github.com/apache/syncope/security/code-scanning/2511)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to