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
9bf9bb02
Commit
9bf9bb02
authored
Jul 18, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(ldap): fixed issue with ldap group mappings to org roles sync, #1450
parent
5744c703
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
7 deletions
+32
-7
pkg/login/ldap.go
+12
-7
pkg/login/ldap_test.go
+20
-0
No files found.
pkg/login/ldap.go
View file @
9bf9bb02
...
...
@@ -130,14 +130,17 @@ func (a *ldapAuther) syncOrgRoles(user *m.User, ldapUser *ldapUserInfo) error {
return
err
}
//
remove or updat
e org roles
//
update or remov
e org roles
for
_
,
org
:=
range
orgsQuery
.
Result
{
match
:=
false
for
_
,
group
:=
range
a
.
server
.
LdapGroups
{
if
org
.
OrgId
!=
group
.
OrgId
{
continue
}
if
ldapUser
.
isMemberOf
(
group
.
GroupDN
)
{
match
=
true
if
org
.
Role
!=
group
.
OrgRole
{
// update role
cmd
:=
m
.
UpdateOrgUserCommand
{
OrgId
:
org
.
OrgId
,
UserId
:
user
.
Id
,
Role
:
group
.
OrgRole
}
...
...
@@ -147,12 +150,14 @@ func (a *ldapAuther) syncOrgRoles(user *m.User, ldapUser *ldapUserInfo) error {
}
// ignore subsequent ldap group mapping matches
break
}
else
{
// remove role
cmd
:=
m
.
RemoveOrgUserCommand
{
OrgId
:
org
.
OrgId
,
UserId
:
user
.
Id
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
return
err
}
}
}
// remove role if no mappings match
if
!
match
{
cmd
:=
m
.
RemoveOrgUserCommand
{
OrgId
:
org
.
OrgId
,
UserId
:
user
.
Id
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
return
err
}
}
}
...
...
pkg/login/ldap_test.go
View file @
9bf9bb02
...
...
@@ -139,6 +139,26 @@ func TestLdapAuther(t *testing.T) {
})
})
ldapAutherScenario
(
"given org role is updated in config"
,
func
(
sc
*
scenarioContext
)
{
ldapAuther
:=
NewLdapAuthenticator
(
&
LdapServerConf
{
LdapGroups
:
[]
*
LdapGroupToOrgRole
{
{
GroupDN
:
"cn=admin"
,
OrgId
:
1
,
OrgRole
:
"Admin"
},
{
GroupDN
:
"cn=users"
,
OrgId
:
1
,
OrgRole
:
"Viewer"
},
},
})
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
.
removeOrgUserCmd
,
ShouldBeNil
)
So
(
sc
.
updateOrgUserCmd
,
ShouldNotBeNil
)
})
})
ldapAutherScenario
(
"given multiple matching ldap groups"
,
func
(
sc
*
scenarioContext
)
{
ldapAuther
:=
NewLdapAuthenticator
(
&
LdapServerConf
{
LdapGroups
:
[]
*
LdapGroupToOrgRole
{
...
...
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