Guest User

Untitled

a guest
Jul 18th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. def _check_security(self):
  2. predicate = getattr(self, 'allow_only', None)
  3. if predicate is None:
  4. return True
  5. try:
  6. predicate.check_authorization(pylons.request.environ)
  7. except WhatNotAuthorizedError, e:
  8. reason = unicode(e)
  9. if hasattr(self, '_failed_authorization'):
  10. # Should shortcircut the rest, but if not we will still
  11. # deny authorization
  12. self._failed_authorization(reason)
  13. if not_anonymous().is_met(request.environ):
  14. # The user is authenticated but not allowed.
  15. code = 403
  16. status = 'error'
  17. else:
  18. # The user has not been not authenticated.
  19. code = 401
  20. status = 'warning'
  21. pylons.response.status = code
  22. flash(reason, status=status)
  23. abort(code, comment=reason)
  24. except NotAuthorizedError, e:
  25. reason = getattr(e, 'msg', 'You are not Authorized to access this Resource')
  26. code = getattr(e, 'code', 401)
  27. status = getattr(e, 'status', 'error')
  28. pylons.response.status = code
  29. flash(reason, status=status)
  30. abort(code, comment=reason)
Add Comment
Please, Sign In to add comment