Skip to content

Commit

Permalink
Always use TLS for ldap user driver
Browse files Browse the repository at this point in the history
  • Loading branch information
labkode committed Jan 18, 2017
1 parent 1a12fa4 commit 7ba6a52
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions root/ldapuserdriver/ldapuserdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
)

import (
"crypto/tls"
"github.com/clawio/clawiod/root"
"github.com/go-kit/kit/log/levels"
"gopkg.in/ldap.v2"
Expand Down Expand Up @@ -41,23 +42,14 @@ func New(logger levels.Levels,
}

func (c *driver) GetByCredentials(username, password string) (root.User, error) {
l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", c.hostname, c.port))
l, err := ldap.DialTLS("tcp", fmt.Sprintf("%s:%d", c.hostname, c.port), &tls.Config{InsecureSkipVerify: true})
if err != nil {
c.logger.Error().Log("error", err)
return nil, err
}
defer l.Close()
c.logger.Info().Log("msg", "connection stablished")

// Reconnect with TLS
/*
err = l.StartTLS(&tls.Config{InsecureSkipVerify: true})
if err != nil {
c.logger.Error().Log("error", err)
return nil, err
}
*/

// First bind with a read only user
err = l.Bind(c.bindUsername, c.bindPassword)
if err != nil {
Expand All @@ -69,7 +61,6 @@ func (c *driver) GetByCredentials(username, password string) (root.User, error)
searchRequest := ldap.NewSearchRequest(
c.baseDN,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
//fmt.Sprintf("(&(objectClass=user)&(samaccountname=%s))", username),
fmt.Sprintf(c.filter, username),
[]string{"dn"},
nil,
Expand All @@ -96,6 +87,7 @@ func (c *driver) GetByCredentials(username, password string) (root.User, error)
c.logger.Error().Log("error", err)
return nil, err
}
c.logger.Info().Log("msg", "binding ok")

// TODO(labkode) Get more attrs from LDAP query like email and displayName at least
u := &user{
Expand Down

0 comments on commit 7ba6a52

Please sign in to comment.