Beispiel #1
0
 def process_request(self, request):
     try:
         # Try and construct a User instance from data stored in the cache
         session_user_id = SafeSessionMiddleware.get_user_id_from_session(request)
         request.user = User.get_cached(session_user_id)  # pylint: disable=no-member
         if request.user.id != session_user_id:
             log.error(
                 "CacheBackedAuthenticationMiddleware cached user '%s' does not match requested user '%s'.",
                 request.user.id,
                 session_user_id,
             )
             # Raise an exception to fall through to the except clause below.
             raise Exception
     except:
         # Fallback to constructing the User from the database.
         super(CacheBackedAuthenticationMiddleware, self).process_request(request)
 def process_request(self, request):
     try:
         # Try and construct a User instance from data stored in the cache
         session_user_id = SafeSessionMiddleware.get_user_id_from_session(request)
         request.user = User.get_cached(session_user_id)
         if request.user.id != session_user_id:
             log.error(
                 u"CacheBackedAuthenticationMiddleware cached user '%s' does not match requested user '%s'.",
                 request.user.id,
                 session_user_id,
             )
             # Raise an exception to fall through to the except clause below.
             raise Exception
         self._verify_session_auth(request)
     except:  # pylint: disable=bare-except
         # Fallback to constructing the User from the database.
         super(CacheBackedAuthenticationMiddleware, self).process_request(request)
Beispiel #3
0
    def process_request(self, request):
        try:
            # Try and construct a User instance from data stored in the cache
            session_user_id = SafeSessionMiddleware.get_user_id_from_session(
                request)
            cached_user = User.get_cached(session_user_id)
            if cached_user is None:
                request.user = User.objects.get(id=int(session_user_id))
                log.error(u"pp::: cached_user line 113 '%s'.", cached_user)
            else:
                request.user = cached_user
                log.error(u"pp::: get_user_id_from_session line 116 '%s'.",
                          session_user_id)
            if request.user.id != session_user_id:
                log.error(
                    u"pp:: CacheBackedAuthenticationMiddleware cached user '%s' does not match requested user '%s'.",
                    request.user.id,
                    session_user_id,
                )
                # Raise an exception to fall through to the except clause below.
                raise Exception
            #self._verify_session_auth(request)
            if not CacheBackedAuthenticationMiddleware._is_user_authenticated(
                    request):
                user = auth.authenticate(request.user)
                if user is None:
                    return HttpResponseForbidden()

                request.user = user
                auth.login(request, user)
        except Exception as e:  # pylint: disable=bare-except
            # Fallback to constructing the User from the database.
            log.error(u"pp::: cache error  {0!r}: {1}".format(  # pylint: disable=logging-format-interpolation
                six.text_type(self),
                text_type(e),
            ))
            super(CacheBackedAuthenticationMiddleware,
                  self).process_request(request)