LDAP: reduce API and allow its extension (#17209)
* Removes Add/Remove methods * Publicise necessary fields and methods so we could extend it * Publicise mock API * More comments and additional simplifications * Sync with master Still having low coverage :/ - should be addressed in #17208
This commit is contained in:
@@ -35,9 +35,6 @@ type IMultiLDAP interface {
|
||||
User(login string) (
|
||||
*models.ExternalUserInfo, error,
|
||||
)
|
||||
|
||||
Add(dn string, values map[string][]string) error
|
||||
Remove(dn string) error
|
||||
}
|
||||
|
||||
// MultiLDAP is basic struct of LDAP authorization
|
||||
@@ -52,55 +49,6 @@ func New(configs []*ldap.ServerConfig) IMultiLDAP {
|
||||
}
|
||||
}
|
||||
|
||||
// Add adds user to the *first* defined LDAP
|
||||
func (multiples *MultiLDAP) Add(
|
||||
dn string,
|
||||
values map[string][]string,
|
||||
) error {
|
||||
if len(multiples.configs) == 0 {
|
||||
return ErrNoLDAPServers
|
||||
}
|
||||
|
||||
config := multiples.configs[0]
|
||||
ldap := ldap.New(config)
|
||||
|
||||
if err := ldap.Dial(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer ldap.Close()
|
||||
|
||||
err := ldap.Add(dn, values)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Remove removes user from the *first* defined LDAP
|
||||
func (multiples *MultiLDAP) Remove(dn string) error {
|
||||
if len(multiples.configs) == 0 {
|
||||
return ErrNoLDAPServers
|
||||
}
|
||||
|
||||
config := multiples.configs[0]
|
||||
ldap := ldap.New(config)
|
||||
|
||||
if err := ldap.Dial(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer ldap.Close()
|
||||
|
||||
err := ldap.Remove(dn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Login tries to log in the user in multiples LDAP
|
||||
func (multiples *MultiLDAP) Login(query *models.LoginUserQuery) (
|
||||
*models.ExternalUserInfo, error,
|
||||
|
||||
Reference in New Issue
Block a user