mirror of
https://github.com/ansible/awx.git
synced 2026-01-15 03:40:42 -03:30
parent
6182dad0d4
commit
f3cae7e1f0
@ -3,9 +3,11 @@
|
||||
|
||||
# Python
|
||||
import urllib
|
||||
import logging
|
||||
|
||||
# Django
|
||||
from django.utils.timezone import now as tz_now
|
||||
from django.utils.encoding import smart_text
|
||||
|
||||
# Django REST Framework
|
||||
from rest_framework import authentication
|
||||
@ -16,6 +18,8 @@ from rest_framework import HTTP_HEADER_ENCODING
|
||||
from awx.main.models import UnifiedJob, AuthToken
|
||||
from awx.main.conf import tower_settings
|
||||
|
||||
logger = logging.getLogger('awx.api.authentication')
|
||||
|
||||
class TokenAuthentication(authentication.TokenAuthentication):
|
||||
'''
|
||||
Custom token authentication using tokens that expire and are associated
|
||||
@ -93,7 +97,7 @@ class TokenAuthentication(authentication.TokenAuthentication):
|
||||
if not token.in_valid_tokens(now=now):
|
||||
token.invalidate(reason='limit_reached')
|
||||
raise exceptions.AuthenticationFailed(AuthToken.reason_long('limit_reached'))
|
||||
|
||||
|
||||
# If the user is inactive, then return an error.
|
||||
if not token.user.is_active:
|
||||
raise exceptions.AuthenticationFailed('User inactive or deleted')
|
||||
@ -116,6 +120,16 @@ class TokenGetAuthentication(TokenAuthentication):
|
||||
return super(TokenGetAuthentication, self).authenticate(request)
|
||||
|
||||
|
||||
class LoggedBasicAuthentication(authentication.BasicAuthentication):
|
||||
|
||||
def authenticate(self, request):
|
||||
ret = super(LoggedBasicAuthentication, self).authenticate(request)
|
||||
if ret:
|
||||
username = ret[0].username if ret[0] else '<none>'
|
||||
logger.debug(smart_text(u"User {} performed a {} to {} through the API".format(username, request.method, request.path)))
|
||||
return ret
|
||||
|
||||
|
||||
class TaskAuthentication(authentication.BaseAuthentication):
|
||||
'''
|
||||
Custom authentication used for views accessed by the inventory and callback
|
||||
|
||||
@ -72,7 +72,7 @@ from awx.api.metadata import RoleMetadata
|
||||
from awx.main.utils import emit_websocket_notification
|
||||
from awx.main.conf import tower_settings
|
||||
|
||||
logger = logging.getLogger('awx.api.generics')
|
||||
logger = logging.getLogger('awx.api.views')
|
||||
|
||||
def api_exception_handler(exc, context):
|
||||
'''
|
||||
|
||||
@ -202,7 +202,7 @@ REST_FRAMEWORK = {
|
||||
'PAGE_SIZE': 25,
|
||||
'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||
'awx.api.authentication.TokenAuthentication',
|
||||
'rest_framework.authentication.BasicAuthentication',
|
||||
'awx.api.authentication.LoggedBasicAuthentication',
|
||||
#'rest_framework.authentication.SessionAuthentication',
|
||||
),
|
||||
'DEFAULT_PERMISSION_CLASSES': (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user