Skip to content

Commit

Permalink
Add command line utility for querying LDAP and manual testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jtblin committed Dec 5, 2016
1 parent 993d307 commit ad9f2ea
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test.sh
61 changes: 61 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"flag"
"log"

"github.com/jtblin/go-ldap-client"
)

var base, bindDN, bindPassword, groupFilter, host, password, serverName, userFilter, username string
var port int
var useSSL bool

type server struct{}

func main() {
flag.Parse()

client := &ldap.LDAPClient{
Base: base,
Host: host,
Port: port,
UseSSL: useSSL,
BindDN: bindDN,
BindPassword: bindPassword,
UserFilter: userFilter,
GroupFilter: groupFilter,
Attributes: []string{"givenName", "sn", "mail", "uid"},
ServerName: serverName,
}
defer client.Close()

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)

groups, err := client.GetGroupsOfUser(username)
if err != nil {
log.Fatalf("Error getting groups for user %s: %+v", username, err)
}
log.Printf("Groups: %+v", groups)
}

func init() {
flag.StringVar(&base, "base", "dc=example,dc=com", "Base LDAP")
flag.StringVar(&bindDN, "bind-dn", "uid=readonlysuer,ou=People,dc=example,dc=com", "Bind DN")
flag.StringVar(&bindPassword, "bind-pwd", "readonlypassword", "Bind password")
flag.StringVar(&groupFilter, "group-filter", "(memberUid=%s)", "Group filter")
flag.StringVar(&host, "host", "ldap.example.com", "LDAP host")
flag.StringVar(&password, "password", "", "Password")
flag.IntVar(&port, "port", 389, "LDAP port")
flag.StringVar(&userFilter, "user-filter", "(uid=%s)", "User filter")
flag.StringVar(&username, "username", "", "Username")
flag.StringVar(&serverName, "server-name", "", "Server name for SSL (if use-ssl is set)")
flag.BoolVar(&useSSL, "use-ssl", false, "Use SSL")
}

0 comments on commit ad9f2ea

Please sign in to comment.