def authenticate(self, token, request=None):
     """Authenticates user based on token"""
     admin_client = utils.get_admin_client()
     try:
         auth_ref = admin_client.tokens.validate(token)
     except keystone_exceptions.NotFound as exc:
         msg = _('Invalid credentials.')
         LOG.debug(str(exc))
         raise exceptions.KeystoneAuthException(msg)
     return self._process_auth_ref(request, auth_ref, admin_client.auth_url)
示例#2
0
    def process_request(self, request):
        if request.user.is_authenticated():
            cli = get_admin_client()
            try:
                cli.tokens.validate(request.user.token.id)
                return
            except NotFound:
                auth_logout(request)

        path = request.path_info
        exempt_urls = [re.compile(expr) for expr in
                       getattr(settings, 'LOGIN_EXEMPT_URLS', list())]
        if not any(m.match(path) for m in exempt_urls):
            return HttpResponseRedirect(settings.LOGIN_URL)