Skip to content

Commit

Permalink
Add method LDAPCPConfig.CreateDefaultConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvand committed Jul 8, 2019
1 parent 9b2d063 commit b182f3c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion LDAPCP.Tests/BackupCurrentConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion LDAPCP.Tests/UnitTestsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SPWebService>(String.Empty);
Expand Down
2 changes: 1 addition & 1 deletion LDAPCP/Features/LDAPCP/LDAPCP.EventReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
26 changes: 25 additions & 1 deletion LDAPCP/LDAPCPConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,17 +481,41 @@ public void ResetClaimTypesList()
TraceSeverity.High, EventSeverity.Information, TraceCategory.Core);
}

/// <summary>
/// Create LDAPCP configuration with default settings, and save it into configuration database. If it already exists, it will be deleted.
/// </summary>
/// <param name="spTrustName">Name of the SPTrustedLoginProvider that LDAPCP is associated with</param>
/// <returns></returns>
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);
}
}

/// <summary>
/// Create a persisted object with default configuration of LDAPCP. If it already exists, it will be deleted.
/// </summary>
/// <param name="persistedObjectID">GUID of persisted object</param>
/// <param name="persistedObjectName">Name of persisted object</param>
/// <param name="spTrustName">Name of the SPTrustedLoginProvider that LDAPCP is associated with</param>
/// <returns></returns>
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
Expand Down

0 comments on commit b182f3c

Please sign in to comment.