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
4ef74844
Commit
4ef74844
authored
Oct 07, 2014
by
Jan-Willem van der Meer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adapt to new LDAP::Config class
parent
e60da677
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
46 additions
and
69 deletions
+46
-69
config/initializers/1_settings.rb
config/initializers/1_settings.rb
+2
-2
lib/gitlab/ldap/access.rb
lib/gitlab/ldap/access.rb
+20
-4
lib/gitlab/ldap/adapter.rb
lib/gitlab/ldap/adapter.rb
+9
-48
lib/gitlab/ldap/user.rb
lib/gitlab/ldap/user.rb
+4
-4
spec/lib/gitlab/ldap/access_spec.rb
spec/lib/gitlab/ldap/access_spec.rb
+1
-2
spec/lib/gitlab/ldap/adapter_spec.rb
spec/lib/gitlab/ldap/adapter_spec.rb
+1
-1
spec/lib/gitlab/ldap/user_spec.rb
spec/lib/gitlab/ldap/user_spec.rb
+9
-8
No files found.
config/initializers/1_settings.rb
View file @
4ef74844
...
...
@@ -59,13 +59,13 @@ Settings.ldap['allow_username_or_email_login'] = false if Settings.ldap['allow_u
Settings
.
ldap
[
'sync_time'
]
=
3600
if
Settings
.
ldap
[
'sync_time'
].
nil?
# backwards compatibility, we only have one host
if
Settings
.
ldap
[
'enabled'
]
if
Settings
.
ldap
[
'enabled'
]
||
Rails
.
env
.
test?
if
Settings
.
ldap
[
'host'
].
present?
excluded_per_server_settings
=
%w(sync_time allow_username_or_email_login)
server
=
Settings
.
ldap
.
except
(
excluded_per_server_settings
)
server
[
'primary'
]
=
true
server
[
'label'
]
=
'LDAP'
server
[
'provider_i
ndex
'
]
=
''
#providername will be ldap
server
[
'provider_i
d
'
]
=
''
#providername will be ldap
Settings
.
ldap
[
'servers'
]
=
[
server
]
end
...
...
lib/gitlab/ldap/access.rb
View file @
4ef74844
...
...
@@ -43,22 +43,26 @@ module Gitlab
false
end
def
adapter
@adapter
||=
Gitlab
::
LDAP
::
Adapter
.
new
(
provider
)
end
def
get_ldap_user
(
user
)
@ldap_user
||=
Gitlab
::
LDAP
::
Person
.
find_by_dn
(
user
.
extern_uid
,
adapter
)
end
def
update_permissions
(
user
)
if
ldap_config
[
'sync_ssh_keys'
]
if
sync_ssh_keys?
update_ssh_keys
(
user
)
end
# Skip updating group permissions
# if instance does not use group_base setting
return
true
unless
ldap_config
[
'group_base'
]
.
present?
return
true
unless
group_base
.
present?
update_ldap_group_links
(
user
)
if
ldap_config
[
'admin_group'
]
.
present?
if
admin_group
.
present?
update_admin_status
(
user
)
end
end
...
...
@@ -147,7 +151,19 @@ module Gitlab
end
def
ldap_config
Gitlab
::
LDAP
::
Adapter
.
config_for
(
provider
)
Gitlab
::
LDAP
::
Config
.
new
(
provider
)
end
def
sync_ssh_keys?
ldap_config
.
sync_ssh_keys?
end
def
group_base
ldap_config
.
group_base
end
def
admin_group
ldap_config
.
admin_group
end
private
...
...
lib/gitlab/ldap/adapter.rb
View file @
4ef74844
...
...
@@ -4,55 +4,22 @@ module Gitlab
attr_reader
:provider
,
:ldap
def
self
.
open
(
provider
,
&
block
)
Net
::
LDAP
.
open
(
adapter_options
(
provider
)
)
do
|
ldap
|
Net
::
LDAP
.
open
(
config
(
provider
).
adapter_options
)
do
|
ldap
|
block
.
call
(
self
.
new
(
provider
,
ldap
))
end
end
def
self
.
config
Gitlab
.
config
.
ldap
def
self
.
config
(
provider
)
Gitlab
::
LDAP
::
Config
.
new
(
provider
)
end
def
self
.
config_for
(
provider
)
config
.
servers
.
find
{
|
server
|
server
.
provider_name
==
provider
}
end
def
self
.
adapter_options
(
provider
)
config
=
config_for
(
provider
)
encryption
=
case
config
[
'method'
].
to_s
when
'ssl'
:simple_tls
when
'tls'
:start_tls
else
nil
end
options
=
{
host:
config
[
'host'
],
port:
config
[
'port'
],
encryption:
encryption
}
auth_options
=
{
auth:
{
method: :simple
,
username:
config
[
'bind_dn'
],
password:
config
[
'password'
]
}
}
if
config
[
'password'
]
||
config
[
'bind_dn'
]
options
.
merge!
(
auth_options
)
end
options
end
def
initialize
(
provider
,
ldap
=
nil
)
@provider
=
provider
@ldap
=
ldap
||
Net
::
LDAP
.
new
(
self
.
class
.
adapter_options
)
@ldap
=
ldap
||
Net
::
LDAP
.
new
(
config
.
adapter_options
)
end
def
config
Gitlab
::
LDAP
::
Config
.
new
(
provider
)
end
# Get LDAP groups from ou=Groups
...
...
@@ -107,7 +74,7 @@ module Gitlab
end
entries
.
map
do
|
entry
|
Gitlab
::
LDAP
::
Person
.
new
(
entry
)
Gitlab
::
LDAP
::
Person
.
new
(
entry
,
provider
)
end
end
...
...
@@ -135,12 +102,6 @@ module Gitlab
results
end
end
private
def
config
@config
||=
self
.
class
.
config_for
(
provider
)
end
end
end
end
lib/gitlab/ldap/user.rb
View file @
4ef74844
...
...
@@ -26,21 +26,21 @@ module Gitlab
end
def
adapter
@adapter
||=
OmniAuth
::
LDAP
::
Adaptor
.
new
(
ldap_conf
)
@adapter
||=
OmniAuth
::
LDAP
::
Adaptor
.
new
(
ldap_conf
.
options
)
end
def
user_filter
(
login
)
filter
=
Net
::
LDAP
::
Filter
.
eq
(
adapter
.
uid
,
login
)
# Apply LDAP user filter if present
if
ldap_conf
[
'user_filter'
]
.
present?
user_filter
=
Net
::
LDAP
::
Filter
.
construct
(
ldap_conf
[
'user_filter'
]
)
if
ldap_conf
.
user_filter
.
present?
user_filter
=
Net
::
LDAP
::
Filter
.
construct
(
ldap_conf
.
user_filter
)
filter
=
Net
::
LDAP
::
Filter
.
join
(
filter
,
user_filter
)
end
filter
end
def
ldap_conf
Gitlab
.
config
.
ldap
Gitlab
::
LDAP
::
Config
.
new
(
provider
)
end
def
find_by_uid
(
uid
)
...
...
spec/lib/gitlab/ldap/access_spec.rb
View file @
4ef74844
require
'spec_helper'
describe
Gitlab
::
LDAP
::
Access
do
let
(
:access
)
{
Gitlab
::
LDAP
::
Access
.
new
}
let
(
:access
)
{
Gitlab
::
LDAP
::
Access
.
new
'ldapmain'
}
let
(
:user
)
{
create
(
:user
)
}
describe
:allowed?
do
subject
{
access
.
allowed?
(
user
)
}
...
...
spec/lib/gitlab/ldap/adapter_spec.rb
View file @
4ef74844
require
'spec_helper'
describe
Gitlab
::
LDAP
::
Adapter
do
let
(
:adapter
)
{
Gitlab
::
LDAP
::
Adapter
.
new
}
let
(
:adapter
)
{
Gitlab
::
LDAP
::
Adapter
.
new
'ldapmain'
}
describe
:dn_matches_filter?
do
let
(
:ldap
)
{
double
(
:ldap
)
}
...
...
spec/lib/gitlab/ldap/user_spec.rb
View file @
4ef74844
...
...
@@ -10,12 +10,12 @@ describe Gitlab::LDAP::User do
}
end
let
(
:auth_hash
)
do
double
(
uid:
'my-uid'
,
provider:
'ldap'
,
info:
double
(
info
))
double
(
uid:
'my-uid'
,
provider:
'ldap
main
'
,
info:
double
(
info
))
end
describe
:find_or_create
do
it
"finds the user if already existing"
do
existing_user
=
create
(
:user
,
extern_uid:
'my-uid'
,
provider:
'ldap'
)
existing_user
=
create
(
:user
,
extern_uid:
'my-uid'
,
provider:
'ldap
main
'
)
expect
{
gl_user
.
save
}.
to_not
change
{
User
.
count
}
end
...
...
@@ -26,7 +26,7 @@ describe Gitlab::LDAP::User do
existing_user
.
reload
expect
(
existing_user
.
extern_uid
).
to
eql
'my-uid'
expect
(
existing_user
.
provider
).
to
eql
'ldap'
expect
(
existing_user
.
provider
).
to
eql
'ldap
main
'
end
it
"creates a new user if not found"
do
...
...
@@ -38,13 +38,14 @@ describe Gitlab::LDAP::User do
let
(
:login
)
{
'john'
}
let
(
:password
)
{
'my-secret'
}
before
{
Gitlab
.
config
.
ldap
[
'enabled'
]
=
true
Gitlab
.
config
.
ldap
[
'user_filter'
]
=
'employeeType=developer'
}
after
{
Gitlab
.
config
.
ldap
[
'enabled'
]
=
false
}
#
before {
#
Gitlab.config.ldap['enabled'] = true
#
Gitlab.config.ldap['user_filter'] = 'employeeType=developer'
#
}
#
after { Gitlab.config.ldap['enabled'] = false }
it
"send an authentication request to ldap"
do
pending
(
'needs refactoring'
)
expect
(
Gitlab
::
LDAP
::
User
.
adapter
).
to
receive
(
:bind_as
)
Gitlab
::
LDAP
::
User
.
authenticate
(
login
,
password
)
end
...
...
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