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
0df1cf7f
Commit
0df1cf7f
authored
Sep 04, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Inherit Gitlab::LDAP::User from Gitlab::OAuth::User
parent
b45e9264
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
67 deletions
+33
-67
lib/gitlab/ldap/user.rb
lib/gitlab/ldap/user.rb
+33
-67
No files found.
lib/gitlab/ldap/user.rb
View file @
0df1cf7f
require
'gitlab/oauth/user'
# LDAP extension for User model
# LDAP extension for User model
#
#
# * Find or create user from omniauth.auth data
# * Find or create user from omniauth.auth data
# * Links LDAP account with existing user
# * Links LDAP account with existing user
# * Auth LDAP user with login and password
#
#
module
Gitlab
module
Gitlab
module
LDAP
module
LDAP
class
User
class
User
<
Gitlab
::
OAuth
::
User
class
<<
self
class
<<
self
def
find
(
uid
,
email
)
# Look for user with ldap provider and same uid
user
=
find_by_uid
(
uid
)
return
user
if
user
# Look for user with same emails
#
# Possible cases:
# * When user already has account and need to link his LDAP account.
# * LDAP uid changed for user with same email and we need to update his uid
#
user
=
model
.
find_by_email
(
email
)
if
user
user
.
update_attributes
(
extern_uid:
uid
,
provider:
'ldap'
)
log
.
info
(
"(LDAP) Updating legacy LDAP user
#{
email
}
with extern_uid =>
#{
uid
}
"
)
end
user
end
def
create
(
uid
,
email
,
name
)
password
=
Devise
.
friendly_token
[
0
,
8
].
downcase
username
=
email
.
match
(
/^[^@]*/
)[
0
]
opts
=
{
extern_uid:
uid
,
provider:
'ldap'
,
name:
name
,
username:
username
,
email:
email
,
password:
password
,
password_confirmation:
password
,
}
user
=
model
.
new
(
opts
,
as: :admin
).
with_defaults
user
.
save!
log
.
info
"(LDAP) Creating user
#{
email
}
from login with extern_uid =>
#{
uid
}
"
user
end
def
find_or_create
(
auth
)
def
find_or_create
(
auth
)
uid
,
email
,
name
=
uid
(
auth
),
email
(
auth
),
name
(
auth
)
@auth
=
auth
if
uid
.
blank?
||
email
.
blank?
if
uid
.
blank?
||
email
.
blank?
raise_error
(
"Account must provide an uid and email address"
)
raise_error
(
"Account must provide an uid and email address"
)
end
end
user
=
find
(
uid
,
email
)
user
=
find
(
auth
)
user
=
create
(
uid
,
email
,
name
)
unless
user
user
unless
user
end
# Look for user with same emails
#
# Possible cases:
# * When user already has account and need to link his LDAP account.
# * LDAP uid changed for user with same email and we need to update his uid
#
user
=
model
.
find_by_email
(
email
)
if
user
user
.
update_attributes
(
extern_uid:
uid
,
provider:
provider
)
log
.
info
(
"(LDAP) Updating legacy LDAP user
#{
email
}
with extern_uid =>
#{
uid
}
"
)
else
# Create a new user inside GitLab database
# based on LDAP credentials
#
#
user
=
create
(
auth
)
end
end
def
find_by_uid
(
uid
)
user
model
.
ldap
.
where
(
extern_uid:
uid
).
last
end
end
def
auth
(
login
,
password
)
def
auth
enticate
(
login
,
password
)
# Check user against LDAP backend if user is not authenticated
# Check user against LDAP backend if user is not authenticated
# Only check with valid login and password to prevent anonymous bind results
# Only check with valid login and password to prevent anonymous bind results
return
nil
unless
ldap_conf
.
enabled
&&
login
.
present?
&&
password
.
present?
return
nil
unless
ldap_conf
.
enabled
&&
login
.
present?
&&
password
.
present?
...
@@ -82,30 +60,18 @@ module Gitlab
...
@@ -82,30 +60,18 @@ module Gitlab
private
private
def
uid
(
auth
)
def
find_by_uid
(
uid
)
auth
.
info
.
uid
model
.
where
(
provider:
provider
,
extern_uid:
uid
).
last
end
def
email
(
auth
)
auth
.
info
.
email
.
downcase
unless
auth
.
info
.
email
.
nil?
end
def
name
(
auth
)
auth
.
info
.
name
.
to_s
.
force_encoding
(
"utf-8"
)
end
end
def
log
def
provider
Gitlab
::
AppLogger
'ldap'
end
end
def
raise_error
(
message
)
def
raise_error
(
message
)
raise
OmniAuth
::
Error
,
"(LDAP) "
+
message
raise
OmniAuth
::
Error
,
"(LDAP) "
+
message
end
end
def
model
::
User
end
def
ldap_conf
def
ldap_conf
Gitlab
.
config
.
ldap
Gitlab
.
config
.
ldap
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