From 40eb5e91d1140caa6313ec6d9aa69d3b6f75b9fa Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Tue, 1 Dec 2015 14:21:08 +1100 Subject: [PATCH 61/61] Ensure config store commits refresh file-based profile data The file-based LDAP profile subsystem does not update profiles correctly. Ensure that each commit of the underlying config store refreshes the profile inputs, outputs and policy objects. Part of: https://fedorahosted.org/pki/ticket/1700 --- .../cmscore/profile/AbstractProfileSubsystem.java | 39 +++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/base/server/cmscore/src/com/netscape/cmscore/profile/AbstractProfileSubsystem.java b/base/server/cmscore/src/com/netscape/cmscore/profile/AbstractProfileSubsystem.java index e93e090de9244a3a4ad4f17e0616cce5d65a978c..116b8e2026e80b012fb87647fd8924b567194fa3 100644 --- a/base/server/cmscore/src/com/netscape/cmscore/profile/AbstractProfileSubsystem.java +++ b/base/server/cmscore/src/com/netscape/cmscore/profile/AbstractProfileSubsystem.java @@ -22,12 +22,15 @@ import java.util.Enumeration; import java.util.Hashtable; import java.util.LinkedHashMap; +import com.netscape.certsrv.apps.CMS; import com.netscape.certsrv.base.EBaseException; import com.netscape.certsrv.base.IConfigStore; import com.netscape.certsrv.base.ISubsystem; import com.netscape.certsrv.profile.EProfileException; import com.netscape.certsrv.profile.IProfile; import com.netscape.certsrv.profile.IProfileSubsystem; +import com.netscape.certsrv.registry.IPluginInfo; +import com.netscape.certsrv.registry.IPluginRegistry; public abstract class AbstractProfileSubsystem implements IProfileSubsystem { protected static final String PROP_CHECK_OWNER = "checkOwner"; @@ -120,8 +123,42 @@ public abstract class AbstractProfileSubsystem implements IProfileSubsystem { */ public void commitProfile(String id) throws EProfileException { + IConfigStore cs = mProfiles.get(id).getConfigStore(); + + // first create a *new* profile object from the configStore + // and initialise it with the updated configStore + // + IPluginRegistry registry = (IPluginRegistry) + CMS.getSubsystem(CMS.SUBSYSTEM_REGISTRY); + String classId = mProfileClassIds.get(id); + IPluginInfo info = registry.getPluginInfo("profile", classId); + String className = info.getClassName(); + IProfile newProfile = null; try { - mProfiles.get(id).getConfigStore().commit(false); + newProfile = (IProfile) Class.forName(className).newInstance(); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + throw new EProfileException("Could not instantiate class '" + + classId + "' for profile '" + id + "': " + e); + } + newProfile.setId(id); + try { + newProfile.init(this, cs); + } catch (EBaseException e) { + throw new EProfileException( + "Failed to initialise profile '" + id + "': " + e); + } + + // next replace the existing profile with the new profile; + // this is to avoid any intermediate state where the profile + // is not fully initialised with its inputs, outputs and + // policy objects. + // + mProfiles.put(id, newProfile); + + // finally commit the configStore + // + try { + cs.commit(false); } catch (EBaseException e) { throw new EProfileException( "Failed to commit config store of profile '" + id + ": " + e, -- 2.5.0