mirror of
https://github.com/ansible/awx.git
synced 2026-01-16 04:10:44 -03:30
Added sso login logging
Part of #1087 This is untested as we need to have a public facing machine to do SSO stuff against.
This commit is contained in:
parent
f3cae7e1f0
commit
24a841a0bf
@ -3,6 +3,7 @@
|
||||
|
||||
# Python
|
||||
import urllib
|
||||
import logging
|
||||
|
||||
# Django
|
||||
from django.core.urlresolvers import reverse
|
||||
@ -10,6 +11,7 @@ from django.http import HttpResponse
|
||||
from django.utils.timezone import now, utc
|
||||
from django.views.generic import View
|
||||
from django.views.generic.base import RedirectView
|
||||
from django.utils.encoding import smart_text
|
||||
|
||||
# Django REST Framework
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
@ -18,12 +20,14 @@ from rest_framework.renderers import JSONRenderer
|
||||
from awx.main.models import AuthToken
|
||||
from awx.api.serializers import UserSerializer
|
||||
|
||||
logger = logging.getLogger('awx.sso.views')
|
||||
|
||||
class BaseRedirectView(RedirectView):
|
||||
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
last_path = self.request.COOKIES.get('lastPath', '')
|
||||
last_path = urllib.quote(urllib.unquote(last_path).strip('"'))
|
||||
logger.warning(smart_text(u"Redirecting invalid SSO login attempt".format(last_path)))
|
||||
url = reverse('ui:index')
|
||||
if last_path:
|
||||
return '%s#%s' % (url, last_path)
|
||||
@ -45,9 +49,11 @@ class CompleteView(BaseRedirectView):
|
||||
request_hash=request_hash,
|
||||
expires__gt=now())[0]
|
||||
token.refresh()
|
||||
logger.info(smart_text(u"User {} logged in".format(self.request.user.username)))
|
||||
except IndexError:
|
||||
token = AuthToken.objects.create(user=request.user,
|
||||
request_hash=request_hash)
|
||||
logger.info(smart_text(u"User {} logged in".format(self.request.user.username)))
|
||||
request.session['auth_token_key'] = token.key
|
||||
token_key = urllib.quote('"%s"' % token.key)
|
||||
response.set_cookie('token', token_key)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user