Skip to content
Snippets Groups Projects
Commit 5e13c971 authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB
Browse files

move LigoAuthentication from events.api.views to events.api.backends

parent d63d4ddf
No related branches found
No related tags found
No related merge requests found
......@@ -309,6 +309,9 @@ REST_FRAMEWORK = {
'event_creation': '1/second',
'annotation' : '10/second',
},
'DEFAULT_AUTHENTICATION_CLASSES': (
'events.api.backends.LigoAuthentication',
),
}
# Location of packages installed by bower
......
from django.contrib.auth import get_user_model
from django.utils.translation import ugettext_lazy as _
from rest_framework import authentication, exceptions
UserModel = get_user_model()
# We do not want to handle authentication here because it has already
# been taken care of by Apache/Shib or Apache/mod_ssl. Moreover the
# auth middleware has already added a user to the request object. To
# play well with the django rest framework, we need to pretend like we
# authenticated the user. Remember that the request object here is a
# *wrapped* version of the Django request, so we have to dig inside it
# for the user.
class LigoAuthentication(authentication.BaseAuthentication):
def authenticate(self, request):
user = None
try:
user = request._request.user
except:
pass
if isinstance(user, UserModel):
return (user, None)
else:
raise exceptions.AuthenticationFailed(_('Bad user'))
......@@ -28,6 +28,7 @@ from ..forms import CreateEventForm
from ..permission_utils import user_has_perm, filter_events_for_user, \
is_external, check_external_file_access
from .backends import LigoAuthentication
from .throttles import EventCreationThrottle, AnnotationThrottle
from core.vfile import VersionedFile
......@@ -83,28 +84,6 @@ import StringIO
use_in(LIGOLWContentHandler)
#
# We do not want to handle authentication here because it has already
# been taken care of by Apache/Shib or Apache/mod_ssl. Moreover the
# auth middleware has already added a user to the request object. To
# play well with the django rest framework, we need to pretend like we
# authenticated the user. Remember that the request object here is a
# *wrapped* version of the Django request, so we have to dig inside it
# for the user.
#
class LigoAuthentication(authentication.BaseAuthentication):
def authenticate(self, request):
user = None
try:
user = request._request.user
except:
pass
if isinstance(user, User):
return (user, None)
else:
raise exceptions.AuthenticationFailed("Bad user")
#
# A custom permission class for the EventDetail view.
#
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment