Have LDAP read from config

This commit is contained in:
Daniel Hall
2024-04-07 10:18:00 -07:00
parent 995c566131
commit b36f26e32a
7 changed files with 52 additions and 64 deletions

No files matched your search

+4 -1
View File
@@ -27,6 +27,7 @@ import (
"go.senan.xyz/gonic/db"
"go.senan.xyz/gonic/handlerutil"
"go.senan.xyz/gonic/lastfm"
"go.senan.xyz/gonic/ldap"
"go.senan.xyz/gonic/podcast"
"go.senan.xyz/gonic/scanner"
"go.senan.xyz/gonic/server/ctrladmin/adminui"
@@ -48,11 +49,12 @@ type Controller struct {
podcasts *podcast.Podcasts
lastfmClient *lastfm.Client
resolveProxyPath ProxyPathResolver
ldapConfig ldap.Config
}
type ProxyPathResolver func(in string) string
func New(dbc *db.DB, sessDB *gormstore.Store, scanner *scanner.Scanner, podcasts *podcast.Podcasts, lastfmClient *lastfm.Client, resolveProxyPath ProxyPathResolver) (*Controller, error) {
func New(dbc *db.DB, sessDB *gormstore.Store, scanner *scanner.Scanner, podcasts *podcast.Podcasts, lastfmClient *lastfm.Client, resolveProxyPath ProxyPathResolver, ldapConfig ldap.Config) (*Controller, error) {
c := Controller{
ServeMux: http.NewServeMux(),
@@ -62,6 +64,7 @@ func New(dbc *db.DB, sessDB *gormstore.Store, scanner *scanner.Scanner, podcasts
podcasts: podcasts,
lastfmClient: lastfmClient,
resolveProxyPath: resolveProxyPath,
ldapConfig: ldapConfig,
}
resp := respHandler(adminui.TemplatesFS, resolveProxyPath)
+1 -1
View File
@@ -21,7 +21,7 @@ func (c *Controller) ServeLoginDo(w http.ResponseWriter, r *http.Request) {
if user == nil || password != user.Password {
// Because internal authentication failed, we can now try to use LDAP, if
// it was enabled by the user.
ok, err := ldap.CheckLDAPcreds(username, password, c.dbc)
ok, err := ldap.CheckLDAPcreds(username, password, c.dbc, c.ldapConfig)
if err != nil {
sessAddFlashW(session, []string{err.Error()})
} else if !ok {