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
0320baeb
Commit
0320baeb
authored
Jul 14, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(ldap): user org role sync working
parent
42670c27
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
7 deletions
+70
-7
pkg/auth/ldap.go
+15
-2
pkg/auth/ldap_test.go
+55
-5
No files found.
pkg/auth/ldap.go
View file @
0320baeb
...
...
@@ -27,7 +27,7 @@ func init() {
SearchFilter
:
"(cn=%s)"
,
SearchBaseDNs
:
[]
string
{
"dc=grafana,dc=org"
},
LdapGroups
:
[]
*
LdapGroupToOrgRole
{
{
GroupDN
:
"cn=users,dc=grafana,dc=org"
,
Org
Role
:
m
.
ROLE_EDITO
R
},
{
GroupDN
:
"cn=users,dc=grafana,dc=org"
,
Org
Id
:
1
,
OrgRole
:
m
.
ROLE_VIEWE
R
},
},
},
}
...
...
@@ -143,16 +143,29 @@ func (a *ldapAuther) syncOrgRoles(user *m.User, ldapUser *ldapUserInfo) error {
// remove or update org roles
for
_
,
org
:=
range
orgsQuery
.
Result
{
for
_
,
group
:=
range
a
.
server
.
LdapGroups
{
if
group
.
OrgId
==
org
.
OrgId
&&
ldapUser
.
isMemberOf
(
group
.
GroupDN
)
{
if
org
.
OrgId
!=
group
.
OrgId
{
continue
}
if
ldapUser
.
isMemberOf
(
group
.
GroupDN
)
{
if
org
.
Role
!=
group
.
OrgRole
{
// update role
cmd
:=
m
.
UpdateOrgUserCommand
{
OrgId
:
org
.
OrgId
,
UserId
:
user
.
Id
,
Role
:
group
.
OrgRole
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
return
err
}
}
}
else
{
// remove role
cmd
:=
m
.
RemoveOrgUserCommand
{
OrgId
:
org
.
OrgId
,
UserId
:
user
.
Id
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
return
err
}
}
}
}
// add missing org roles
for
_
,
group
:=
range
a
.
server
.
LdapGroups
{
if
!
ldapUser
.
isMemberOf
(
group
.
GroupDN
)
{
continue
...
...
pkg/auth/ldap_test.go
View file @
0320baeb
...
...
@@ -97,10 +97,48 @@ func TestLdapAuther(t *testing.T) {
Convey
(
"Should create new org user"
,
func
()
{
So
(
err
,
ShouldBeNil
)
So
(
sc
.
addOrgUserC
omman
d
,
ShouldNotBeNil
)
So
(
sc
.
addOrgUserC
omman
d
.
Role
,
ShouldEqual
,
m
.
ROLE_ADMIN
)
So
(
sc
.
addOrgUserC
m
d
,
ShouldNotBeNil
)
So
(
sc
.
addOrgUserC
m
d
.
Role
,
ShouldEqual
,
m
.
ROLE_ADMIN
)
})
})
ldapAutherScenario
(
"given different current org role"
,
func
(
sc
*
scenarioContext
)
{
ldapAuther
:=
NewLdapAuthenticator
(
&
LdapServerConf
{
LdapGroups
:
[]
*
LdapGroupToOrgRole
{
{
GroupDN
:
"cn=users"
,
OrgId
:
1
,
OrgRole
:
"Admin"
},
},
})
sc
.
userOrgsQueryReturns
([]
*
m
.
UserOrgDTO
{{
OrgId
:
1
,
Role
:
m
.
ROLE_EDITOR
}})
err
:=
ldapAuther
.
syncOrgRoles
(
&
m
.
User
{},
&
ldapUserInfo
{
MemberOf
:
[]
string
{
"cn=users"
},
})
Convey
(
"Should update org role"
,
func
()
{
So
(
err
,
ShouldBeNil
)
So
(
sc
.
updateOrgUserCmd
,
ShouldNotBeNil
)
So
(
sc
.
updateOrgUserCmd
.
Role
,
ShouldEqual
,
m
.
ROLE_ADMIN
)
})
})
ldapAutherScenario
(
"given current org role is removed in ldap"
,
func
(
sc
*
scenarioContext
)
{
ldapAuther
:=
NewLdapAuthenticator
(
&
LdapServerConf
{
LdapGroups
:
[]
*
LdapGroupToOrgRole
{
{
GroupDN
:
"cn=users"
,
OrgId
:
1
,
OrgRole
:
"Admin"
},
},
})
sc
.
userOrgsQueryReturns
([]
*
m
.
UserOrgDTO
{{
OrgId
:
1
,
Role
:
m
.
ROLE_EDITOR
}})
err
:=
ldapAuther
.
syncOrgRoles
(
&
m
.
User
{},
&
ldapUserInfo
{
MemberOf
:
[]
string
{
"cn=other"
},
})
Convey
(
"Should remove org role"
,
func
()
{
So
(
err
,
ShouldBeNil
)
So
(
sc
.
removeOrgUserCmd
,
ShouldNotBeNil
)
})
})
})
}
...
...
@@ -117,7 +155,17 @@ func ldapAutherScenario(desc string, fn scenarioFunc) {
})
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
AddOrgUserCommand
)
error
{
sc
.
addOrgUserCommand
=
cmd
sc
.
addOrgUserCmd
=
cmd
return
nil
})
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
UpdateOrgUserCommand
)
error
{
sc
.
updateOrgUserCmd
=
cmd
return
nil
})
bus
.
AddHandler
(
"test"
,
func
(
cmd
*
m
.
RemoveOrgUserCommand
)
error
{
sc
.
removeOrgUserCmd
=
cmd
return
nil
})
...
...
@@ -126,8 +174,10 @@ func ldapAutherScenario(desc string, fn scenarioFunc) {
}
type
scenarioContext
struct
{
createUserCmd
*
m
.
CreateUserCommand
addOrgUserCommand
*
m
.
AddOrgUserCommand
createUserCmd
*
m
.
CreateUserCommand
addOrgUserCmd
*
m
.
AddOrgUserCommand
updateOrgUserCmd
*
m
.
UpdateOrgUserCommand
removeOrgUserCmd
*
m
.
RemoveOrgUserCommand
}
func
(
sc
*
scenarioContext
)
userQueryReturns
(
user
*
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