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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
e900ff97
Commit
e900ff97
authored
May 13, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve JwtController code
parent
9ef9e008
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
18 deletions
+19
-18
app/controllers/jwt_controller.rb
app/controllers/jwt_controller.rb
+19
-18
No files found.
app/controllers/jwt_controller.rb
View file @
e900ff97
class
JwtController
<
ApplicationController
skip_before_action
:authenticate_user!
skip_before_action
:verify_authenticity_token
before_action
:authenticate_project_or_user
SERVICES
=
{
'container_registry'
=>
::
Gitlab
::
JWT
::
ContainerRegistryAuthenticationService
,
}
def
auth
@authenticated
=
authenticate_with_http_basic
do
|
login
,
password
|
# if it's possible we first try to authenticate project with login and password
@project
=
authenticate_project
(
login
,
password
)
@user
=
authenticate_user
(
login
,
password
)
unless
@project
end
unless
@authenticated
head
:forbidden
if
ActionController
::
HttpAuthentication
::
Basic
.
has_basic_credentials?
(
request
)
end
service
=
SERVICES
[
params
[
:service
]]
head
:not_found
unless
service
...
...
@@ -28,19 +19,28 @@ class JwtController < ApplicationController
private
def
authenticate_project_or_user
authenticate_with_http_basic
do
|
login
,
password
|
# if it's possible we first try to authenticate project with login and password
@project
=
authenticate_project
(
login
,
password
)
return
if
@project
@user
=
authenticate_user
(
login
,
password
)
return
if
@user
end
if
ActionController
::
HttpAuthentication
::
Basic
.
has_basic_credentials?
(
request
)
head
:forbidden
end
end
def
auth_params
params
.
permit
(
:service
,
:scope
,
:offline_token
,
:account
,
:client_id
)
end
def
authenticate_project
(
login
,
password
)
matched_login
=
/(?<s>^[a-zA-Z]*-ci)-token$/
.
match
(
login
)
if
matched_login
.
present?
underscored_service
=
matched_login
[
's'
].
underscore
if
underscored_service
==
'gitlab_ci'
Project
.
find_by
(
builds_enabled:
true
,
runners_token:
password
)
end
if
login
==
'gitlab_ci_token'
Project
.
find_by
(
builds_enabled:
true
,
runners_token:
password
)
end
end
...
...
@@ -77,6 +77,7 @@ class JwtController < ApplicationController
if
banned
Rails
.
logger
.
info
"IP
#{
request
.
ip
}
failed to login "
\
"as
#{
login
}
but has been temporarily banned from Git auth"
return
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