Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
1969fb79
Commit
1969fb79
authored
Feb 28, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改authentication backends
parent
9b350920
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
13 additions
and
21 deletions
+13
-21
auth.py
apps/authentication/api/auth.py
+3
-2
backends.py
apps/authentication/backends/openid/backends.py
+0
-1
middleware.py
apps/authentication/backends/openid/middleware.py
+6
-8
views.py
apps/authentication/backends/openid/views.py
+3
-2
__init__.py
apps/authentication/migrations/__init__.py
+0
-3
models.py
apps/authentication/models.py
+0
-1
views_urls.py
apps/users/urls/views_urls.py
+0
-3
utils.py
apps/users/utils.py
+1
-1
No files found.
apps/authentication/api/auth.py
View file @
1969fb79
...
@@ -15,14 +15,15 @@ from rest_framework.views import APIView
...
@@ -15,14 +15,15 @@ from rest_framework.views import APIView
from
common.utils
import
get_logger
,
get_request_ip
from
common.utils
import
get_logger
,
get_request_ip
from
common.permissions
import
IsOrgAdminOrAppUser
from
common.permissions
import
IsOrgAdminOrAppUser
from
orgs.mixins
import
RootOrgViewMixin
from
orgs.mixins
import
RootOrgViewMixin
from
authentication.signals
import
post_auth_success
,
post_auth_failed
from
users.serializers
import
UserSerializer
from
users.serializers
import
UserSerializer
from
users.models
import
User
,
LoginLog
from
users.models
import
User
,
LoginLog
from
assets.models
import
Asset
,
SystemUser
from
users.utils
import
(
from
users.utils
import
(
check_user_valid
,
check_otp_code
,
increase_login_failed_count
,
check_user_valid
,
check_otp_code
,
increase_login_failed_count
,
is_block_login
,
clean_failed_count
is_block_login
,
clean_failed_count
)
)
from
users.hands
import
Asset
,
SystemUser
from
..signals
import
post_auth_success
,
post_auth_failed
logger
=
get_logger
(
__name__
)
logger
=
get_logger
(
__name__
)
__all__
=
[
__all__
=
[
...
...
apps/authentication/backends/openid/backends.py
View file @
1969fb79
...
@@ -75,7 +75,6 @@ class OpenIDAuthorizationPasswordBackend(BaseOpenIDAuthorizationBackend):
...
@@ -75,7 +75,6 @@ class OpenIDAuthorizationPasswordBackend(BaseOpenIDAuthorizationBackend):
if
not
settings
.
AUTH_OPENID
:
if
not
settings
.
AUTH_OPENID
:
return
None
return
None
elif
not
username
:
elif
not
username
:
return
None
return
None
...
...
apps/authentication/backends/openid/middleware.py
View file @
1969fb79
...
@@ -10,9 +10,7 @@ from common.utils import get_logger
...
@@ -10,9 +10,7 @@ from common.utils import get_logger
from
.utils
import
new_client
from
.utils
import
new_client
from
.models
import
OIDT_ACCESS_TOKEN
from
.models
import
OIDT_ACCESS_TOKEN
BACKEND_OPENID_AUTH_CODE
=
\
BACKEND_OPENID_AUTH_CODE
=
'OpenIDAuthorizationCodeBackend'
'authentication.backends.openid.OpenIDAuthorizationCodeBackend'
client
=
new_client
()
logger
=
get_logger
(
__file__
)
logger
=
get_logger
(
__file__
)
__all__
=
[
'OpenIDAuthenticationMiddleware'
]
__all__
=
[
'OpenIDAuthenticationMiddleware'
]
...
@@ -23,22 +21,22 @@ class OpenIDAuthenticationMiddleware(MiddlewareMixin):
...
@@ -23,22 +21,22 @@ class OpenIDAuthenticationMiddleware(MiddlewareMixin):
"""
"""
def
process_request
(
self
,
request
):
def
process_request
(
self
,
request
):
# Don't need openid auth if AUTH_OPENID is False
# Don't need openid auth if AUTH_OPENID is False
if
not
settings
.
AUTH_OPENID
:
if
not
settings
.
AUTH_OPENID
:
return
return
# Don't need check single logout if user not authenticated
# Don't need check single logout if user not authenticated
if
not
request
.
user
.
is_authenticated
:
if
not
request
.
user
.
is_authenticated
:
return
return
elif
request
.
session
[
BACKEND_SESSION_KEY
]
.
endswith
(
elif
request
.
session
[
BACKEND_SESSION_KEY
]
!=
BACKEND_OPENID_AUTH_CODE
:
BACKEND_OPENID_AUTH_CODE
)
:
return
return
# Check openid user single logout or not with access_token
# Check openid user single logout or not with access_token
client
=
new_client
()
try
:
try
:
client
.
openid_connect_client
.
userinfo
(
client
.
openid_connect_client
.
userinfo
(
token
=
request
.
session
.
get
(
OIDT_ACCESS_TOKEN
))
token
=
request
.
session
.
get
(
OIDT_ACCESS_TOKEN
)
)
except
Exception
as
e
:
except
Exception
as
e
:
logout
(
request
)
logout
(
request
)
...
...
apps/authentication/backends/openid/views.py
View file @
1969fb79
...
@@ -26,7 +26,6 @@ __all__ = ['OpenIDLoginView', 'OpenIDLoginCompleteView']
...
@@ -26,7 +26,6 @@ __all__ = ['OpenIDLoginView', 'OpenIDLoginCompleteView']
class
OpenIDLoginView
(
RedirectView
):
class
OpenIDLoginView
(
RedirectView
):
def
get_redirect_url
(
self
,
*
args
,
**
kwargs
):
def
get_redirect_url
(
self
,
*
args
,
**
kwargs
):
# Todo: 待优化
redirect_uri
=
settings
.
BASE_SITE_URL
+
settings
.
LOGIN_COMPLETE_URL
redirect_uri
=
settings
.
BASE_SITE_URL
+
settings
.
LOGIN_COMPLETE_URL
nonce
=
Nonce
(
nonce
=
Nonce
(
redirect_uri
=
redirect_uri
,
redirect_uri
=
redirect_uri
,
...
@@ -71,6 +70,8 @@ class OpenIDLoginCompleteView(RedirectView):
...
@@ -71,6 +70,8 @@ class OpenIDLoginCompleteView(RedirectView):
return
HttpResponseBadRequest
()
return
HttpResponseBadRequest
()
login
(
self
.
request
,
user
)
login
(
self
.
request
,
user
)
post_openid_login_success
.
send
(
sender
=
self
.
__class__
,
user
=
user
,
request
=
self
.
request
)
post_openid_login_success
.
send
(
sender
=
self
.
__class__
,
user
=
user
,
request
=
self
.
request
)
return
HttpResponseRedirect
(
nonce
.
next_path
or
'/'
)
return
HttpResponseRedirect
(
nonce
.
next_path
or
'/'
)
apps/au
dits/hands
.py
→
apps/au
thentication/migrations/__init__
.py
View file @
1969fb79
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#
#
from
users.models
import
LoginLog
\ No newline at end of file
apps/authentication/models.py
View file @
1969fb79
apps/users/urls/views_urls.py
View file @
1969fb79
...
@@ -46,7 +46,4 @@ urlpatterns = [
...
@@ -46,7 +46,4 @@ urlpatterns = [
path
(
'user-group/<uuid:pk>/update/'
,
views
.
UserGroupUpdateView
.
as_view
(),
name
=
'user-group-update'
),
path
(
'user-group/<uuid:pk>/update/'
,
views
.
UserGroupUpdateView
.
as_view
(),
name
=
'user-group-update'
),
path
(
'user-group/<uuid:pk>/assets/'
,
views
.
UserGroupGrantedAssetView
.
as_view
(),
name
=
'user-group-granted-asset'
),
path
(
'user-group/<uuid:pk>/assets/'
,
views
.
UserGroupGrantedAssetView
.
as_view
(),
name
=
'user-group-granted-asset'
),
# Login log
# Abandon
# path('login-log/', views.LoginLogListView.as_view(), name='login-log-list'),
]
]
apps/users/utils.py
View file @
1969fb79
...
@@ -18,7 +18,7 @@ from datetime import datetime
...
@@ -18,7 +18,7 @@ from datetime import datetime
from
common.tasks
import
send_mail_async
from
common.tasks
import
send_mail_async
from
common.utils
import
reverse
,
get_object_or_none
,
get_ip_city
from
common.utils
import
reverse
,
get_object_or_none
,
get_ip_city
from
.models
import
User
,
LoginLog
from
.models
import
User
logger
=
logging
.
getLogger
(
'jumpserver'
)
logger
=
logging
.
getLogger
(
'jumpserver'
)
...
...
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