mirror of
https://github.com/goauthentik/authentik.git
synced 2026-06-17 19:09:11 +03:00
5727ae4271
* core, internal, packages: fix British spellings flagged by cspell Apply American spellings in Python docstrings/comments, Go log messages, a Rust doc comment, and a template comment (behaviour->behavior, initialise->initialize, finalise->finalize, etc.). Part of enabling cspell's British-spelling rule; the rule itself lands in a separate PR once all areas are clean. Co-Authored-By: Playpen Agent <279763771+playpen-agent@users.noreply.github.com> * gen Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io> Co-authored-by: Playpen Agent <279763771+playpen-agent@users.noreply.github.com> Co-authored-by: Jens Langhammer <jens@goauthentik.io>
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("initialized 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")
|
|
}
|
|
}
|