mirror of
https://github.com/grafana/grafana.git
synced 2026-08-18 17:15:08 -05:00
LDAP: Add API endpoint to debug user mapping from LDAP (#18833)
* Move the ReloadLDAPCfg function to the debug file Appears to be a better suite place for this. * LDAP: Return the server information when we find a specific user We allow you to specify multiple LDAP servers as part of LDAP authentication integration. As part of searching for specific users, we need to understand from which server they come from. Returning the server configuration as part of the search will help us do two things: - Understand in which server we found the user - Have access the groups specified as part of the server configuration * LDAP: Adds the /api/admin/ldap/:username endpoint This endpoint returns a user found within the configured LDAP server(s). Moreso, it provides the mapping information for the user to help administrators understand how the users would be created within Grafana based on the current configuration. No changes are executed or saved to the database, this is all an in-memory representation of how the final result would look like.
This commit is contained in:
@@ -39,7 +39,7 @@ type IMultiLDAP interface {
|
||||
)
|
||||
|
||||
User(login string) (
|
||||
*models.ExternalUserInfo, error,
|
||||
*models.ExternalUserInfo, ldap.ServerConfig, error,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -92,14 +92,15 @@ func (multiples *MultiLDAP) Login(query *models.LoginUserQuery) (
|
||||
return nil, ErrInvalidCredentials
|
||||
}
|
||||
|
||||
// User gets a user by login
|
||||
// User attempts to find an user by login/username by searching into all of the configured LDAP servers. Then, if the user is found it returns the user alongisde the server it was found.
|
||||
func (multiples *MultiLDAP) User(login string) (
|
||||
*models.ExternalUserInfo,
|
||||
ldap.ServerConfig,
|
||||
error,
|
||||
) {
|
||||
|
||||
if len(multiples.configs) == 0 {
|
||||
return nil, ErrNoLDAPServers
|
||||
return nil, ldap.ServerConfig{}, ErrNoLDAPServers
|
||||
}
|
||||
|
||||
search := []string{login}
|
||||
@@ -107,26 +108,26 @@ func (multiples *MultiLDAP) User(login string) (
|
||||
server := newLDAP(config)
|
||||
|
||||
if err := server.Dial(); err != nil {
|
||||
return nil, err
|
||||
return nil, *config, err
|
||||
}
|
||||
|
||||
defer server.Close()
|
||||
|
||||
if err := server.Bind(); err != nil {
|
||||
return nil, err
|
||||
return nil, *config, err
|
||||
}
|
||||
|
||||
users, err := server.Users(search)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, *config, err
|
||||
}
|
||||
|
||||
if len(users) != 0 {
|
||||
return users[0], nil
|
||||
return users[0], *config, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, ErrDidNotFindUser
|
||||
return nil, ldap.ServerConfig{}, ErrDidNotFindUser
|
||||
}
|
||||
|
||||
// Users gets users from multiple LDAP servers
|
||||
|
||||
Reference in New Issue
Block a user