Skip to content

Commit

Permalink
ldap missing ID and idp fix (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
madsi1m authored and labkode committed Dec 4, 2019
1 parent 825f8b1 commit 9d163b2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/fatih/color v1.7.0 // indirect
github.com/go-openapi/strfmt v0.19.2 // indirect
github.com/gofrs/uuid v3.2.0+incompatible
github.com/gogo/protobuf v1.2.0 // indirect
github.com/golang/protobuf v1.3.2
github.com/gomodule/redigo v2.0.0+incompatible
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4
Expand All @@ -24,17 +25,20 @@ require (
github.com/pkg/errors v0.8.1
github.com/pkg/xattr v0.4.1
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829 // indirect
github.com/rs/cors v1.7.0
github.com/rs/zerolog v1.17.2
go.opencensus.io v0.22.1
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 // indirect
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 // indirect
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421
google.golang.org/grpc v1.25.1
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.27 // indirect
gopkg.in/ldap.v2 v2.5.1
gopkg.in/square/go-jose.v2 v2.2.2 // indirect
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc // indirect
)

go 1.13
5 changes: 2 additions & 3 deletions pkg/auth/manager/ldap/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type config struct {
Filter string `mapstructure:"filter"`
BindUsername string `mapstructure:"bind_username"`
BindPassword string `mapstructure:"bind_password"`
Idp string `mapstructure:"idp"`
Schema attributes `mapstructure:"schema"`
}

Expand Down Expand Up @@ -137,9 +138,7 @@ func (am *mgr) Authenticate(ctx context.Context, clientID, clientSecret string)
u := &user.User{
// TODO(jfd) clean up idp = iss, sub = opaque ... is redundant
Id: &user.UserId{
// TODO(jfd): how do we determine the issuer for ldap? ... make configurable
Idp: fmt.Sprintf("%s:%d", am.c.Hostname, am.c.Port),
// TODO(jfd): objectguid, entryuuid etc ... make configurable
Idp: am.c.Idp,
OpaqueId: sr.Entries[0].GetAttributeValue(am.c.Schema.UID),
},
// Subject: claims.Sub, // TODO(labkode) remove from CS3, is in Id
Expand Down
11 changes: 11 additions & 0 deletions pkg/user/manager/ldap/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type manager struct {
filter string
bindUsername string
bindPassword string
idp string
schema attributes
}

Expand All @@ -54,6 +55,7 @@ type config struct {
Filter string `mapstructure:"filter"`
BindUsername string `mapstructure:"bind_username"`
BindPassword string `mapstructure:"bind_password"`
Idp string `mapstructure:"idp"`
Schema attributes `mapstructure:"schema"`
}

Expand Down Expand Up @@ -98,6 +100,7 @@ func New(m map[string]interface{}) (user.Manager, error) {
filter: c.Filter,
bindUsername: c.BindUsername,
bindPassword: c.BindPassword,
idp: c.Idp,
schema: c.Schema,
}, nil
}
Expand Down Expand Up @@ -137,6 +140,10 @@ func (m *manager) GetUser(ctx context.Context, uid *userpb.UserId) (*userpb.User
log.Debug().Interface("entries", sr.Entries).Msg("entries")

return &userpb.User{
Id: &userpb.UserId{
Idp: m.idp,
OpaqueId: uid.OpaqueId,
},
Username: sr.Entries[0].GetAttributeValue(m.schema.UID),
Groups: []string{},
Mail: sr.Entries[0].GetAttributeValue(m.schema.Mail),
Expand Down Expand Up @@ -175,6 +182,10 @@ func (m *manager) FindUsers(ctx context.Context, query string) ([]*userpb.User,

for _, entry := range sr.Entries {
user := &userpb.User{
Id: &userpb.UserId{
Idp: m.idp,
OpaqueId: sr.Entries[0].GetAttributeValue(m.schema.UID),
},
Username: entry.GetAttributeValue(m.schema.UID),
Groups: []string{},
Mail: sr.Entries[0].GetAttributeValue(m.schema.Mail),
Expand Down

0 comments on commit 9d163b2

Please sign in to comment.