Skip to content

Commit

Permalink
Add helper methods to get/delete a directory connection in the config…
Browse files Browse the repository at this point in the history
…uration
  • Loading branch information
Yvand committed May 7, 2024
1 parent d57f979 commit ab6b8a6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Add the property MaxSearchResultsCount, to override the SharePoint limit of the maximum number of objects that the LDAP server returns - https://github.com/Yvand/LDAPCP/issues/209
* Correctly initialize LDAP-specific properties with their actual value, instead of the default value of the type - https://github.com/Yvand/LDAPCP/pull/212
* Fix an NullReferenceException in a very rare scenario where ClaimsPrincipal.Identity is null
* Add helper methods to get/delete a directory connection in the configuration

## LDAPCP Second Edition v17.0.20240226.2 - Published in February 26, 2024

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.DirectoryServices.Protocols;
using System.Linq;
using Yvand.LdapClaimsProvider.Logging;

Expand Down Expand Up @@ -423,6 +424,39 @@ protected virtual ILdapProviderSettings GenerateSettingsFromCurrentConfiguration
return (ILdapProviderSettings)entityProviderSettings;
}

/// <summary>
/// Gets the directory configuration
/// </summary>
/// <param name="directoryConnectionPath">Directory path</param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public DirectoryConnection GetLdapConnection(string directoryConnectionPath)
{
if (String.IsNullOrWhiteSpace(directoryConnectionPath))
{
throw new ArgumentNullException(nameof(directoryConnectionPath));
}
return this.LdapConnections.FirstOrDefault(x => x.LdapPath.Equals(directoryConnectionPath, StringComparison.OrdinalIgnoreCase));
}

/// <summary>
/// Deletes the directory configuration
/// </summary>
/// <param name="directoryConnectionPath">Directory path</param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public bool DeleteLdapConnection(string directoryConnectionPath)
{
if (String.IsNullOrWhiteSpace(directoryConnectionPath))
{
throw new ArgumentNullException(nameof(directoryConnectionPath));
}

DirectoryConnection directory = GetLdapConnection(directoryConnectionPath);
if (directory == null) { return false; }
return this.LdapConnections.Remove(directory);
}

/// <summary>
/// If it is valid, commits the current settings to the SharePoint settings database
/// </summary>
Expand Down

0 comments on commit ab6b8a6

Please sign in to comment.