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
f99d6d75
Commit
f99d6d75
authored
Apr 23, 2018
by
James Edwards-Jones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Group SAML links user Identity
parent
1b61a419
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
1 deletion
+84
-1
app/controllers/omniauth_callbacks_controller.rb
app/controllers/omniauth_callbacks_controller.rb
+1
-1
ee/lib/gitlab/auth/group_saml/identity_linker.rb
ee/lib/gitlab/auth/group_saml/identity_linker.rb
+24
-0
ee/spec/lib/gitlab/auth/group_saml/identity_linker_spec.rb
ee/spec/lib/gitlab/auth/group_saml/identity_linker_spec.rb
+55
-0
lib/gitlab/auth/omniauth_identity_linker_base.rb
lib/gitlab/auth/omniauth_identity_linker_base.rb
+4
-0
No files found.
app/controllers/omniauth_callbacks_controller.rb
View file @
f99d6d75
...
@@ -93,7 +93,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
...
@@ -93,7 +93,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
if
identity_linker
.
changed?
if
identity_linker
.
changed?
redirect_identity_linked
redirect_identity_linked
elsif
identity_linker
.
error_message
.
present
?
elsif
identity_linker
.
failed
?
redirect_identity_link_failed
(
identity_linker
.
error_message
)
redirect_identity_link_failed
(
identity_linker
.
error_message
)
else
else
redirect_identity_exists
redirect_identity_exists
...
...
ee/lib/gitlab/auth/group_saml/identity_linker.rb
0 → 100644
View file @
f99d6d75
module
Gitlab
module
Auth
module
GroupSaml
class
IdentityLinker
<
Gitlab
::
Auth
::
Saml
::
IdentityLinker
attr_reader
:saml_provider
def
initialize
(
current_user
,
oauth
,
saml_provider
)
super
(
current_user
,
oauth
)
@saml_provider
=
saml_provider
end
protected
def
identity
@identity
||=
current_user
.
identities
.
where
(
provider: :group_saml
,
saml_provider:
saml_provider
,
extern_uid:
uid
.
to_s
)
.
first_or_initialize
end
end
end
end
end
ee/spec/lib/gitlab/auth/group_saml/identity_linker_spec.rb
0 → 100644
View file @
f99d6d75
require
'spec_helper'
describe
Gitlab
::
Auth
::
GroupSaml
::
IdentityLinker
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:provider
)
{
'group_saml'
}
let
(
:uid
)
{
user
.
email
}
let
(
:oauth
)
{
{
'provider'
=>
provider
,
'uid'
=>
uid
}
}
let
(
:saml_provider
)
{
create
(
:saml_provider
)
}
subject
{
described_class
.
new
(
user
,
oauth
,
saml_provider
)
}
context
'linked identity exists'
do
let!
(
:identity
)
{
user
.
identities
.
create!
(
provider:
provider
,
extern_uid:
uid
,
saml_provider:
saml_provider
)
}
it
"doesn't create new identity"
do
expect
{
subject
.
link
}.
not_to
change
{
Identity
.
count
}
end
it
"sets #changed? to false"
do
subject
.
link
expect
(
subject
).
not_to
be_changed
end
end
context
'identity needs to be created'
do
it
'creates linked identity'
do
expect
{
subject
.
link
}.
to
change
{
user
.
identities
.
count
}
end
it
'sets identity provider'
do
subject
.
link
expect
(
user
.
identities
.
last
.
provider
).
to
eq
provider
end
it
'sets saml provider'
do
subject
.
link
expect
(
user
.
identities
.
last
.
saml_provider
).
to
eq
saml_provider
end
it
'sets identity extern_uid'
do
subject
.
link
expect
(
user
.
identities
.
last
.
extern_uid
).
to
eq
uid
end
it
'sets #changed? to true'
do
subject
.
link
expect
(
subject
).
to
be_changed
end
end
end
lib/gitlab/auth/omniauth_identity_linker_base.rb
View file @
f99d6d75
...
@@ -17,6 +17,10 @@ module Gitlab
...
@@ -17,6 +17,10 @@ module Gitlab
@changed
@changed
end
end
def
failed?
error_message
.
present?
end
def
error_message
def
error_message
identity
.
validate
identity
.
validate
...
...
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