Only allow use of subsonic API with one auth method
This commit is contained in:
+30
-10
@@ -241,20 +241,17 @@ func withUser(dbc *db.DB, ldapConfig ldap.Config) handlerutil.Middleware {
|
|||||||
"please provide `t` and `s`, or just `p`"))
|
"please provide `t` and `s`, or just `p`"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
user := dbc.GetUserByName(username)
|
user := dbc.GetUserByName(username)
|
||||||
|
|
||||||
var credsOk bool
|
if ldapConfig.IsSetup() {
|
||||||
if tokenAuth && user != nil {
|
// Complete auth using LDAP
|
||||||
credsOk = checkCredsToken(user.Password, token, salt)
|
log.Println("Authenticating using LDAP ...")
|
||||||
} else if user != nil {
|
|
||||||
credsOk = checkCredsBasic(user.Password, password)
|
|
||||||
}
|
|
||||||
if !credsOk {
|
|
||||||
// Because internal authentication failed, we can now try to use LDAP,
|
|
||||||
// if it was enabled by the user.
|
|
||||||
ok, err := ldap.CheckLDAPcreds(username, password, dbc, ldapConfig)
|
ok, err := ldap.CheckLDAPcreds(username, password, dbc, ldapConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = writeResp(w, r, spec.NewError(40, err.Error()))
|
log.Println("Failed to check LDAP creds:", err)
|
||||||
|
_ = writeResp(w, r, spec.NewError(40, "invalid password"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,7 +259,30 @@ func withUser(dbc *db.DB, ldapConfig ldap.Config) handlerutil.Middleware {
|
|||||||
_ = writeResp(w, r, spec.NewError(40, "invalid password"))
|
_ = writeResp(w, r, spec.NewError(40, "invalid password"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
withUser := context.WithValue(r.Context(), CtxUser, user)
|
||||||
|
next.ServeHTTP(w, r.WithContext(withUser))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("Authenticating using built-in ...")
|
||||||
|
if user == nil {
|
||||||
|
_ = writeResp(w, r, spec.NewError(40, "invalid password"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var credsOk bool
|
||||||
|
if tokenAuth {
|
||||||
|
credsOk = checkCredsToken(user.Password, token, salt)
|
||||||
|
} else {
|
||||||
|
credsOk = checkCredsBasic(user.Password, password)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !credsOk {
|
||||||
|
_ = writeResp(w, r, spec.NewError(40, "invalid password"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
withUser := context.WithValue(r.Context(), CtxUser, user)
|
withUser := context.WithValue(r.Context(), CtxUser, user)
|
||||||
next.ServeHTTP(w, r.WithContext(withUser))
|
next.ServeHTTP(w, r.WithContext(withUser))
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user