From f366bd375dbee4ab6a44f39889a93a35b22c0d4e Mon Sep 17 00:00:00 2001
From: an-Peter Nilsson <notifications@github.com>
Date: Wed, 09 Sep 2020 15:06:58 +0000
Subject: [PATCH] FIX Replication status attributes for schema backend not read from disk https://github.com/OpenIdentityPlatform/OpenDJ/issues/140

---
 opendj-server-legacy/src/main/java/org/opends/server/schema/SchemaHandler.java |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/schema/SchemaHandler.java b/opendj-server-legacy/src/main/java/org/opends/server/schema/SchemaHandler.java
index 378d73f..8146514 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/schema/SchemaHandler.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/schema/SchemaHandler.java
@@ -147,6 +147,7 @@
    * Example: replication uses this to store its state and GenerationID.
    */
   private Map<String, Attribute> extraAttributes = new HashMap<>();
+  private Map<String, org.forgerock.opendj.ldap.Attribute> extraAttributesInitialize = new HashMap<>();
 
   /** Guards updates to the schema. */
   private final Lock exclusiveLock = new ReentrantLock();
@@ -224,6 +225,15 @@
       {
         throw new ConfigException(e.getMessageObject(), e);
       }
+
+      // Do attribute conversion after fully loading the schema
+      // otherwise attributes using types defined in the schema will not be properly converted
+      for (final Map.Entry<String, org.forgerock.opendj.ldap.Attribute> entry : extraAttributesInitialize.entrySet())
+      {
+        Attribute a = Converters.toAttribute(entry.getValue());
+        extraAttributes.put(entry.getKey(), a);
+      }
+      extraAttributesInitialize.clear();
   }
 
   /**
@@ -960,6 +970,15 @@
     final Entry entry = readSchemaEntry(schemaFile, readSchema);
     if (entry != null)
     {
+      for (org.forgerock.opendj.ldap.Attribute a : entry.getAllAttributes())
+      {
+        AttributeType attrType = a .getAttributeDescription().getAttributeType();
+        String attrName = attrType.getNameOrOID();
+        if (attrName.startsWith("ds-sync-") || attrName.equals("modifiersName") || attrName.equals("modifyTimestamp"))
+        {
+          extraAttributesInitialize.put(attrName, a);
+        }
+      }
       updateSchemaBuilderWithEntry(schemaBuilder, entry, schemaFile.getName(), failOnError);
     }
     return entry;

--
Gitblit v1.10.0