1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2024-12-22 11:32:19 +00:00

Add aliases auth support if the authentication method is LDAP

This commit is contained in:
Yohann D'ANELLO 2020-12-06 13:36:24 +01:00
parent 849196b4cb
commit 0035c63c22
3 changed files with 18 additions and 4 deletions

View File

@ -3,12 +3,14 @@ package ldap
import ( import (
"github.com/go-ldap/ldap/v3" "github.com/go-ldap/ldap/v3"
"log"
) )
// Options holds package configuration // Options holds package configuration
type Options struct { type Options struct {
URI string Aliases map[string]string
UserDn string URI string
UserDn string
} }
// LDAP authentification backend // LDAP authentification backend
@ -20,6 +22,12 @@ type LDAP struct {
// Login tries to bind to LDAP // Login tries to bind to LDAP
// Returns (true, nil) if success // Returns (true, nil) if success
func (a LDAP) Login(username string, password string) (bool, error) { 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 // Try to bind as user
bindDn := "cn=" + username + "," + a.Cfg.UserDn bindDn := "cn=" + username + "," + a.Cfg.UserDn
err := a.Conn.Bind(bindDn, password) err := a.Conn.Bind(bindDn, password)

View File

@ -34,6 +34,11 @@ auth:
#ldap: #ldap:
# uri: ldap://127.0.0.1:389 # uri: ldap://127.0.0.1:389
# userdn: cn=users,dc=example,dc=com # 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 ## ## Stream forwarding ##
# Forward an incoming stream to other servers # Forward an incoming stream to other servers

View File

@ -42,8 +42,9 @@ func New() *Config {
Credentials: make(map[string]string), Credentials: make(map[string]string),
}, },
LDAP: ldap.Options{ LDAP: ldap.Options{
URI: "ldap://127.0.0.1:389", Aliases: make(map[string]string),
UserDn: "cn=users,dc=example,dc=com", URI: "ldap://127.0.0.1:389",
UserDn: "cn=users,dc=example,dc=com",
}, },
}, },
Forwarding: make(map[string][]string), Forwarding: make(map[string][]string),