Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
2fa9311e
Commit
2fa9311e
authored
Jul 13, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Progress on ldap support, #1450
parent
14f439f8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
11 deletions
+63
-11
pkg/auth/ldap.go
+58
-6
pkg/setting/setting_ldap.go
+5
-5
No files found.
pkg/auth/ldap.go
View file @
2fa9311e
...
...
@@ -5,7 +5,9 @@ import (
"fmt"
"github.com/go-ldap/ldap"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
)
...
...
@@ -40,6 +42,24 @@ type ldapUserInfo struct {
MemberOf
[]
string
}
func
(
u
*
ldapUserInfo
)
isMemberOfAny
(
groups
[]
string
)
bool
{
for
_
,
group
:=
range
groups
{
if
u
.
isMemberOf
(
group
)
{
return
true
}
}
return
false
}
func
(
u
*
ldapUserInfo
)
isMemberOf
(
group
string
)
bool
{
for
_
,
member
:=
range
u
.
MemberOf
{
if
member
==
group
{
return
true
}
}
return
false
}
func
NewLdapAuthenticator
(
server
*
setting
.
LdapServerConf
)
*
ldapAuther
{
return
&
ldapAuther
{
server
:
server
,
...
...
@@ -70,16 +90,48 @@ func (a *ldapAuther) login(query *AuthenticateUserQuery) error {
}
// find user entry & attributes
if
u
ser
,
err
:=
a
.
searchForUser
(
query
.
Username
);
err
!=
nil
{
if
ldapU
ser
,
err
:=
a
.
searchForUser
(
query
.
Username
);
err
!=
nil
{
return
err
}
else
{
log
.
Info
(
"Surname: %s"
,
user
.
LastName
)
log
.
Info
(
"givenName: %s"
,
user
.
FirstName
)
log
.
Info
(
"email: %s"
,
user
.
Email
)
log
.
Info
(
"memberOf: %s"
,
user
.
MemberOf
)
log
.
Info
(
"Surname: %s"
,
ldapUser
.
LastName
)
log
.
Info
(
"givenName: %s"
,
ldapUser
.
FirstName
)
log
.
Info
(
"email: %s"
,
ldapUser
.
Email
)
log
.
Info
(
"memberOf: %s"
,
ldapUser
.
MemberOf
)
if
grafanaUser
,
err
:=
a
.
getGrafanaUserFor
(
ldapUser
);
err
!=
nil
{
return
err
}
else
{
query
.
User
=
grafanaUser
return
nil
}
}
}
func
(
a
*
ldapAuther
)
getGrafanaUserFor
(
ldapUser
*
ldapUserInfo
)
(
*
m
.
User
,
error
)
{
// get user from grafana db
userQuery
:=
m
.
GetUserByLoginQuery
{
LoginOrEmail
:
ldapUser
.
Username
}
if
err
:=
bus
.
Dispatch
(
&
userQuery
);
err
!=
nil
{
if
err
==
m
.
ErrUserNotFound
{
return
a
.
createGrafanaUser
(
ldapUser
)
}
}
return
userQuery
.
Result
,
nil
}
func
(
a
*
ldapAuther
)
createGrafanaUser
(
ldapUser
*
ldapUserInfo
)
(
*
m
.
User
,
error
)
{
cmd
:=
m
.
CreateUserCommand
{
Login
:
ldapUser
.
Username
,
Email
:
ldapUser
.
Email
,
Name
:
fmt
.
Sprintf
(
"%s %s"
,
ldapUser
.
FirstName
,
ldapUser
.
LastName
),
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
return
nil
,
err
}
return
errors
.
New
(
"Aasd"
)
return
&
cmd
.
Result
,
nil
}
func
(
a
*
ldapAuther
)
initialBind
(
username
,
userPassword
string
)
error
{
...
...
pkg/setting/setting_ldap.go
View file @
2fa9311e
package
setting
type
Ldap
Member
ToOrgRole
struct
{
Ldap
MemberPattern
string
OrgId
int
OrgRole
string
type
Ldap
Group
ToOrgRole
struct
{
Ldap
GroupPath
string
OrgId
int
OrgRole
string
}
type
LdapServerConf
struct
{
...
...
@@ -21,5 +21,5 @@ type LdapServerConf struct {
SearchFilter
string
SearchBaseDNs
[]
string
Ldap
MemberMap
[]
LdapMember
ToOrgRole
Ldap
Groups
[]
LdapGroup
ToOrgRole
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment