feat: LDAP-Test zeigt User-Tabelle mit Univention-UCS-Support

Nach erfolgreichem Verbindungstest werden bis zu 50 Benutzer (UID,
Name, E-Mail) in einer scrollbaren Tabelle angezeigt. Unterstützt
mailPrimaryAddress (Univention UCS) als Fallback für mail sowie
inetOrgPerson objectClass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sysops
2026-03-20 11:23:12 +01:00
parent 30c6694dff
commit 2da61689ea
3 changed files with 118 additions and 22 deletions
+48 -14
View File
@@ -23,14 +23,23 @@ type Config struct {
TLSSkipVerify bool
}
// LDAPUser is a preview entry returned by TestConnection.
type LDAPUser struct {
DN string `json:"dn"`
UID string `json:"uid"`
DisplayName string `json:"display_name"`
Mail string `json:"mail"`
}
// TestResult is the structured output of TestConnection.
type TestResult struct {
OK bool `json:"ok"`
Message string `json:"message"`
LatencyMS int64 `json:"latency_ms"`
ServerInfo string `json:"server_info"`
UsersFound int `json:"users_found"`
ErrorDetail string `json:"error_detail"`
OK bool `json:"ok"`
Message string `json:"message"`
LatencyMS int64 `json:"latency_ms"`
ServerInfo string `json:"server_info"`
UsersFound int `json:"users_found"`
Users []LDAPUser `json:"users"`
ErrorDetail string `json:"error_detail"`
}
// TestConnection opens a connection to the LDAP server, binds with the service
@@ -62,8 +71,8 @@ func TestConnection(cfg Config) TestResult {
// Query RootDSE for server info
serverInfo := queryRootDSE(conn)
// Count user objects (capped at 500 to avoid large result sets)
usersFound := countUsers(conn, cfg.BaseDN)
// Fetch user objects (capped at 500 for count, 50 for preview list)
usersFound, users := listUsers(conn, cfg.BaseDN)
return TestResult{
OK: true,
@@ -71,6 +80,7 @@ func TestConnection(cfg Config) TestResult {
LatencyMS: time.Since(start).Milliseconds(),
ServerInfo: serverInfo,
UsersFound: usersFound,
Users: users,
}
}
@@ -176,20 +186,44 @@ func queryRootDSE(conn *ldapv3.Conn) string {
return strings.Join(parts, " ")
}
// countUsers searches for person/user objects and returns the count (max 500).
func countUsers(conn *ldapv3.Conn, baseDN string) int {
// listUsers searches for person/user objects and returns the total count (max 500)
// plus a preview slice of up to 50 entries. Supports both AD (mail) and
// Univention UCS (mailPrimaryAddress) mail attributes.
func listUsers(conn *ldapv3.Conn, baseDN string) (int, []LDAPUser) {
req := ldapv3.NewSearchRequest(
baseDN,
ldapv3.ScopeWholeSubtree,
ldapv3.NeverDerefAliases,
500, 30, false,
"(|(objectClass=person)(objectClass=user))",
[]string{"dn"},
"(|(objectClass=person)(objectClass=user)(objectClass=inetOrgPerson))",
[]string{"dn", "uid", "cn", "displayName", "mail", "mailPrimaryAddress"},
nil,
)
res, err := conn.Search(req)
if err != nil {
return 0
return 0, nil
}
return len(res.Entries)
preview := make([]LDAPUser, 0, min(50, len(res.Entries)))
for i, e := range res.Entries {
if i >= 50 {
break
}
mail := e.GetAttributeValue("mail")
if mail == "" {
mail = e.GetAttributeValue("mailPrimaryAddress")
}
displayName := e.GetAttributeValue("displayName")
if displayName == "" {
displayName = e.GetAttributeValue("cn")
}
preview = append(preview, LDAPUser{
DN: e.DN,
UID: e.GetAttributeValue("uid"),
DisplayName: displayName,
Mail: mail,
})
}
return len(res.Entries), preview
}