mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-08 10:49:08 +00:00
perf: Check the validity of the connection token
This commit is contained in:
@@ -472,6 +472,7 @@ class SuperConnectionTokenViewSet(ConnectionTokenViewSet):
|
||||
rbac_perms = {
|
||||
'create': 'authentication.add_superconnectiontoken',
|
||||
'renewal': 'authentication.add_superconnectiontoken',
|
||||
'check': 'authentication.view_superconnectiontoken',
|
||||
'get_secret_detail': 'authentication.view_superconnectiontokensecret',
|
||||
'get_applet_info': 'authentication.view_superconnectiontoken',
|
||||
'release_applet_account': 'authentication.view_superconnectiontoken',
|
||||
@@ -484,6 +485,28 @@ class SuperConnectionTokenViewSet(ConnectionTokenViewSet):
|
||||
def get_user(self, serializer):
|
||||
return serializer.validated_data.get('user')
|
||||
|
||||
@action(methods=['GET'], detail=True, url_path='check')
|
||||
def check(self, request, *args, **kwargs):
|
||||
instance = self.get_object()
|
||||
data = {
|
||||
"detail": "OK",
|
||||
"code": "perm_ok",
|
||||
"expired": instance.is_expired
|
||||
}
|
||||
try:
|
||||
self._validate_perm(
|
||||
instance.user,
|
||||
instance.asset,
|
||||
instance.account,
|
||||
instance.protocol
|
||||
)
|
||||
except JMSException as e:
|
||||
data['code'] = e.detail.code
|
||||
data['detail'] = str(e.detail)
|
||||
return Response(data=data, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
return Response(data=data, status=status.HTTP_200_OK)
|
||||
|
||||
@action(methods=['PATCH'], detail=False)
|
||||
def renewal(self, request, *args, **kwargs):
|
||||
from common.utils.timezone import as_current_tz
|
||||
|
Reference in New Issue
Block a user