ldap

package
v0.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoUserFound = errors.New("no LDAP entries found for user")
)

Functions

This section is empty.

Types

type Client

type Client interface {
	GetGroupData(ctx context.Context, groupDN string) ([]SyncUser, error)
	GetUserByEmail(ctx context.Context, email string) (map[string]any, error)
	GetUserByID(ctx context.Context, userID string) (map[string]any, error)
}

Client defines the interface for LDAP operations used by the gdrive package.

func InitLDAP

func InitLDAP(config Config) (Client, error)

InitLDAP initializes a connection to the LDAP server using the provided configuration.

type Config

type Config struct {
	// Server is the LDAP server URL (e.g., "ldap://ldap.example.com:389").
	Server string `yaml:"server" json:"server"`
	// GroupDN is the base DN for group searches.
	GroupDN string `yaml:"groupDN" json:"groupDN"`
	// UserDN is the DN template for user lookups (must contain %s for the user ID).
	UserDN string `yaml:"userDN" json:"userDN"`
	// BaseUserDN is the base DN for user searches.
	BaseUserDN string `yaml:"baseUserDN" json:"baseUserDN"`
	// UserSearchFilter is the LDAP filter for user searches (e.g., "(objectClass=person)").
	UserSearchFilter string `yaml:"userSearchFilter" json:"userSearchFilter"`
	// EmailAttribute is the LDAP attribute containing user email addresses (e.g., "mail").
	EmailAttribute string `yaml:"emailAttribute" json:"emailAttribute"`
	// Attributes is the list of LDAP attributes to retrieve.
	Attributes []string `yaml:"attributes" json:"attributes"`
}

Config holds configuration for connecting to an LDAP server.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with generic LDAP defaults.

type LDAPConn

type LDAPConn struct {
	// contains filtered or unexported fields
}

LDAPConn manages an LDAP connection and provides query methods.

func (*LDAPConn) GetBaseUserDN

func (l *LDAPConn) GetBaseUserDN() string

GetBaseUserDN returns the base user DN.

func (*LDAPConn) GetGroupDN

func (l *LDAPConn) GetGroupDN() string

GetGroupDN returns the group DN.

func (*LDAPConn) GetGroupData

func (l *LDAPConn) GetGroupData(_ context.Context, groupName string) ([]SyncUser, error)

GetGroupData retrieves all members of an LDAP group by its common name.

func (*LDAPConn) GetUserByEmail

func (l *LDAPConn) GetUserByEmail(ctx context.Context, email string) (map[string]any, error)

GetUserByEmail retrieves user data from LDAP using an email address. It searches the base user DN subtree using the configured email attribute.

func (*LDAPConn) GetUserByID

func (l *LDAPConn) GetUserByID(ctx context.Context, userID string) (map[string]any, error)

GetUserByID retrieves user data from LDAP using a user ID. It constructs the user DN from the configured template and performs a base object search.

func (*LDAPConn) GetUserDN

func (l *LDAPConn) GetUserDN() string

GetUserDN returns the user DN template.

type LDAPConnClient

type LDAPConnClient interface {
	IsClosing() bool
	Search(*ldap.SearchRequest) (*ldap.SearchResult, error)
	UnauthenticatedBind(username string) error
}

LDAPConnClient abstracts the underlying LDAP connection for testability.

type SyncUser

type SyncUser struct {
	UID string
}

SyncUser represents a user resolved from an LDAP group membership.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL