Skip to content
Snippets Groups Projects
Commit 9d9698a1 authored by Lars Seipel's avatar Lars Seipel
Browse files

connector/ldap: hex-encode UserID to ensure it is UTF8

parent d8f5a783
No related branches found
No related tags found
No related merge requests found
package ldap package ldap
import ( import (
"encoding/hex"
"strings" "strings"
"github.com/dexidp/dex/connector" "github.com/dexidp/dex/connector"
...@@ -9,10 +10,18 @@ import ( ...@@ -9,10 +10,18 @@ import (
// TweakIdentity adjusts attributes received from the LDAP directory. Don't ask // TweakIdentity adjusts attributes received from the LDAP directory. Don't ask
// why this is necessary. Just learn to accept it. // why this is necessary. Just learn to accept it.
func tweakIdentity(id connector.Identity) connector.Identity { func tweakIdentity(id connector.Identity) connector.Identity {
id.UserID = tweakUserID(id)
id.Username = tweakName(id) id.Username = tweakName(id)
return id return id
} }
func tweakUserID(id connector.Identity) string {
// If the UserID happens to be something that is not valid UTF8 (like
// Windows/AD SIDs), it gets mangled during JSON marshaling when saved to
// storage. Ensure it is UTF8.
return hex.EncodeToString([]byte(id.UserID))
}
func tweakName(id connector.Identity) string { func tweakName(id connector.Identity) string {
name := id.Username name := id.Username
if name == " " { if name == " " {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment