Skip to content

Commit 1969fb7

Browse files
committed
[Update] 修改authentication backends
1 parent 9b35092 commit 1969fb7

9 files changed

Lines changed: 15 additions & 22 deletions

File tree

apps/audits/hands.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

apps/authentication/api/auth.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
from common.utils import get_logger, get_request_ip
1616
from common.permissions import IsOrgAdminOrAppUser
1717
from orgs.mixins import RootOrgViewMixin
18-
from authentication.signals import post_auth_success, post_auth_failed
1918
from users.serializers import UserSerializer
2019
from users.models import User, LoginLog
20+
from assets.models import Asset, SystemUser
2121
from users.utils import (
2222
check_user_valid, check_otp_code, increase_login_failed_count,
2323
is_block_login, clean_failed_count
2424
)
25-
from users.hands import Asset, SystemUser
25+
26+
from ..signals import post_auth_success, post_auth_failed
2627

2728
logger = get_logger(__name__)
2829
__all__ = [

apps/authentication/backends/openid/backends.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ def authenticate(self, request, username=None, password=None, **kwargs):
7575

7676
if not settings.AUTH_OPENID:
7777
return None
78-
7978
elif not username:
8079
return None
8180

apps/authentication/backends/openid/middleware.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
from .utils import new_client
1111
from .models import OIDT_ACCESS_TOKEN
1212

13-
BACKEND_OPENID_AUTH_CODE = \
14-
'authentication.backends.openid.OpenIDAuthorizationCodeBackend'
15-
client = new_client()
13+
BACKEND_OPENID_AUTH_CODE = 'OpenIDAuthorizationCodeBackend'
1614
logger = get_logger(__file__)
1715
__all__ = ['OpenIDAuthenticationMiddleware']
1816

@@ -23,22 +21,22 @@ class OpenIDAuthenticationMiddleware(MiddlewareMixin):
2321
"""
2422

2523
def process_request(self, request):
26-
2724
# Don't need openid auth if AUTH_OPENID is False
2825
if not settings.AUTH_OPENID:
2926
return
30-
3127
# Don't need check single logout if user not authenticated
3228
if not request.user.is_authenticated:
3329
return
34-
35-
elif request.session[BACKEND_SESSION_KEY] != BACKEND_OPENID_AUTH_CODE:
30+
elif request.session[BACKEND_SESSION_KEY].endswith(
31+
BACKEND_OPENID_AUTH_CODE):
3632
return
3733

3834
# Check openid user single logout or not with access_token
35+
client = new_client()
3936
try:
4037
client.openid_connect_client.userinfo(
41-
token=request.session.get(OIDT_ACCESS_TOKEN))
38+
token=request.session.get(OIDT_ACCESS_TOKEN)
39+
)
4240

4341
except Exception as e:
4442
logout(request)

apps/authentication/backends/openid/views.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
class OpenIDLoginView(RedirectView):
2727

2828
def get_redirect_url(self, *args, **kwargs):
29-
# Todo: 待优化
3029
redirect_uri = settings.BASE_SITE_URL + settings.LOGIN_COMPLETE_URL
3130
nonce = Nonce(
3231
redirect_uri=redirect_uri,
@@ -71,6 +70,8 @@ def get(self, request, *args, **kwargs):
7170
return HttpResponseBadRequest()
7271

7372
login(self.request, user)
74-
post_openid_login_success.send(sender=self.__class__, user=user, request=self.request)
73+
post_openid_login_success.send(
74+
sender=self.__class__, user=user, request=self.request
75+
)
7576
return HttpResponseRedirect(nonce.next_path or '/')
7677

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# -*- coding: utf-8 -*-
2+
#

apps/authentication/models.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

apps/users/urls/views_urls.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,4 @@
4646
path('user-group/<uuid:pk>/update/', views.UserGroupUpdateView.as_view(), name='user-group-update'),
4747
path('user-group/<uuid:pk>/assets/', views.UserGroupGrantedAssetView.as_view(), name='user-group-granted-asset'),
4848

49-
# Login log
50-
# Abandon
51-
# path('login-log/', views.LoginLogListView.as_view(), name='login-log-list'),
5249
]

apps/users/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from common.tasks import send_mail_async
2020
from common.utils import reverse, get_object_or_none, get_ip_city
21-
from .models import User, LoginLog
21+
from .models import User
2222

2323

2424
logger = logging.getLogger('jumpserver')

0 commit comments

Comments
 (0)