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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
45e9150a
Commit
45e9150a
authored
Jun 05, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tweak code.
parent
dfcea8ed
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
21 deletions
+24
-21
lib/gitlab/o_auth/user.rb
lib/gitlab/o_auth/user.rb
+24
-21
No files found.
lib/gitlab/o_auth/user.rb
View file @
45e9150a
...
@@ -61,16 +61,18 @@ module Gitlab
...
@@ -61,16 +61,18 @@ module Gitlab
def
find_or_create_ldap_user
def
find_or_create_ldap_user
return
unless
ldap_person
return
unless
ldap_person
#If a corresponding person exists with same uid in a LDAP server,
#set up a Gitlab user with dual LDAP and Omniauth identities.
# If a corresponding person exists with same uid in a LDAP server,
# set up a Gitlab user with dual LDAP and Omniauth identities.
if
user
=
Gitlab
::
LDAP
::
User
.
find_by_uid_and_provider
(
ldap_person
.
dn
.
downcase
,
ldap_person
.
provider
)
if
user
=
Gitlab
::
LDAP
::
User
.
find_by_uid_and_provider
(
ldap_person
.
dn
.
downcase
,
ldap_person
.
provider
)
#
c
ase when a LDAP user already exists in Gitlab. Add the Omniauth identity to existing account.
#
C
ase when a LDAP user already exists in Gitlab. Add the Omniauth identity to existing account.
user
.
identities
.
build
(
extern_uid:
auth_hash
.
uid
,
provider:
auth_hash
.
provider
)
user
.
identities
.
build
(
extern_uid:
auth_hash
.
uid
,
provider:
auth_hash
.
provider
)
else
else
#
n
o account in Gitlab yet: create it and add the LDAP identity
#
N
o account in Gitlab yet: create it and add the LDAP identity
user
=
build_new_user
user
=
build_new_user
user
.
identities
.
new
(
provider:
ldap_person
.
provider
,
extern_uid:
ldap_person
.
dn
)
user
.
identities
.
new
(
provider:
ldap_person
.
provider
,
extern_uid:
ldap_person
.
dn
)
end
end
user
user
end
end
...
@@ -85,26 +87,20 @@ module Gitlab
...
@@ -85,26 +87,20 @@ module Gitlab
def
ldap_person
def
ldap_person
return
@ldap_person
if
defined?
(
@ldap_person
)
return
@ldap_person
if
defined?
(
@ldap_person
)
#looks for a corresponding person with same uid in any of the configured LDAP providers
#
looks for a corresponding person with same uid in any of the configured LDAP providers
Gitlab
::
LDAP
::
Config
.
providers
.
each
do
|
provider
|
@ldap_person
=
Gitlab
::
LDAP
::
Config
.
providers
.
find
do
|
provider
|
adapter
=
Gitlab
::
LDAP
::
Adapter
.
new
(
provider
)
adapter
=
Gitlab
::
LDAP
::
Adapter
.
new
(
provider
)
@ldap_person
=
Gitlab
::
LDAP
::
Person
.
find_by_uid
(
auth_hash
.
uid
,
adapter
)
break
if
@ldap_person
#exit on first person found
Gitlab
::
LDAP
::
Person
.
find_by_uid
(
auth_hash
.
uid
,
adapter
)
end
end
@ldap_person
#may be nil if we could not find a match
end
end
def
ldap_config
def
ldap_config
ldap_person
&&
Gitlab
::
LDAP
::
Config
.
new
(
ldap_person
.
provider
)
Gitlab
::
LDAP
::
Config
.
new
(
ldap_person
.
provider
)
if
ldap_person
end
end
def
needs_blocking?
def
needs_blocking?
return
false
unless
new?
new?
&&
block_after_signup?
if
creating_linked_ldap_user?
ldap_config
.
block_auto_created_users
else
block_after_signup?
end
end
end
def
signup_enabled?
def
signup_enabled?
...
@@ -112,8 +108,12 @@ module Gitlab
...
@@ -112,8 +108,12 @@ module Gitlab
end
end
def
block_after_signup?
def
block_after_signup?
if
creating_linked_ldap_user?
ldap_config
.
block_auto_created_users
else
Gitlab
.
config
.
omniauth
.
block_auto_created_users
Gitlab
.
config
.
omniauth
.
block_auto_created_users
end
end
end
def
auth_hash
=
(
auth_hash
)
def
auth_hash
=
(
auth_hash
)
@auth_hash
=
AuthHash
.
new
(
auth_hash
)
@auth_hash
=
AuthHash
.
new
(
auth_hash
)
...
@@ -133,12 +133,15 @@ module Gitlab
...
@@ -133,12 +133,15 @@ module Gitlab
def
user_attributes
def
user_attributes
# Give preference to LDAP for sensitive information when creating a linked account
# Give preference to LDAP for sensitive information when creating a linked account
username
,
email
=
if
creating_linked_ldap_user?
if
creating_linked_ldap_user?
[
ldap_person
.
username
,
ldap_person
.
email
.
first
]
username
=
ldap_person
.
username
email
=
ldap_person
.
email
.
first
else
else
[
auth_hash
.
username
,
auth_hash
.
email
]
username
=
auth_hash
.
username
email
=
auth_hash
.
email
end
end
return
{
{
name:
auth_hash
.
name
,
name:
auth_hash
.
name
,
username:
::
Namespace
.
clean_path
(
username
),
username:
::
Namespace
.
clean_path
(
username
),
email:
email
,
email:
email
,
...
...
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