Path: redb-identity/src/redb.Identity.Ldap/LdapSyncOptions.cs
Snapshot: redb-identity, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-identity
Page: https://redbase.app/src/dev-2026-12-06/redb-identity/src/redb.Identity.Ldap/LdapSyncOptions.cs
----
namespace redb.Identity.Ldap;
///
/// Configuration for the LDAP directory sync route (Watch consumer).
/// Extends connection settings with sync-specific options.
///
public sealed class LdapSyncOptions : LdapConnectionSettings
{
/// Route identifier. Default: "ldap-sync".
public string RouteId { get; set; } = "ldap-sync";
// ── Search ──
/// Base DN for user search.
public string UserBaseDn { get; set; } = "";
/// LDAP filter for user entries. Default: "(objectClass=inetOrgPerson)".
public string UserFilter { get; set; } = "(objectClass=inetOrgPerson)";
/// LDAP attributes to request.
public string[] Attributes { get; set; } = [];
// ── Change tracking ──
/// Poll interval in milliseconds. Default: 60000 (1 min).
public int PollIntervalMs { get; set; } = 60_000;
/// Change tracking mode. Default: ModifyTimestamp.
public string ChangeTrackingMode { get; set; } = "ModifyTimestamp";
/// Load all entries on first poll. Default: true.
public bool InitialLoad { get; set; } = true;
/// Detect deleted entries. Default: true.
public bool DetectDeletions { get; set; } = true;
/// Full sync interval in poll cycles (for deletion detection). Default: 10.
public int FullSyncInterval { get; set; } = 10;
// ── Identity integration ──
/// Provider name stored in user's ExternalProvider field. Default: "ldap-sync".
public string ProviderName { get; set; } = "ldap-sync";
///
/// Attribute map for converting LDAP entries to user profiles.
/// Keys: "externalId", "displayName", "email", "phone", "givenName", "familyName".
///
public Dictionary AttributeMap { get; set; } = new(StringComparer.OrdinalIgnoreCase);
/// Extra LDAP attributes mapped to custom claims.
public Dictionary AdditionalClaimsMap { get; set; } = new(StringComparer.OrdinalIgnoreCase);
/// Enable group sync from memberOf attribute. Default: false.
public bool SyncGroups { get; set; }
/// Group mapper options (used when SyncGroups = true).
public LdapGroupMapperOptions GroupMapperOptions { get; set; } = new();
/// Whether to disable users when they are deleted from LDAP. Default: true.
public bool DisableDeletedUsers { get; set; } = true;
private static readonly HashSet ValidTrackingModes = new(StringComparer.OrdinalIgnoreCase)
{
"ModifyTimestamp", "Usn", "Persistent"
};
public void Validate()
{
ValidateConnection();
if (string.IsNullOrWhiteSpace(UserBaseDn))
throw new InvalidOperationException("LdapSyncOptions.UserBaseDn is required.");
if (PollIntervalMs <= 0)
throw new InvalidOperationException(
$"LdapSyncOptions.PollIntervalMs must be positive, got: {PollIntervalMs}.");
if (!ValidTrackingModes.Contains(ChangeTrackingMode))
throw new InvalidOperationException(
$"LdapSyncOptions.ChangeTrackingMode '{ChangeTrackingMode}' is not valid. Use: {string.Join(", ", ValidTrackingModes)}.");
}
}