mirror of
https://github.com/ansible/awx.git
synced 2026-03-27 05:45:02 -02:30
@@ -3,9 +3,11 @@
|
|||||||
|
|
||||||
# Python
|
# Python
|
||||||
import urllib
|
import urllib
|
||||||
|
import logging
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.utils.timezone import now as tz_now
|
from django.utils.timezone import now as tz_now
|
||||||
|
from django.utils.encoding import smart_text
|
||||||
|
|
||||||
# Django REST Framework
|
# Django REST Framework
|
||||||
from rest_framework import authentication
|
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.models import UnifiedJob, AuthToken
|
||||||
from awx.main.conf import tower_settings
|
from awx.main.conf import tower_settings
|
||||||
|
|
||||||
|
logger = logging.getLogger('awx.api.authentication')
|
||||||
|
|
||||||
class TokenAuthentication(authentication.TokenAuthentication):
|
class TokenAuthentication(authentication.TokenAuthentication):
|
||||||
'''
|
'''
|
||||||
Custom token authentication using tokens that expire and are associated
|
Custom token authentication using tokens that expire and are associated
|
||||||
@@ -116,6 +120,16 @@ class TokenGetAuthentication(TokenAuthentication):
|
|||||||
return super(TokenGetAuthentication, self).authenticate(request)
|
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):
|
class TaskAuthentication(authentication.BaseAuthentication):
|
||||||
'''
|
'''
|
||||||
Custom authentication used for views accessed by the inventory and callback
|
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.utils import emit_websocket_notification
|
||||||
from awx.main.conf import tower_settings
|
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):
|
def api_exception_handler(exc, context):
|
||||||
'''
|
'''
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ REST_FRAMEWORK = {
|
|||||||
'PAGE_SIZE': 25,
|
'PAGE_SIZE': 25,
|
||||||
'DEFAULT_AUTHENTICATION_CLASSES': (
|
'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||||
'awx.api.authentication.TokenAuthentication',
|
'awx.api.authentication.TokenAuthentication',
|
||||||
'rest_framework.authentication.BasicAuthentication',
|
'awx.api.authentication.LoggedBasicAuthentication',
|
||||||
#'rest_framework.authentication.SessionAuthentication',
|
#'rest_framework.authentication.SessionAuthentication',
|
||||||
),
|
),
|
||||||
'DEFAULT_PERMISSION_CLASSES': (
|
'DEFAULT_PERMISSION_CLASSES': (
|
||||||
|
|||||||
Reference in New Issue
Block a user