Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
6bf117c6
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6bf117c6
编写于
9月 02, 2013
作者:
D
Dmitriy Zaporozhets
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Mode User+LDAP functionality from Gitlab::Auth
上级
1f3f8741
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
99 addition
and
23 deletion
+99
-23
app/controllers/omniauth_callbacks_controller.rb
app/controllers/omniauth_callbacks_controller.rb
+6
-6
app/models/user.rb
app/models/user.rb
+1
-0
lib/gitlab/auth.rb
lib/gitlab/auth.rb
+0
-17
lib/gitlab/ldap/user.rb
lib/gitlab/ldap/user.rb
+92
-0
未找到文件。
app/controllers/omniauth_callbacks_controller.rb
浏览文件 @
6bf117c6
...
...
@@ -16,12 +16,12 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
end
def
ldap
# We only find ourselves here
if the authentication to LDAP was successful.
@user
=
User
.
find_for_ldap_auth
(
request
.
env
[
"omniauth.auth"
],
current_user
)
if
@user
.
persisted?
@user
.
remember_me
=
true
end
sign_in_and_redirect
@user
# We only find ourselves here
# if the authentication to LDAP was successful.
@user
=
Gitlab
::
LDAP
::
User
.
find_or_create
(
request
.
env
[
"omniauth.auth"
])
@user
.
remember_me
=
true
if
@user
.
persisted?
sign_in_and_redirect
(
@user
)
end
private
...
...
app/models/user.rb
浏览文件 @
6bf117c6
...
...
@@ -159,6 +159,7 @@ class User < ActiveRecord::Base
scope
:not_in_team
,
->
(
team
){
where
(
'users.id NOT IN (:ids)'
,
ids:
team
.
member_ids
)
}
scope
:not_in_project
,
->
(
project
)
{
project
.
users
.
present?
?
where
(
"id not in (:ids)"
,
ids:
project
.
users
.
map
(
&
:id
)
)
:
scoped
}
scope
:without_projects
,
->
{
where
(
'id NOT IN (SELECT DISTINCT(user_id) FROM users_projects)'
)
}
scope
:ldap
,
->
{
where
(
provider:
'ldap'
)
}
scope
:potential_team_members
,
->
(
team
)
{
team
.
members
.
any?
?
active
.
not_in_team
(
team
)
:
active
}
...
...
lib/gitlab/auth.rb
浏览文件 @
6bf117c6
...
...
@@ -13,23 +13,6 @@ module Gitlab
end
end
def
find_for_ldap_auth
(
auth
,
signed_in_resource
=
nil
)
uid
=
auth
.
info
.
uid
provider
=
auth
.
provider
email
=
auth
.
info
.
email
.
downcase
unless
auth
.
info
.
email
.
nil?
raise
OmniAuth
::
Error
,
"LDAP accounts must provide an uid and email address"
if
uid
.
nil?
or
email
.
nil?
if
@user
=
User
.
find_by_extern_uid_and_provider
(
uid
,
provider
)
@user
elsif
@user
=
User
.
find_by_email
(
email
)
log
.
info
"Updating legacy LDAP user
#{
email
}
with extern_uid =>
#{
uid
}
"
@user
.
update_attributes
(
extern_uid:
uid
,
provider:
provider
)
@user
else
create_from_omniauth
(
auth
,
true
)
end
end
def
create_from_omniauth
(
auth
,
ldap
=
false
)
provider
=
auth
.
provider
uid
=
auth
.
info
.
uid
||
auth
.
uid
...
...
lib/gitlab/ldap/user.rb
0 → 100644
浏览文件 @
6bf117c6
# LDAP extension for User model
#
# * Find or create user from omniauth.auth data
# * Links LDAP account with existing user
#
module
Gitlab
module
LDAP
class
User
class
<<
self
def
find
(
uid
,
email
)
# Look for user with ldap provider and same uid
user
=
model
.
ldap
.
where
(
extern_uid:
uid
).
last
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
)
uid
,
email
,
name
=
uid
(
auth
),
email
(
auth
),
name
(
auth
)
if
uid
.
blank?
||
email
.
blank?
raise_error
(
"Account must provide an uid and email address"
)
end
user
=
find
(
uid
,
email
)
user
=
create
(
uid
,
email
,
name
)
unless
user
user
end
private
def
uid
(
auth
)
auth
.
info
.
uid
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
def
log
Gitlab
::
AppLogger
end
def
raise_error
(
message
)
raise
OmniAuth
::
Error
,
"(LDAP) "
+
message
end
def
model
::
User
end
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录