Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
737bdc30
Commit
737bdc30
authored
Sep 10, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'refactor/ldap_access' of /home/git/repositories/gitlab/gitlab-ee
parents
b1150883
61ba66c0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
25 deletions
+49
-25
lib/gitlab/ldap/access.rb
lib/gitlab/ldap/access.rb
+28
-14
lib/gitlab/ldap/adapter.rb
lib/gitlab/ldap/adapter.rb
+4
-0
lib/gitlab/ldap/group.rb
lib/gitlab/ldap/group.rb
+17
-1
lib/gitlab/ldap/person.rb
lib/gitlab/ldap/person.rb
+0
-10
No files found.
lib/gitlab/ldap/access.rb
View file @
737bdc30
...
...
@@ -12,27 +12,41 @@ module Gitlab
# if instance does not use group_base setting
return
true
unless
Gitlab
.
config
.
ldap
[
'group_base'
].
present?
# Get LDAP user entry
ldap_user
=
Gitlab
::
LDAP
::
Person
.
find_by_dn
(
user
.
extern_uid
)
ldap_groups
=
ldap_user
.
groups
ldap_groups_cn
=
ldap_groups
.
map
(
&
:name
)
groups
=
::
Group
.
where
(
ldap_cn:
ldap_groups_cn
)
# First lets add user to new groups
groups
.
each
do
|
group
|
group
.
add_users
([
user
.
id
],
group
.
ldap_access
)
if
group
.
ldap_access
.
present?
end
# Get all GitLab groups with activated LDAP
groups
=
::
Group
.
where
(
'ldap_cn IS NOT NULL'
)
# Get LDAP groups based on cn from GitLab groups
ldap_groups
=
groups
.
pluck
(
:ldap_cn
).
map
{
|
cn
|
Gitlab
::
LDAP
::
Group
.
find_by_cn
(
cn
)
}
ldap_groups
=
ldap_groups
.
compact
.
uniq
# Remove groups with LDAP if user lost access to it
user
.
authorized_groups
.
where
(
'ldap_cn IS NOT NULL'
).
each
do
|
group
|
if
ldap_groups_cn
.
include?
(
group
.
ldap_cn
)
# ok user still in group
# Iterate over ldap groups and check user membership
ldap_groups
.
each
do
|
ldap_group
|
if
ldap_group
.
has_member?
(
ldap_user
)
# If user present in LDAP group -> add him to GitLab groups
add_user_to_groups
(
user
.
id
,
ldap_group
.
cn
)
else
# user lost access to this group in ldap
membership
=
group
.
users_groups
.
where
(
user_id:
user
.
id
).
last
membership
.
destroy
if
membership
# If not - remove him from GitLab groups
remove_user_from_groups
(
user
.
id
,
ldap_group
.
cn
)
end
end
end
def
add_user_to_groups
(
user_id
,
group_cn
)
groups
=
::
Group
.
where
(
ldap_cn:
group_cn
)
groups
.
each
do
|
group
|
group
.
add_users
([
user_id
],
group
.
ldap_access
)
if
group
.
ldap_access
.
present?
end
end
def
remove_user_from_groups
(
user_id
,
group_cn
)
groups
=
::
Group
.
where
(
ldap_cn:
group_cn
)
groups
.
each
do
|
group
|
group
.
users_groups
.
where
(
user_id:
user_id
).
destroy_all
end
end
end
end
end
lib/gitlab/ldap/adapter.rb
View file @
737bdc30
...
...
@@ -51,6 +51,10 @@ module Gitlab
end
end
def
group
(
*
args
)
groups
(
*
args
).
first
end
def
users
(
field
,
value
)
if
field
.
to_sym
==
:dn
options
=
{
...
...
lib/gitlab/ldap/group.rb
View file @
737bdc30
...
...
@@ -7,14 +7,22 @@
module
Gitlab
module
LDAP
class
Group
def
self
.
find_by_cn
(
cn
)
Gitlab
::
LDAP
::
Adapter
.
new
.
group
(
cn
)
end
def
initialize
(
entry
)
@entry
=
entry
end
def
name
def
cn
entry
.
cn
.
join
(
" "
)
end
def
name
cn
end
def
path
name
.
parameterize
end
...
...
@@ -27,6 +35,14 @@ module Gitlab
entry
.
memberuid
end
def
has_member?
(
user
)
if
memberuid?
member_uids
.
include?
(
user
.
uid
)
else
member_dns
.
include?
(
user
.
dn
)
end
end
def
member_dns
if
entry
.
respond_to?
:member
entry
.
member
...
...
lib/gitlab/ldap/person.rb
View file @
737bdc30
...
...
@@ -35,16 +35,6 @@ module Gitlab
entry
.
dn
end
def
groups
adapter
.
groups
.
select
do
|
group
|
if
group
.
memberuid?
group
.
member_uids
.
include?
(
uid
)
else
group
.
member_dns
.
include?
(
dn
)
end
end
end
private
def
entry
...
...
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