diff --git a/CHANGELOG.md b/CHANGELOG.md index 6064c7e..7d155c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change log for LDAPCP +## Unreleased + +* Add method LDAPCPConfig.CreateDefaultConfiguration + ## LDAPCP 13.0.20190621.905 enhancements & bug-fixes - Published in June 21, 2019 * Add a default mapping to populate the email of groups diff --git a/LDAPCP.Tests/BackupCurrentConfig.cs b/LDAPCP.Tests/BackupCurrentConfig.cs index d529242..1f9aa96 100644 --- a/LDAPCP.Tests/BackupCurrentConfig.cs +++ b/LDAPCP.Tests/BackupCurrentConfig.cs @@ -20,7 +20,7 @@ public void Init() if (Config == null) { Trace.TraceWarning($"{DateTime.Now.ToString("s")} Configuration {UnitTestsHelper.ClaimsProviderConfigName} does not exist, create it with default settings..."); - Config = LDAPCPConfig.CreateConfiguration(ClaimsProviderConstants.CONFIG_ID, ClaimsProviderConstants.CONFIG_NAME, UnitTestsHelper.SPTrust.Name); + Config = LDAPCPConfig.CreateDefaultConfiguration(UnitTestsHelper.SPTrust.Name); } BackupConfig = Config.CopyConfiguration(); InitializeConfiguration(); diff --git a/LDAPCP.Tests/UnitTestsHelper.cs b/LDAPCP.Tests/UnitTestsHelper.cs index 42b9c1b..428a042 100644 --- a/LDAPCP.Tests/UnitTestsHelper.cs +++ b/LDAPCP.Tests/UnitTestsHelper.cs @@ -74,7 +74,7 @@ public static void InitializeSiteCollection() LDAPCPConfig config = LDAPCPConfig.GetConfiguration(UnitTestsHelper.ClaimsProviderConfigName, UnitTestsHelper.SPTrust.Name); if (config == null) { - LDAPCPConfig.CreateConfiguration(ClaimsProviderConstants.CONFIG_ID, ClaimsProviderConstants.CONFIG_NAME, SPTrust.Name); + LDAPCPConfig.CreateDefaultConfiguration(UnitTestsHelper.SPTrust.Name); } var service = SPFarm.Local.Services.GetValue(String.Empty); diff --git a/LDAPCP/Features/LDAPCP/LDAPCP.EventReceiver.cs b/LDAPCP/Features/LDAPCP/LDAPCP.EventReceiver.cs index 15dee17..82e020d 100644 --- a/LDAPCP/Features/LDAPCP/LDAPCP.EventReceiver.cs +++ b/LDAPCP/Features/LDAPCP/LDAPCP.EventReceiver.cs @@ -46,7 +46,7 @@ private void ExecBaseFeatureActivated(SPFeatureReceiverProperties properties) { LDAPCPConfig existingConfig = LDAPCPConfig.GetConfiguration(ClaimsProviderConstants.CONFIG_NAME); if (existingConfig == null) - LDAPCPConfig.CreateConfiguration(ClaimsProviderConstants.CONFIG_ID, ClaimsProviderConstants.CONFIG_NAME, spTrust.Name); + LDAPCPConfig.CreateDefaultConfiguration(spTrust.Name); else ClaimsProviderLogging.Log($"[{LDAPCP._ProviderInternalName}] Use configuration \"{ClaimsProviderConstants.CONFIG_NAME}\" found in the configuration database", TraceSeverity.High, EventSeverity.Information, ClaimsProviderLogging.TraceCategory.Configuration); } diff --git a/LDAPCP/LDAPCPConfig.cs b/LDAPCP/LDAPCPConfig.cs index 887372b..171686a 100644 --- a/LDAPCP/LDAPCPConfig.cs +++ b/LDAPCP/LDAPCPConfig.cs @@ -481,17 +481,41 @@ public void ResetClaimTypesList() TraceSeverity.High, EventSeverity.Information, TraceCategory.Core); } + /// + /// Create LDAPCP configuration with default settings, and save it into configuration database. If it already exists, it will be deleted. + /// + /// Name of the SPTrustedLoginProvider that LDAPCP is associated with + /// + public static LDAPCPConfig CreateDefaultConfiguration(string spTrustName) + { + if (String.IsNullOrEmpty(spTrustName)) + { + throw new ArgumentNullException("spTrustName"); + } + + SPTrustedLoginProvider spTrust = LDAPCP.GetSPTrustAssociatedWithCP(LDAPCP._ProviderInternalName); + if (spTrust == null) + { + return null; + } + else + { + return CreateConfiguration(ClaimsProviderConstants.CONFIG_ID, ClaimsProviderConstants.CONFIG_NAME, spTrust.Name); + } + } + /// /// Create a persisted object with default configuration of LDAPCP. If it already exists, it will be deleted. /// /// GUID of persisted object /// Name of persisted object + /// Name of the SPTrustedLoginProvider that LDAPCP is associated with /// public static LDAPCPConfig CreateConfiguration(string persistedObjectID, string persistedObjectName, string spTrustName) { if (String.IsNullOrEmpty(spTrustName)) { - throw new ArgumentNullException("spTrust"); + throw new ArgumentNullException("spTrustName"); } // Ensure it doesn't already exists and delete it if so