diff --git a/openerp/addons/base/ir/ir_http.py b/openerp/addons/base/ir/ir_http.py index bd211d14cb8..122b9d9bb26 100644 --- a/openerp/addons/base/ir/ir_http.py +++ b/openerp/addons/base/ir/ir_http.py @@ -71,17 +71,23 @@ class ir_http(osv.AbstractModel): request.uid = request.session.uid def _authenticate(self, auth_method='user'): - if request.session.uid: - try: - request.session.check_security() - # what if error in security.check() - # -> res_users.check() - # -> res_users.check_credentials() - except (openerp.exceptions.AccessDenied, openerp.http.SessionExpiredException): - # All other exceptions mean undetermined status (e.g. connection pool full), - # let them bubble up - request.session.logout() - getattr(self, "_auth_method_%s" % auth_method)() + try: + if request.session.uid: + try: + request.session.check_security() + # what if error in security.check() + # -> res_users.check() + # -> res_users.check_credentials() + except (openerp.exceptions.AccessDenied, openerp.http.SessionExpiredException): + # All other exceptions mean undetermined status (e.g. connection pool full), + # let them bubble up + request.session.logout() + getattr(self, "_auth_method_%s" % auth_method)() + except (openerp.exceptions.AccessDenied, openerp.http.SessionExpiredException): + raise + except Exception: + _logger.exception("Exception during request Authentication.") + raise openerp.exceptions.AccessDenied() return auth_method def _handle_exception(self, exception): diff --git a/openerp/http.py b/openerp/http.py index ec979fd1793..d32d00326f7 100644 --- a/openerp/http.py +++ b/openerp/http.py @@ -208,8 +208,6 @@ class WebRequest(object): to abitrary responses. Anything returned (except None) will be used as response.""" self._failed = exception # prevent tx commit - if isinstance(exception, werkzeug.exceptions.HTTPException): - return exception raise def _call_function(self, *args, **kwargs): @@ -456,6 +454,15 @@ class HttpRequest(WebRequest): params.pop('session_id', None) self.params = params + def _handle_exception(self, exception): + """Called within an except block to allow converting exceptions + to abitrary responses. Anything returned (except None) will + be used as response.""" + try: + return super(HttpRequest, self)._handle_exception(exception) + except werkzeug.exceptions.HTTPException, e: + return e + def dispatch(self): # TODO: refactor this correctly. This is a quick fix for pos demo. if request.httprequest.method == 'OPTIONS' and request.func and request.func.routing.get('cors'):