Path: redb-route/redb.Route.Ldap/LdapEndpointOptions.cs
Snapshot: redb-route, 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-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Ldap/LdapEndpointOptions.cs
----
using redb.Route.Core;
namespace redb.Route.Ldap;
///
/// Typed options for LDAP endpoint. Bound from URI query parameters.
///
public sealed class LdapEndpointOptions : EndpointOptions
{
// ── Connection ──
/// LDAP server hostname or IP.
public string Server { get; set; } = "localhost";
/// LDAP port (389 for plain, 636 for LDAPS).
public int Port { get; set; } = 389;
/// Use LDAPS (SSL/TLS from the start, typically port 636).
public bool Ssl { get; set; }
/// Use STARTTLS upgrade on the plain port (389).
public bool StartTls { get; set; }
/// Named connection factory from the registry.
[RegistryReference(typeof(LdapConnectionFactory))]
public string? ConnectionFactory { get; set; }
/// Connection timeout in milliseconds.
public int ConnectTimeout { get; set; } = 5000;
/// Operation timeout in milliseconds.
public int OperationTimeout { get; set; } = 30000;
// ── Auth (service account) ──
/// Bind DN for service account authentication.
public string? BindDn { get; set; }
/// Password for service account authentication.
[Sensitive]
public string? BindPassword { get; set; }
// ── Search ──
///
/// LDAP filter expression, e.g. (objectClass=user).
/// Supports ${...} expressions via for per-request resolution.
///
public DynamicValue? Filter { get; set; }
/// Search scope: base, onelevel, or subtree (default).
public string Scope { get; set; } = "subtree";
/// Comma-separated list of attributes to return, e.g. cn,mail,sAMAccountName.
public string? Attributes { get; set; }
/// Page size for paged search results (default 500).
public int PageSize { get; set; } = 500;
/// Server-side maximum number of entries to return (0 = unlimited).
public int SizeLimit { get; set; }
/// Server-side time limit in seconds (0 = unlimited).
public int TimeLimit { get; set; }
// ── Consumer (Watch) ──
/// Poll interval in milliseconds for the Watch consumer (default 60000).
public int PollInterval { get; set; } = 60000;
/// Change tracking mode: modifyTimestamp, usn, or persistent.
public string ChangeTrackingMode { get; set; } = "modifyTimestamp";
/// Load all matching entries on consumer startup.
public bool InitialLoad { get; set; }
/// Detect deleted entries by comparing known DNs with current search results (opt-in).
public bool DetectDeletions { get; set; }
/// Number of poll cycles between full synchronizations for deletion detection (default 10).
public int FullSyncInterval { get; set; } = 10;
// ── Protocol ──
/// LDAP protocol version (default 3).
public int ProtocolVersion { get; set; } = 3;
/// Follow LDAP referrals automatically.
public bool FollowReferrals { get; set; } = true;
// ── Pool ──
/// Maximum number of connections in the pool.
public int MaxConnections { get; set; } = 10;
// ── SSL options ──
/// Skip server certificate validation (development only!).
public bool TrustAllCertificates { get; set; }
/// Path to client certificate for mutual TLS.
public string? ClientCertPath { get; set; }
/// Password for client certificate.
[Sensitive]
public string? ClientCertPassword { get; set; }
///
protected override string? UnknownParameterHint(string name)
=> name.Equals("skipCertificateValidation", StringComparison.OrdinalIgnoreCase)
? "'skipCertificateValidation' is renamed 'trustAllCertificates', the name every other connector uses."
: null;
///
public override void Validate()
{
if (string.IsNullOrWhiteSpace(Server))
throw new ArgumentException("LDAP server is required.", nameof(Server));
if (Port is <= 0 or > 65535)
throw new ArgumentOutOfRangeException(nameof(Port), Port, "Port must be between 1 and 65535.");
if (Ssl && StartTls)
throw new InvalidOperationException("Ssl and StartTls are mutually exclusive. Use Ssl for LDAPS (port 636) or StartTls for upgrading a plain connection (port 389).");
if (PageSize < 0)
throw new ArgumentOutOfRangeException(nameof(PageSize), PageSize, "PageSize must be >= 0 (0 disables paged results).");
if (MaxConnections <= 0)
throw new ArgumentOutOfRangeException(nameof(MaxConnections), MaxConnections, "MaxConnections must be > 0.");
if (ConnectTimeout <= 0)
throw new ArgumentOutOfRangeException(nameof(ConnectTimeout), ConnectTimeout, "ConnectTimeout must be > 0.");
if (OperationTimeout <= 0)
throw new ArgumentOutOfRangeException(nameof(OperationTimeout), OperationTimeout, "OperationTimeout must be > 0.");
if (PollInterval <= 0)
throw new ArgumentOutOfRangeException(nameof(PollInterval), PollInterval, "PollInterval must be > 0.");
if (FullSyncInterval <= 0)
throw new ArgumentOutOfRangeException(nameof(FullSyncInterval), FullSyncInterval, "FullSyncInterval must be > 0.");
}
///
/// Parses the string into a enum.
///
internal LdapSearchScope ParseScope() => Scope?.ToLowerInvariant() switch
{
"base" => LdapSearchScope.Base,
"onelevel" or "one" => LdapSearchScope.OneLevel,
_ => LdapSearchScope.Subtree
};
///
/// Parses the CSV string into an array.
/// Returns null if no specific attributes are requested (= return all).
///
internal string[]? ParseAttributes() =>
string.IsNullOrWhiteSpace(Attributes) ? null : Attributes.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
///
/// Parses the string into enum.
///
internal LdapChangeTrackingMode ParseChangeTrackingMode() => ChangeTrackingMode?.ToLowerInvariant() switch
{
"usn" => LdapChangeTrackingMode.Usn,
"persistent" => LdapChangeTrackingMode.Persistent,
_ => LdapChangeTrackingMode.ModifyTimestamp
};
///
/// Gets the effective LDAP port: if SSL is enabled and default port is still 389, switch to 636.
///
internal int EffectivePort => Ssl && Port == 389 ? 636 : Port;
}