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
327febaf
Commit
327febaf
authored
Jun 24, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 更改查看认证需要的MFA时间间隔
parent
0f8d4f5b
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
21 additions
and
16 deletions
+21
-16
asset_user.py
apps/assets/api/asset_user.py
+6
-12
_asset_user_list.html
apps/assets/templates/assets/_asset_user_list.html
+3
-2
auth.py
apps/authentication/api/auth.py
+1
-1
permissions.py
apps/common/permissions.py
+8
-0
conf.py
apps/jumpserver/conf.py
+1
-1
context_processor.py
apps/jumpserver/context_processor.py
+1
-0
settings.py
apps/jumpserver/settings.py
+1
-0
django.mo
apps/locale/zh/LC_MESSAGES/django.mo
+0
-0
django.po
apps/locale/zh/LC_MESSAGES/django.po
+0
-0
No files found.
apps/assets/api/asset_user.py
View file @
327febaf
...
...
@@ -10,7 +10,7 @@ from rest_framework import filters
from
rest_framework_bulk
import
BulkModelViewSet
from
django.shortcuts
import
get_object_or_404
from
common.permissions
import
IsOrgAdminOrAppUser
from
common.permissions
import
IsOrgAdminOrAppUser
,
NeedMFAVerify
from
common.utils
import
get_object_or_none
,
get_logger
from
common.mixins
import
IDInCacheFilterMixin
from
..backends
import
AssetUserManager
...
...
@@ -57,7 +57,7 @@ class AssetUserSearchBackend(filters.BaseFilterBackend):
class
AssetUserViewSet
(
IDInCacheFilterMixin
,
BulkModelViewSet
):
pagination_class
=
LimitOffsetPagination
serializer_class
=
serializers
.
AssetUserSerializer
permission_classes
=
(
IsOrgAdminOrAppUser
,
)
permission_classes
=
[
IsOrgAdminOrAppUser
]
http_method_names
=
[
'get'
,
'post'
]
filter_fields
=
[
"id"
,
"ip"
,
"hostname"
,
"username"
,
"asset_id"
,
"node_id"
,
...
...
@@ -111,22 +111,16 @@ class AssetUserExportViewSet(AssetUserViewSet):
serializer_class
=
serializers
.
AssetUserExportSerializer
http_method_names
=
[
'get'
]
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
otp_last_verify
=
request
.
session
.
get
(
"OTP_LAST_VERIFY_TIME"
)
if
not
otp_last_verify
or
time
.
time
()
-
int
(
otp_last_verify
)
>
600
:
return
Response
({
"error"
:
"Need MFA confirm mfa auth"
},
status
=
403
)
return
super
()
.
list
(
request
,
*
args
,
**
kwargs
)
def
get_permissions
(
self
):
self
.
permission_classes
.
append
(
NeedMFAVerify
)
return
super
()
.
get_permissions
()
class
AssetUserAuthInfoApi
(
generics
.
RetrieveAPIView
):
serializer_class
=
serializers
.
AssetUserAuthInfoSerializer
permission_classes
=
(
IsOrgAdminOrAppUser
,)
permission_classes
=
[
IsOrgAdminOrAppUser
,
NeedMFAVerify
]
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
otp_last_verify
=
request
.
session
.
get
(
"OTP_LAST_VERIFY_TIME"
)
if
not
otp_last_verify
or
time
.
time
()
-
int
(
otp_last_verify
)
>
600
:
return
Response
({
"error"
:
"Need MFA confirm mfa auth"
},
status
=
403
)
instance
=
self
.
get_object
()
serializer
=
self
.
get_serializer
(
instance
)
status_code
=
status
.
HTTP_200_OK
...
...
apps/assets/templates/assets/_asset_user_list.html
View file @
327febaf
...
...
@@ -32,8 +32,9 @@ var assetUserListUrl = "{% url "api-assets:asset-user-list" %}";
var
assetUserTable
;
var
needPush
=
false
;
var
prefer
=
null
;
var
lastMFATime
=
"{{ request.session.
OTP_LAST
_VERIFY_TIME }}"
;
var
lastMFATime
=
"{{ request.session.
MFA
_VERIFY_TIME }}"
;
var
testDatetime
=
"{% trans 'Test datetime: ' %}"
;
var
mfaVerifyTTL
=
"{{ SECURITY_MFA_VERIFY_TTL }}"
;
function
initAssetUserTable
()
{
var
options
=
{
...
...
@@ -109,7 +110,7 @@ $(document).ready(function(){
authUsername
=
$
(
this
).
data
(
'user'
);
var
now
=
new
Date
();
var
nowTime
=
now
.
getTime
()
/
1000
;
if
(
!
lastMFATime
||
nowTime
-
lastMFATime
>
60
*
10
)
{
if
(
!
lastMFATime
||
nowTime
-
lastMFATime
>
mfaVerifyTTL
)
{
mfaFor
=
"viewAuth"
;
$
(
"#mfa_auth_confirm"
).
modal
(
"show"
);
}
else
{
...
...
apps/authentication/api/auth.py
View file @
327febaf
...
...
@@ -194,7 +194,7 @@ class UserOtpVerifyApi(CreateAPIView):
code
=
serializer
.
validated_data
[
"code"
]
if
request
.
user
.
check_otp
(
code
):
request
.
session
[
"
OTP_LAST
_VERIFY_TIME"
]
=
int
(
time
.
time
())
request
.
session
[
"
MFA
_VERIFY_TIME"
]
=
int
(
time
.
time
())
return
Response
({
"ok"
:
"1"
})
else
:
return
Response
({
"error"
:
"Code not valid"
},
status
=
400
)
...
...
apps/common/permissions.py
View file @
327febaf
...
...
@@ -132,3 +132,11 @@ class PermissionsMixin(UserPassesTestMixin):
if
not
permission_class
()
.
has_permission
(
self
.
request
,
self
):
return
False
return
True
class
NeedMFAVerify
(
permissions
.
BasePermission
):
def
has_permission
(
self
,
request
,
view
):
mfa_verify_time
=
request
.
session
.
get
(
'MFA_VERIFY_TIME'
,
0
)
if
time
.
time
()
-
mfa_verify_time
<
settings
.
SECURITY_MFA_VERIFY_TTL
:
return
True
return
False
apps/jumpserver/conf.py
View file @
327febaf
...
...
@@ -374,7 +374,7 @@ defaults = {
'HTTP_LISTEN_PORT'
:
8080
,
'LOGIN_LOG_KEEP_DAYS'
:
90
,
'ASSETS_PERM_CACHE_TIME'
:
3600
,
'SECURITY_MFA_VERIFY_TTL'
:
3600
,
}
...
...
apps/jumpserver/context_processor.py
View file @
327febaf
...
...
@@ -17,6 +17,7 @@ def jumpserver_processor(request):
'VERSION'
:
settings
.
VERSION
,
'COPYRIGHT'
:
'FIT2CLOUD 飞致云'
+
' © 2014-2019'
,
'SECURITY_COMMAND_EXECUTION'
:
settings
.
SECURITY_COMMAND_EXECUTION
,
'SECURITY_MFA_VERIFY_TTL'
:
settings
.
SECURITY_MFA_VERIFY_TTL
,
}
return
context
...
...
apps/jumpserver/settings.py
View file @
327febaf
...
...
@@ -565,6 +565,7 @@ SECURITY_PASSWORD_RULES = [
'SECURITY_PASSWORD_NUMBER'
,
'SECURITY_PASSWORD_SPECIAL_CHAR'
]
SECURITY_MFA_VERIFY_TTL
=
CONFIG
.
SECURITY_MFA_VERIFY_TTL
TERMINAL_PASSWORD_AUTH
=
CONFIG
.
TERMINAL_PASSWORD_AUTH
TERMINAL_PUBLIC_KEY_AUTH
=
CONFIG
.
TERMINAL_PUBLIC_KEY_AUTH
...
...
apps/locale/zh/LC_MESSAGES/django.mo
View file @
327febaf
No preview for this file type
apps/locale/zh/LC_MESSAGES/django.po
View file @
327febaf
This diff is collapsed.
Click to expand it.
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