
* remove search_group Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make api operations cleaerer Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix migration Signed-off-by: Jens Langhammer <jens@goauthentik.io> * actually use get Signed-off-by: Jens Langhammer <jens@goauthentik.io> * use correct api client for ldap Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix migration Signed-off-by: Jens Langhammer <jens@goauthentik.io> * unrelated: fix migration warning Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add docs Signed-off-by: Jens Langhammer <jens@goauthentik.io> * update docs Signed-off-by: Jens Langhammer <jens@goauthentik.io> * unrelated: fix styling issue in dark mode Signed-off-by: Jens Langhammer <jens@goauthentik.io> * unrelated-ish fix button order in wizard Signed-off-by: Jens Langhammer <jens@goauthentik.io> * unrelated: fix missing css import Signed-off-by: Jens Langhammer <jens@goauthentik.io> * Optimised images with calibre/image-actions * Update index.md Co-authored-by: Tana M Berry <tanamarieberry@yahoo.com> Signed-off-by: Jens L. <jens@beryju.org> * Update index.md Co-authored-by: Tana M Berry <tanamarieberry@yahoo.com> Signed-off-by: Jens L. <jens@beryju.org> * Apply suggestions from code review Co-authored-by: Tana M Berry <tanamarieberry@yahoo.com> Signed-off-by: Jens L. <jens@beryju.org> * update release notes based on new template Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io> Signed-off-by: Jens L. <jens@beryju.org> Co-authored-by: authentik-automation[bot] <135050075+authentik-automation[bot]@users.noreply.github.com> Co-authored-by: Tana M Berry <tanamarieberry@yahoo.com>
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package direct
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
|
|
goldap "github.com/go-ldap/ldap/v3"
|
|
log "github.com/sirupsen/logrus"
|
|
"goauthentik.io/internal/outpost/flow"
|
|
"goauthentik.io/internal/outpost/ldap/server"
|
|
"goauthentik.io/internal/outpost/ldap/utils"
|
|
)
|
|
|
|
const ContextUserKey = "ak_user"
|
|
|
|
type DirectBinder struct {
|
|
si server.LDAPServerInstance
|
|
log *log.Entry
|
|
}
|
|
|
|
func NewDirectBinder(si server.LDAPServerInstance) *DirectBinder {
|
|
db := &DirectBinder{
|
|
si: si,
|
|
log: log.WithField("logger", "authentik.outpost.ldap.binder.direct"),
|
|
}
|
|
db.log.Info("initialised direct binder")
|
|
return db
|
|
}
|
|
|
|
func (db *DirectBinder) GetUsername(dn string) (string, error) {
|
|
if !utils.HasSuffixNoCase(dn, db.si.GetBaseDN()) {
|
|
return "", errors.New("invalid base DN")
|
|
}
|
|
dns, err := goldap.ParseDN(dn)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
for _, part := range dns.RDNs {
|
|
for _, attribute := range part.Attributes {
|
|
if strings.ToLower(attribute.Type) == "cn" {
|
|
return attribute.Value, nil
|
|
}
|
|
}
|
|
}
|
|
return "", errors.New("failed to find cn")
|
|
}
|
|
|
|
func (db *DirectBinder) TimerFlowCacheExpiry(ctx context.Context) {
|
|
fe := flow.NewFlowExecutor(ctx, db.si.GetAuthenticationFlowSlug(), db.si.GetAPIClient().GetConfig(), log.Fields{})
|
|
fe.Params.Add("goauthentik.io/outpost/ldap", "true")
|
|
fe.Params.Add("goauthentik.io/outpost/ldap-warmup", "true")
|
|
|
|
err := fe.WarmUp()
|
|
if err != nil {
|
|
db.log.WithError(err).Warning("failed to warm up flow cache")
|
|
}
|
|
}
|