2021-04-19 22:30:27 +00:00
|
|
|
package ldap
|
|
|
|
|
|
|
|
import (
|
2021-05-04 19:49:15 +00:00
|
|
|
"sync"
|
|
|
|
|
2021-04-19 22:30:27 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"goauthentik.io/outpost/pkg/ak"
|
2021-05-04 19:49:15 +00:00
|
|
|
"goauthentik.io/outpost/pkg/models"
|
2021-04-19 22:30:27 +00:00
|
|
|
|
2021-05-04 19:49:15 +00:00
|
|
|
"github.com/nmcclain/ldap"
|
2021-04-19 22:30:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const GroupObjectClass = "group"
|
|
|
|
const UserObjectClass = "user"
|
|
|
|
|
2021-04-26 09:53:06 +00:00
|
|
|
type ProviderInstance struct {
|
2021-04-19 22:30:27 +00:00
|
|
|
BaseDN string
|
|
|
|
|
2021-04-26 09:53:06 +00:00
|
|
|
UserDN string
|
|
|
|
GroupDN string
|
|
|
|
|
2021-05-04 19:49:15 +00:00
|
|
|
appSlug string
|
|
|
|
flowSlug string
|
|
|
|
s *LDAPServer
|
|
|
|
log *log.Entry
|
|
|
|
|
|
|
|
boundUsersMutex sync.RWMutex
|
|
|
|
boundUsers map[string]UserFlags
|
|
|
|
}
|
|
|
|
|
|
|
|
type UserFlags struct {
|
|
|
|
UserInfo *models.User
|
|
|
|
CanSearch bool
|
2021-04-26 09:53:06 +00:00
|
|
|
}
|
2021-04-19 22:30:27 +00:00
|
|
|
|
2021-04-26 09:53:06 +00:00
|
|
|
type LDAPServer struct {
|
2021-04-19 22:30:27 +00:00
|
|
|
s *ldap.Server
|
|
|
|
log *log.Entry
|
|
|
|
ac *ak.APIController
|
2021-04-25 20:07:12 +00:00
|
|
|
|
2021-04-26 09:53:06 +00:00
|
|
|
providers []*ProviderInstance
|
2021-04-19 22:30:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewServer(ac *ak.APIController) *LDAPServer {
|
|
|
|
s := ldap.NewServer()
|
|
|
|
s.EnforceLDAP = true
|
|
|
|
ls := &LDAPServer{
|
2021-04-26 09:53:06 +00:00
|
|
|
s: s,
|
2021-04-26 13:35:56 +00:00
|
|
|
log: log.WithField("logger", "authentik.outpost.ldap"),
|
2021-04-26 09:53:06 +00:00
|
|
|
ac: ac,
|
|
|
|
providers: []*ProviderInstance{},
|
2021-04-19 22:30:27 +00:00
|
|
|
}
|
|
|
|
s.BindFunc("", ls)
|
|
|
|
s.SearchFunc("", ls)
|
|
|
|
return ls
|
|
|
|
}
|