diff --git a/auth/ldap/ldap.go b/auth/ldap/ldap.go index c027fce..d433ce1 100644 --- a/auth/ldap/ldap.go +++ b/auth/ldap/ldap.go @@ -3,12 +3,14 @@ package ldap import ( "github.com/go-ldap/ldap/v3" + "log" ) // Options holds package configuration type Options struct { - URI string - UserDn string + Aliases map[string]string + URI string + UserDn string } // LDAP authentification backend @@ -20,6 +22,12 @@ type LDAP struct { // Login tries to bind to LDAP // Returns (true, nil) if success func (a LDAP) Login(username string, password string) (bool, error) { + // Resolve stream alias if necessary + for aliasFor, ok := a.Cfg.Aliases[username]; ok; { + log.Printf("[LDAP] Use stream alias %s for username %s", username, aliasFor) + username = aliasFor + } + // Try to bind as user bindDn := "cn=" + username + "," + a.Cfg.UserDn err := a.Conn.Bind(bindDn, password) diff --git a/docs/ghostream.example.yml b/docs/ghostream.example.yml index 4e98646..27c7ee4 100644 --- a/docs/ghostream.example.yml +++ b/docs/ghostream.example.yml @@ -34,6 +34,11 @@ auth: #ldap: # uri: ldap://127.0.0.1:389 # userdn: cn=users,dc=example,dc=com + # + # # You can define aliases, to stream on stream.example.com/example with the credentials of the demo account. + # aliases: + # example: demo + # ## Stream forwarding ## # Forward an incoming stream to other servers diff --git a/internal/config/config.go b/internal/config/config.go index de86f7b..a16fa75 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -42,8 +42,9 @@ func New() *Config { Credentials: make(map[string]string), }, LDAP: ldap.Options{ - URI: "ldap://127.0.0.1:389", - UserDn: "cn=users,dc=example,dc=com", + Aliases: make(map[string]string), + URI: "ldap://127.0.0.1:389", + UserDn: "cn=users,dc=example,dc=com", }, }, Forwarding: make(map[string][]string),