Documentation
¶
Overview ¶
Package ldap provides a simple ldap client to authenticate, retrieve basic information and groups for a user.
Index ¶
- type LDAPClient
- func (lc *LDAPClient) Authenticate(username, password string) (bool, map[string]string, error)
- func (lc *LDAPClient) Close()
- func (lc *LDAPClient) Connect() error
- func (lc *LDAPClient) GetAllGroups() ([]string, error)
- func (lc *LDAPClient) GetAllUsers(userField string) ([]string, error)
- func (lc *LDAPClient) GetGroupsOfUser(username string) ([]string, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LDAPClient ¶
type LDAPClient struct {
Attributes []string
Base string
BindDN string
BindPassword string
GroupFilter string // e.g. "(memberUid=%s)"
Host string
ServerName string
UserFilter string // e.g. "(uid=%s)"
PageSize uint32
Conn *ldap.Conn
Port int
InsecureSkipVerify bool
UseSSL bool
SkipTLS bool
ClientCertificates []tls.Certificate // Adding client certificates
}
func (*LDAPClient) Authenticate ¶
Authenticate authenticates the user against the ldap backend.
Example ¶
ExampleLDAPClient_Authenticate shows how a typical application can verify a login attempt
client := setupClient()
ok, user, err := client.Authenticate("username", "password")
if err != nil {
log.Fatalf("Error authenticating user %s: %+v", "username", err)
}
if !ok {
log.Fatalf("Authenticating failed for user %s", "username")
}
log.Printf("User: %+v", user)
func (*LDAPClient) Connect ¶
func (lc *LDAPClient) Connect() error
Connect connects to the ldap backend.
func (*LDAPClient) GetAllGroups ¶
func (lc *LDAPClient) GetAllGroups() ([]string, error)
GetAllGroups returns all the available groups
Example ¶
ExampleLDAPClient_GetAllGroups shows how to retrieve all groups
client := setupClient()
groups, err := client.GetAllGroups()
if err != nil {
log.Fatalf("Error getting groups: %+v", err)
}
log.Printf("Groups: %+v", groups)
func (*LDAPClient) GetAllUsers ¶
func (lc *LDAPClient) GetAllUsers(userField string) ([]string, error)
GetAllUsers returns all users
Example ¶
ExampleLDAPClient_GetAllUsers shows how to retrieve all users
client := setupClient()
users, err := client.GetAllUsers("sAMAccountName")
if err != nil {
log.Fatalf("Error getting users: %+v", err)
}
log.Printf("Users: %+v", users)
func (*LDAPClient) GetGroupsOfUser ¶
func (lc *LDAPClient) GetGroupsOfUser(username string) ([]string, error)
GetGroupsOfUser returns the group for a user.
Example ¶
ExampleLDAPClient_GetGroupsOfUser shows how to retrieve user groups
client := setupClient()
groups, err := client.GetGroupsOfUser("username")
if err != nil {
log.Fatalf("Error getting groups for user %s: %+v", "username", err)
}
log.Printf("Groups: %+v", groups)
Click to show internal directories.
Click to hide internal directories.