mirror of
https://github.com/bolkedebruin/rdpgw.git
synced 2026-03-29 23:16:37 +00:00
Fix username replacement
This commit is contained in:
@@ -48,7 +48,6 @@ func (c *Config) BasicAuth(next http.HandlerFunc) http.HandlerFunc {
|
|||||||
log.Printf("User %s is not authenticated for this service", username)
|
log.Printf("User %s is not authenticated for this service", username)
|
||||||
} else {
|
} else {
|
||||||
ctx := context.WithValue(r.Context(), "preferred_username", username)
|
ctx := context.WithValue(r.Context(), "preferred_username", username)
|
||||||
ctx = context.WithValue(ctx, "access_token", "EMPTY")
|
|
||||||
next.ServeHTTP(w, r.WithContext(ctx))
|
next.ServeHTTP(w, r.WithContext(ctx))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,13 +21,19 @@ func CheckHost(ctx context.Context, host string) (bool, error) {
|
|||||||
// todo get from context?
|
// todo get from context?
|
||||||
return false, errors.New("cannot verify host in 'signed' mode as token data is missing")
|
return false, errors.New("cannot verify host in 'signed' mode as token data is missing")
|
||||||
case "roundrobin", "unsigned":
|
case "roundrobin", "unsigned":
|
||||||
|
var username string
|
||||||
|
|
||||||
log.Printf("Checking host")
|
log.Printf("Checking host")
|
||||||
s := getSessionInfo(ctx)
|
s := getSessionInfo(ctx)
|
||||||
if s == nil {
|
if s == nil {
|
||||||
return false, errors.New("no valid session info found in context")
|
var ok bool
|
||||||
|
username, ok = ctx.Value("preferred_username").(string)
|
||||||
|
if !ok {
|
||||||
|
return false, errors.New("no valid session info or username found in context")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for _, h := range Hosts {
|
for _, h := range Hosts {
|
||||||
if s.UserName != "" {
|
if username != "" {
|
||||||
h = strings.Replace(h, "{{ preferred_username }}", s.UserName, 1)
|
h = strings.Replace(h, "{{ preferred_username }}", s.UserName, 1)
|
||||||
}
|
}
|
||||||
if h == host {
|
if h == host {
|
||||||
|
|||||||
Reference in New Issue
Block a user