1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/053943b668af/ Changeset: 053943b668af User: jmchilton Date: 2014-07-23 16:16:08 Summary: More standardized (if still terse) exception handling in AuthenticationController. Affected #: 3 files diff -r f24d7ac8ee9549fc19435aa1448854e9024982ff -r 053943b668af334c480b464fe7351b50284b7099 lib/galaxy/exceptions/__init__.py --- a/lib/galaxy/exceptions/__init__.py +++ b/lib/galaxy/exceptions/__init__.py @@ -86,6 +86,11 @@ err_code = error_codes.USER_REQUEST_INVALID_PARAMETER +class AuthenticationFailed( MessageException ): + status_code = 401 + err_code = error_codes.USER_AUTHENTICATION_FAILED + + class AuthenticationRequired( MessageException ): status_code = 403 #TODO: as 401 and send WWW-Authenticate: ??? diff -r f24d7ac8ee9549fc19435aa1448854e9024982ff -r 053943b668af334c480b464fe7351b50284b7099 lib/galaxy/exceptions/error_codes.json --- a/lib/galaxy/exceptions/error_codes.json +++ b/lib/galaxy/exceptions/error_codes.json @@ -60,6 +60,11 @@ "message": "Supplied incorrect or incompatible tool meta parameters." }, { + "name": "USER_AUTHENTICATION_FAILED", + "code": 401001, + "message": "Authentication failed, invalid credentials supplied." + }, + { "name": "USER_NO_API_KEY", "code": 403001, "message": "API authentication required for this request" diff -r f24d7ac8ee9549fc19435aa1448854e9024982ff -r 053943b668af334c480b464fe7351b50284b7099 lib/galaxy/webapps/galaxy/api/authenticate.py --- a/lib/galaxy/webapps/galaxy/api/authenticate.py +++ b/lib/galaxy/webapps/galaxy/api/authenticate.py @@ -12,11 +12,10 @@ """ from base64 import b64decode -from paste.httpexceptions import HTTPBadRequest from urllib import unquote -from galaxy import web -from galaxy.exceptions import ObjectNotFound +from galaxy.web import _future_expose_api_anonymous as expose_api_anonymous +from galaxy import exceptions from galaxy.web.base.controller import BaseAPIController, CreatesApiKeysMixin import logging @@ -25,7 +24,7 @@ class AuthenticationController( BaseAPIController, CreatesApiKeysMixin ): - @web.expose_api_anonymous + @expose_api_anonymous def get_api_key( self, trans, **kwd ): """ def get_api_key( self, trans, **kwd ) @@ -43,7 +42,7 @@ if ( len( user ) is not 1 ): # DB is inconsistent and we have more users with same email - raise ObjectNotFound + raise exceptions.ObjectNotFound() else: user = user[0] is_valid_user = user.check_password( password ) @@ -54,8 +53,7 @@ key = self.create_api_key( trans, user ) return dict( api_key=key ) else: - trans.response.status = 500 - return "invalid password" + raise exceptions.AuthenticationFailed() def _decode_baseauth( self, encoded_str ): """ @@ -81,7 +79,7 @@ try: email, password = b64decode( split[ 0 ] ).split( ':' ) except: - raise HTTPBadRequest + raise exceptions.ActionInputError() # If there are only two elements, check the first and ensure it says # 'basic' so that we know we're about to decode the right thing. If not, @@ -91,13 +89,13 @@ try: email, password = b64decode( split[ 1 ] ).split( ':' ) except: - raise HTTPBadRequest + raise exceptions.ActionInputError() else: - raise HTTPBadRequest + raise exceptions.ActionInputError() # If there are more than 2 elements, something crazy must be happening. # Bail. else: - raise HTTPBadRequest + raise exceptions.ActionInputError() return unquote( email ), unquote( password ) Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.