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
49317371
Unverified
Commit
49317371
authored
Sep 16, 2019
by
BaiJiangJie
Committed by
GitHub
Sep 16, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3230 from jumpserver/dev_auth
[Bugfix] 修复用户认证序列类获取 request 的问题
parents
58288975
4797f99f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
3 deletions
+29
-3
auth.py
apps/authentication/api/auth.py
+23
-3
permissions.py
apps/common/permissions.py
+6
-0
No files found.
apps/authentication/api/auth.py
View file @
49317371
...
@@ -41,6 +41,16 @@ class UserAuthApi(RootOrgViewMixin, APIView):
...
@@ -41,6 +41,16 @@ class UserAuthApi(RootOrgViewMixin, APIView):
permission_classes
=
(
AllowAny
,)
permission_classes
=
(
AllowAny
,)
serializer_class
=
UserSerializer
serializer_class
=
UserSerializer
def
get_serializer_context
(
self
):
return
{
'request'
:
self
.
request
,
'view'
:
self
}
def
get_serializer
(
self
,
*
args
,
**
kwargs
):
kwargs
[
'context'
]
=
self
.
get_serializer_context
()
return
self
.
serializer_class
(
*
args
,
**
kwargs
)
def
post
(
self
,
request
):
def
post
(
self
,
request
):
# limit login
# limit login
username
=
request
.
data
.
get
(
'username'
)
username
=
request
.
data
.
get
(
'username'
)
...
@@ -65,7 +75,7 @@ class UserAuthApi(RootOrgViewMixin, APIView):
...
@@ -65,7 +75,7 @@ class UserAuthApi(RootOrgViewMixin, APIView):
clean_failed_count
(
username
,
ip
)
clean_failed_count
(
username
,
ip
)
token
,
expired_at
=
user
.
create_bearer_token
(
request
)
token
,
expired_at
=
user
.
create_bearer_token
(
request
)
return
Response
(
return
Response
(
{
'token'
:
token
,
'user'
:
self
.
serializer_class
(
user
)
.
data
}
{
'token'
:
token
,
'user'
:
self
.
get_serializer
(
user
)
.
data
}
)
)
seed
=
uuid
.
uuid4
()
.
hex
seed
=
uuid
.
uuid4
()
.
hex
...
@@ -77,7 +87,7 @@ class UserAuthApi(RootOrgViewMixin, APIView):
...
@@ -77,7 +87,7 @@ class UserAuthApi(RootOrgViewMixin, APIView):
'conduct MFA secondary certification'
),
'conduct MFA secondary certification'
),
'otp_url'
:
reverse
(
'api-auth:user-otp-auth'
),
'otp_url'
:
reverse
(
'api-auth:user-otp-auth'
),
'seed'
:
seed
,
'seed'
:
seed
,
'user'
:
self
.
serializer_class
(
user
)
.
data
'user'
:
self
.
get_serializer
(
user
)
.
data
},
status
=
300
},
status
=
300
)
)
...
@@ -147,6 +157,16 @@ class UserOtpAuthApi(RootOrgViewMixin, APIView):
...
@@ -147,6 +157,16 @@ class UserOtpAuthApi(RootOrgViewMixin, APIView):
permission_classes
=
(
AllowAny
,)
permission_classes
=
(
AllowAny
,)
serializer_class
=
UserSerializer
serializer_class
=
UserSerializer
def
get_serializer_context
(
self
):
return
{
'request'
:
self
.
request
,
'view'
:
self
}
def
get_serializer
(
self
,
*
args
,
**
kwargs
):
kwargs
[
'context'
]
=
self
.
get_serializer_context
()
return
self
.
serializer_class
(
*
args
,
**
kwargs
)
def
post
(
self
,
request
):
def
post
(
self
,
request
):
otp_code
=
request
.
data
.
get
(
'otp_code'
,
''
)
otp_code
=
request
.
data
.
get
(
'otp_code'
,
''
)
seed
=
request
.
data
.
get
(
'seed'
,
''
)
seed
=
request
.
data
.
get
(
'seed'
,
''
)
...
@@ -161,7 +181,7 @@ class UserOtpAuthApi(RootOrgViewMixin, APIView):
...
@@ -161,7 +181,7 @@ class UserOtpAuthApi(RootOrgViewMixin, APIView):
return
Response
({
'msg'
:
_
(
'MFA certification failed'
)},
status
=
401
)
return
Response
({
'msg'
:
_
(
'MFA certification failed'
)},
status
=
401
)
self
.
send_auth_signal
(
success
=
True
,
user
=
user
)
self
.
send_auth_signal
(
success
=
True
,
user
=
user
)
token
,
expired_at
=
user
.
create_bearer_token
(
request
)
token
,
expired_at
=
user
.
create_bearer_token
(
request
)
data
=
{
'token'
:
token
,
'user'
:
self
.
serializer_class
(
user
)
.
data
}
data
=
{
'token'
:
token
,
'user'
:
self
.
get_serializer
(
user
)
.
data
}
return
Response
(
data
)
return
Response
(
data
)
def
send_auth_signal
(
self
,
success
=
True
,
user
=
None
,
username
=
''
,
reason
=
''
):
def
send_auth_signal
(
self
,
success
=
True
,
user
=
None
,
username
=
''
,
reason
=
''
):
...
...
apps/common/permissions.py
View file @
49317371
...
@@ -132,6 +132,8 @@ class CanUpdateDeleteUser(permissions.BasePermission):
...
@@ -132,6 +132,8 @@ class CanUpdateDeleteUser(permissions.BasePermission):
@staticmethod
@staticmethod
def
has_delete_object_permission
(
request
,
view
,
obj
):
def
has_delete_object_permission
(
request
,
view
,
obj
):
if
request
.
user
.
is_anonymous
:
return
False
if
not
request
.
user
.
can_admin_current_org
:
if
not
request
.
user
.
can_admin_current_org
:
return
False
return
False
# 超级管理员 / 组织管理员
# 超级管理员 / 组织管理员
...
@@ -157,6 +159,8 @@ class CanUpdateDeleteUser(permissions.BasePermission):
...
@@ -157,6 +159,8 @@ class CanUpdateDeleteUser(permissions.BasePermission):
@staticmethod
@staticmethod
def
has_update_object_permission
(
request
,
view
,
obj
):
def
has_update_object_permission
(
request
,
view
,
obj
):
if
request
.
user
.
is_anonymous
:
return
False
if
not
request
.
user
.
can_admin_current_org
:
if
not
request
.
user
.
can_admin_current_org
:
return
False
return
False
# 超级管理员 / 组织管理员
# 超级管理员 / 组织管理员
...
@@ -179,6 +183,8 @@ class CanUpdateDeleteUser(permissions.BasePermission):
...
@@ -179,6 +183,8 @@ class CanUpdateDeleteUser(permissions.BasePermission):
return
True
return
True
def
has_object_permission
(
self
,
request
,
view
,
obj
):
def
has_object_permission
(
self
,
request
,
view
,
obj
):
if
request
.
user
.
is_anonymous
:
return
False
if
not
request
.
user
.
can_admin_current_org
:
if
not
request
.
user
.
can_admin_current_org
:
return
False
return
False
if
request
.
method
in
[
'DELETE'
]:
if
request
.
method
in
[
'DELETE'
]:
...
...
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