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
Boxiang Sun
gitlab-ce
Commits
7038440e
Commit
7038440e
authored
Jun 06, 2016
by
Patricio Cano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adjust the SAML control flow to allow LDAP identities to be added to an existing SAML user.
parent
740a6ecb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
3 deletions
+46
-3
lib/gitlab/o_auth/user.rb
lib/gitlab/o_auth/user.rb
+1
-1
lib/gitlab/saml/user.rb
lib/gitlab/saml/user.rb
+26
-2
spec/lib/gitlab/saml/user_spec.rb
spec/lib/gitlab/saml/user_spec.rb
+19
-0
No files found.
lib/gitlab/o_auth/user.rb
View file @
7038440e
...
@@ -96,7 +96,7 @@ module Gitlab
...
@@ -96,7 +96,7 @@ module Gitlab
# Look for a corresponding person with same uid in any of the configured LDAP providers
# Look for a corresponding person with same uid in any of the configured LDAP providers
Gitlab
::
LDAP
::
Config
.
providers
.
each
do
|
provider
|
Gitlab
::
LDAP
::
Config
.
providers
.
each
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
)
@ldap_person
=
Gitlab
::
LDAP
::
Person
.
find_by_
dn
(
auth_hash
.
uid
,
adapter
)
break
if
@ldap_person
break
if
@ldap_person
end
end
@ldap_person
@ldap_person
...
...
lib/gitlab/saml/user.rb
View file @
7038440e
...
@@ -12,12 +12,12 @@ module Gitlab
...
@@ -12,12 +12,12 @@ module Gitlab
end
end
def
gl_user
def
gl_user
@user
||=
find_by_uid_and_provider
if
auto_link_ldap_user?
if
auto_link_ldap_user?
@user
||=
find_or_create_ldap_user
@user
||=
find_or_create_ldap_user
end
end
@user
||=
find_by_uid_and_provider
if
auto_link_saml_user?
if
auto_link_saml_user?
@user
||=
find_by_email
@user
||=
find_by_email
end
end
...
@@ -62,6 +62,30 @@ module Gitlab
...
@@ -62,6 +62,30 @@ module Gitlab
!
Gitlab
::
Saml
::
Config
.
external_groups
.
nil?
!
Gitlab
::
Saml
::
Config
.
external_groups
.
nil?
end
end
def
find_or_create_ldap_user
return
unless
ldap_person
# If a corresponding person exists with same uid in a LDAP server,
# check if the user already has a GitLab account
user
=
Gitlab
::
LDAP
::
User
.
find_by_uid_and_provider
(
ldap_person
.
dn
,
ldap_person
.
provider
)
if
user
# Case when a LDAP user already exists in Gitlab. Add the SAML identity to existing account.
user
.
identities
.
build
(
extern_uid:
auth_hash
.
uid
,
provider:
auth_hash
.
provider
)
else
# No account found using LDAP in Gitlab yet: check if there is a SAML account with
# the passed uid and provider
user
=
find_by_uid_and_provider
if
user
.
nil?
# No SAML account found, build a new user.
user
=
build_new_user
end
# Correct account is present, add the LDAP Identity to the user.
user
.
identities
.
new
(
provider:
ldap_person
.
provider
,
extern_uid:
ldap_person
.
dn
)
end
user
end
def
auth_hash
=
(
auth_hash
)
def
auth_hash
=
(
auth_hash
)
@auth_hash
=
Gitlab
::
Saml
::
AuthHash
.
new
(
auth_hash
)
@auth_hash
=
Gitlab
::
Saml
::
AuthHash
.
new
(
auth_hash
)
end
end
...
...
spec/lib/gitlab/saml/user_spec.rb
View file @
7038440e
...
@@ -145,6 +145,7 @@ describe Gitlab::Saml::User, lib: true do
...
@@ -145,6 +145,7 @@ describe Gitlab::Saml::User, lib: true do
allow
(
ldap_user
).
to
receive
(
:email
)
{
%w(john@mail.com john2@example.com)
}
allow
(
ldap_user
).
to
receive
(
:email
)
{
%w(john@mail.com john2@example.com)
}
allow
(
ldap_user
).
to
receive
(
:dn
)
{
'uid=user1,ou=People,dc=example'
}
allow
(
ldap_user
).
to
receive
(
:dn
)
{
'uid=user1,ou=People,dc=example'
}
allow
(
Gitlab
::
LDAP
::
Person
).
to
receive
(
:find_by_uid
).
and_return
(
ldap_user
)
allow
(
Gitlab
::
LDAP
::
Person
).
to
receive
(
:find_by_uid
).
and_return
(
ldap_user
)
allow
(
Gitlab
::
LDAP
::
Person
).
to
receive
(
:find_by_dn
).
and_return
(
ldap_user
)
end
end
context
'and no account for the LDAP user'
do
context
'and no account for the LDAP user'
do
...
@@ -177,6 +178,24 @@ describe Gitlab::Saml::User, lib: true do
...
@@ -177,6 +178,24 @@ describe Gitlab::Saml::User, lib: true do
])
])
end
end
end
end
context
'user has SAML user, and wants to add their LDAP identity'
do
it
'adds the LDAP identity to the existing SAML user'
do
create
(
:omniauth_user
,
email:
'john@mail.com'
,
extern_uid:
'uid=user1,ou=People,dc=example'
,
provider:
'saml'
,
username:
'john'
)
local_hash
=
OmniAuth
::
AuthHash
.
new
(
uid:
'uid=user1,ou=People,dc=example'
,
provider:
provider
,
info:
info_hash
,
extra:
{
raw_info:
OneLogin
::
RubySaml
::
Attributes
.
new
({
'groups'
=>
%w(Developers Freelancers Designers)
})
})
local_saml_user
=
described_class
.
new
(
local_hash
)
local_saml_user
.
save
local_gl_user
=
local_saml_user
.
gl_user
expect
(
local_gl_user
).
to
be_valid
expect
(
local_gl_user
.
identities
.
length
).
to
eql
2
identities_as_hash
=
local_gl_user
.
identities
.
map
{
|
id
|
{
provider:
id
.
provider
,
extern_uid:
id
.
extern_uid
}
}
expect
(
identities_as_hash
).
to
match_array
([
{
provider:
'ldapmain'
,
extern_uid:
'uid=user1,ou=People,dc=example'
},
{
provider:
'saml'
,
extern_uid:
'uid=user1,ou=People,dc=example'
}
])
end
end
end
end
end
end
end
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