feat(auth): 0.5.0 passwordless group lookup ILdapGroupLookup (ScadaBridge#46)

ILdapGroupLookup.GetUserGroupsAsync(username, ct) re-reads a known user's
groups with the service account: same extraction, canonicalisation, endpoint
walk (FallbackServers), timeouts and TLS policy as AuthenticateAsync, via one
shared WalkEndpoints<T>. Explicit statuses: Found, UserNotFound, UserDisabled
(AD userAccountControl), AmbiguousUser, DirectoryUnavailable, NotSupported
(BindMode=User / no service account / foreign ILdapAuthService),
ProviderDisabled. AddZbLdapAuth registers it as the same singleton.

0.5.0 is the first published version carrying 0.4.2-0.4.4; scadaproj#51 was
live-verified against the NAM AD (24/24, identity check mutation-proven).

Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
Joseph Doherty
2026-11-12 20:10:40 -05:00
parent 3ca7e1936f
commit f5ef0efedd
10 changed files with 828 additions and 41 deletions
@@ -22,7 +22,8 @@ public static class ServiceCollectionExtensions
/// <summary>
/// Registers LDAP authentication: binds and validates <see cref="LdapOptions"/> from the
/// configuration section at <paramref name="sectionPath"/>, and registers
/// <see cref="ILdapAuthService"/>.
/// <see cref="ILdapAuthService"/> and (0.5.0) <see cref="ILdapGroupLookup"/> — both resolve to the
/// same <see cref="LdapAuthService"/> instance.
/// </summary>
/// <param name="services">The service collection to add to.</param>
/// <param name="config">The application configuration.</param>
@@ -60,6 +61,24 @@ public static class ServiceCollectionExtensions
sp.GetRequiredService<IOptions<LdapOptions>>().Value,
sp.GetService<Microsoft.Extensions.Logging.ILogger<LdapAuthService>>()));
// 0.5.0: the passwordless group lookup is the SAME instance as the auth service, so both share
// one sticky endpoint preference. A host that registered its own ILdapAuthService (a dev stub,
// a decorator) gets a lookup that answers NotSupported rather than a second, divergent client.
services.TryAddSingleton<ILdapGroupLookup>(sp =>
sp.GetRequiredService<ILdapAuthService>() as ILdapGroupLookup ?? UnsupportedLdapGroupLookup.Instance);
return services;
}
/// <summary>Answers every lookup with <see cref="LdapGroupLookupStatus.NotSupported"/>.</summary>
private sealed class UnsupportedLdapGroupLookup : ILdapGroupLookup
{
public static readonly UnsupportedLdapGroupLookup Instance = new();
public Task<LdapGroupLookupResult> GetUserGroupsAsync(string username, CancellationToken ct)
{
ct.ThrowIfCancellationRequested();
return Task.FromResult(LdapGroupLookupResult.Of(LdapGroupLookupStatus.NotSupported));
}
}
}