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
4f48ed33
Unverified
Commit
4f48ed33
authored
Mar 08, 2019
by
Marcus Efraimsson
Committed by
GitHub
Mar 08, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15872 from grafana/15643_fix2
fix allow anonymous server bind for ldap search
parents
c9e90f89
c242d383
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
1 deletions
+74
-1
pkg/login/ldap.go
+11
-1
pkg/login/ldap_test.go
+63
-0
No files found.
pkg/login/ldap.go
View file @
4f48ed33
...
...
@@ -219,8 +219,18 @@ func (a *ldapAuther) GetGrafanaUserFor(ctx *m.ReqContext, ldapUser *LdapUserInfo
}
func
(
a
*
ldapAuther
)
serverBind
()
error
{
bindFn
:=
func
()
error
{
return
a
.
conn
.
Bind
(
a
.
server
.
BindDN
,
a
.
server
.
BindPassword
)
}
if
a
.
server
.
BindPassword
==
""
{
bindFn
=
func
()
error
{
return
a
.
conn
.
UnauthenticatedBind
(
a
.
server
.
BindDN
)
}
}
// bind_dn and bind_password to bind
if
err
:=
a
.
conn
.
Bind
(
a
.
server
.
BindDN
,
a
.
server
.
BindPassword
);
err
!=
nil
{
if
err
:=
bindFn
(
);
err
!=
nil
{
a
.
log
.
Info
(
"LDAP initial bind failed, %v"
,
err
)
if
ldapErr
,
ok
:=
err
.
(
*
ldap
.
Error
);
ok
{
...
...
pkg/login/ldap_test.go
View file @
4f48ed33
...
...
@@ -78,6 +78,69 @@ func TestLdapAuther(t *testing.T) {
})
})
Convey
(
"serverBind"
,
t
,
func
()
{
Convey
(
"Given bind dn and password configured"
,
func
()
{
conn
:=
&
mockLdapConn
{}
var
actualUsername
,
actualPassword
string
conn
.
bindProvider
=
func
(
username
,
password
string
)
error
{
actualUsername
=
username
actualPassword
=
password
return
nil
}
ldapAuther
:=
&
ldapAuther
{
conn
:
conn
,
server
:
&
LdapServerConf
{
BindDN
:
"o=users,dc=grafana,dc=org"
,
BindPassword
:
"bindpwd"
,
},
}
err
:=
ldapAuther
.
serverBind
()
So
(
err
,
ShouldBeNil
)
So
(
actualUsername
,
ShouldEqual
,
"o=users,dc=grafana,dc=org"
)
So
(
actualPassword
,
ShouldEqual
,
"bindpwd"
)
})
Convey
(
"Given bind dn configured"
,
func
()
{
conn
:=
&
mockLdapConn
{}
unauthenticatedBindWasCalled
:=
false
var
actualUsername
string
conn
.
unauthenticatedBindProvider
=
func
(
username
string
)
error
{
unauthenticatedBindWasCalled
=
true
actualUsername
=
username
return
nil
}
ldapAuther
:=
&
ldapAuther
{
conn
:
conn
,
server
:
&
LdapServerConf
{
BindDN
:
"o=users,dc=grafana,dc=org"
,
},
}
err
:=
ldapAuther
.
serverBind
()
So
(
err
,
ShouldBeNil
)
So
(
unauthenticatedBindWasCalled
,
ShouldBeTrue
)
So
(
actualUsername
,
ShouldEqual
,
"o=users,dc=grafana,dc=org"
)
})
Convey
(
"Given empty bind dn and password"
,
func
()
{
conn
:=
&
mockLdapConn
{}
unauthenticatedBindWasCalled
:=
false
var
actualUsername
string
conn
.
unauthenticatedBindProvider
=
func
(
username
string
)
error
{
unauthenticatedBindWasCalled
=
true
actualUsername
=
username
return
nil
}
ldapAuther
:=
&
ldapAuther
{
conn
:
conn
,
server
:
&
LdapServerConf
{},
}
err
:=
ldapAuther
.
serverBind
()
So
(
err
,
ShouldBeNil
)
So
(
unauthenticatedBindWasCalled
,
ShouldBeTrue
)
So
(
actualUsername
,
ShouldBeEmpty
)
})
})
Convey
(
"When translating ldap user to grafana user"
,
t
,
func
()
{
var
user1
=
&
m
.
User
{}
...
...
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