bugfix: Local users now work with a single usergroup (#486)

This commit is contained in:
James Read 2024-11-24 16:22:24 -05:00 committed by GitHub
parent f0b1cefb72
commit 476838d59a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 9 deletions

View File

@ -147,8 +147,8 @@ type AuthLocalUsersConfig struct {
type LocalUser struct {
Username string
Usergroup string
Password string
Groups []string
}
type OAuth2Provider struct {

View File

@ -114,8 +114,7 @@ func (api *oliveTinAPI) LocalUserLogin(ctx ctx.Context, req *pb.LocalUserLoginRe
match := checkUserPassword(cfg, req.Username, req.Password)
if match {
header := metadata.Pairs("set-user", req.Username)
grpc.SendHeader(ctx, header)
grpc.SendHeader(ctx, metadata.Pairs("set-username", req.Username))
log.WithFields(log.Fields{
"username": req.Username,

View File

@ -5,11 +5,12 @@ import (
"net/http"
"github.com/google/uuid"
"github.com/OliveTin/OliveTin/internal/config"
log "github.com/sirupsen/logrus"
)
var (
localUserSessions = make(map[string]string) // sid -> username, used for local user sessions
localUserSessions = make(map[string]*config.LocalUser)
)
func parseLocalUserCookie(req *http.Request) (string, string, string) {
@ -21,7 +22,7 @@ func parseLocalUserCookie(req *http.Request) (string, string, string) {
cookieValue := cookie.Value
username, ok := localUserSessions[cookieValue]
user, ok := localUserSessions[cookieValue]
if !ok {
log.WithFields(log.Fields{
@ -31,15 +32,31 @@ func parseLocalUserCookie(req *http.Request) (string, string, string) {
return "", "", ""
}
return username, "", cookie.Value
return user.Username, user.Usergroup, cookie.Value
}
func findUserByUsername(searchUsername string) *config.LocalUser {
for _, user := range cfg.AuthLocalUsers.Users {
if user.Username == searchUsername {
return user
}
}
return nil
}
func forwardResponseHandlerLoginLocalUser(md metadata.MD, w http.ResponseWriter) error {
setUser := getMetadataKeyOrEmpty(md, "set-user")
setUsername := getMetadataKeyOrEmpty(md, "set-username")
if setUsername != "" {
user := findUserByUsername(setUsername)
if user == nil {
return nil
}
if setUser != "" {
sid := uuid.NewString()
localUserSessions[sid] = setUser
localUserSessions[sid] = user
http.SetCookie(
w,