Skip to content

Commit

Permalink
Fix #87
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvand committed Aug 20, 2019
1 parent c7daef4 commit a5c1646
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions LDAPCP/LDAPCP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,27 @@ protected bool Initialize(Uri context, string[] entityTypes)
globalConfiguration = GetConfiguration(context, entityTypes, PersistedObjectName, SPTrust.Name);
if (globalConfiguration == null)
{
ClaimsProviderLogging.Log($"[{ProviderInternalName}] Configuration '{PersistedObjectName}' was not foundin configuration database, use default configuration instead. Visit LDAPCP admin pages in central administration to create it.",
TraceSeverity.Unexpected, EventSeverity.Error, TraceCategory.Core);
// Run with default configuration, which creates a connection to connect to current AD domain
globalConfiguration = LDAPCPConfig.ReturnDefaultConfiguration(SPTrust.Name);
refreshConfig = true;
// There is no thread safety issue in reading this.CurrentConfiguration here, thanks to the lock Sync_Init
if (this.CurrentConfiguration == null)
{
ClaimsProviderLogging.Log($"[{ProviderInternalName}] Configuration '{PersistedObjectName}' was not found in configuration database, switch to default. Visit LDAPCP admin pages in central administration to create it.",
TraceSeverity.Unexpected, EventSeverity.Error, TraceCategory.Core);
// Run with default configuration, which creates a connection to connect to current AD domain
refreshConfig = true;
}
else
{
// Default configuration has only 1 connection to AD domain of current SP server.
// If its property LDAPConnection.RootContainer is null, it means that LDAPConnection properties were not set because it was previously done in a thread that did not run as application pool account (https://github.com/Yvand/LDAPCP/issues/87)
// If so, recreate defalt configuration
if (String.IsNullOrEmpty(this.CurrentConfiguration.LDAPConnectionsProp.First().RootContainer))
{
ClaimsProviderLogging.Log($"[{ProviderInternalName}] Default configuration was not fully initialized, recreating it...",
TraceSeverity.Unexpected, EventSeverity.Error, TraceCategory.Core);
refreshConfig = true;
}
}
}
else
{
Expand Down Expand Up @@ -1932,7 +1948,7 @@ public override string GetClaimTypeForUserKey()
protected override SPClaim GetUserKeyForEntity(SPClaim entity)
{
bool initSucceeded = false;

// Elevation of privileges when calling LDAPCP.Initialize is very important to prevent issue https://github.com/Yvand/LDAPCP/issues/87
SPSecurity.RunWithElevatedPrivileges(delegate ()
{
Expand Down

0 comments on commit a5c1646

Please sign in to comment.