Hi,

Thanks for the response. I think I've managed to get it working.

afrotypa wrote:
> It will also likely help if you review the repoze.who configuration
> docs to get a good picture of how it works and how to set it up.
> 
> http://static.repoze.org/whodocs/narr.html
> 
> There are 2 options for configuring repoze.who described in that doc
> -
> 
> 1. via a config file (which you have chosen)
> 
> http://static.repoze.org/whodocs/narr.html#middleware-configuration-via-config-file
> 
> 2. directly in python code (this is the option I use to setup
> repoze.who for my app)
> 
> http://static.repoze.org/whodocs/narr.html#module-repoze.who.middleware
> 
> Either method should work fine if properly setup.

repoze.who is configured via a config file. I got it to work by moving the 
abort 
call out of BaseController and into my specific controller implementations. I 
think it's because the _inspect_call method which catches HTTPExceptions and 
converts them into responses is in the WSGIController which is invoked from 
BaseController. Since I raised the exception in BaseController before 
WSGIController was invoked, I ended up with an error.

Perhaps I should move the auth check into a __before__ method of the 
BaseController.

> Since the HTTPUnauthorized exception blew past the repoze middleware
> and percolated all the way up (or down depending on your view of the
> middleware stack) to the server, I suspect you havent set up
> authorization fully. The challenger plugin (a component of the
> repoze.who authentication middleware) ought to intercept the 401 and
> provide an authentication challenge (i.e. request the user to login
> e.g. via a form or whatever method you have set up to actuate the
> challenge).

The challenge plugins in repoze.who are setup to handle 401 responses, not 401 
exceptions. That's probably why the exception percolates all the way up the 
stack.

Thanks again.

> On Jul 10, 2:43 pm, kochhar <[email protected]> wrote:
>> Hi all,
>>
>> I'm adding an authentication layer to my app and I'm trying to return an 
>> error
>> using the abort() function. It is causing an Internal Server error (500) 
>> instead
>> of returning a proper error response. I've tried with both abort(401) and
>> abort(404). debug is set to false in my app config.
>>
>> I found this irc 
>> discussion:http://pylonshq.com/irclogs/%23pylons/%23pylons.2008-12-16.log.htmlbut
>>  it
>> didn't shed much light on the issue. FWIW, I'm using pylons 0.9.6.1
>>
>> Below is the code which aborts and my middleware setup, the stack trace from
>> paster is attached
>>
>> in lib/base.py:
>> class BaseController(WSGIController):
>>
>>      def __call__(self, environ, start_response):
>>          """Invoke the Controller"""
>>          # WSGIController.__call__ dispatches to the Controller method
>>          # the request is routed to. This routing information is
>>          # available in environ['pylons.routes_dict']
>>
>>          identity = environ.get('repoze.who.identity')
>>          if not identity or not identity.strip():
>>              abort(401)
>>
>>          return WSGIController.__call__(self, environ, start_response)
>>
>> in config/middleware.py:
>>      # Configure the Pylons environment
>>      load_environment(global_conf, app_conf)
>>
>>      # The Pylons WSGI app
>>      app = PylonsApp()
>>
>>      # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
>>      auth_required = app_conf.get('auth_required', 'true')
>>      if asbool(auth_required):
>>          # create the repoze.who authentication middleware
>>          app = make_who_with_config(app, global_conf,
>>                                     app_conf['who.config_file'],
>>                                     app_conf['who.log_file'],
>>                                     app_conf.get('who.log_level', 'debug'))
>>
>>      if asbool(full_stack):
>>          # Handle Python exceptions
>>          app = ErrorHandler(app, global_conf, error_template=error_template,
>>                             **config['pylons.errorware'])
>>
>>          # Display error documents for 401, 403, 404 status codes (and
>>          # 500 when debug is disabled)
>>          app = ErrorDocuments(app, global_conf, mapper=error_mapper, 
>> **app_conf)
>>
>>      # Establish the Registry for this application
>>      app = RegistryManager(app)
>>
>>      # Static files
>>      javascripts_app = StaticJavascripts()
>>      static_app = StaticURLParser(config['pylons.paths']['static_files'])
>>      app = Cascade([static_app, javascripts_app, app])
>>      return app
>>
>> [traceback.txt4K ]Exception happened during processing of request from 
>> ('127.0.0.1', 44090)
>> Traceback (most recent call last):
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/Paste-1.7.3dev_r7858-py2.6.egg/paste/httpserver.py",
>>  line 1068, in process_request_in_thread
>>     self.finish_request(request, client_address)
>>   File "/opt/lib/python2.6/SocketServer.py", line 320, in finish_request
>>     self.RequestHandlerClass(request, client_address, self)
>>   File "/opt/lib/python2.6/SocketServer.py", line 615, in __init__
>>     self.handle()
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/Paste-1.7.3dev_r7858-py2.6.egg/paste/httpserver.py",
>>  line 442, in handle
>>     BaseHTTPRequestHandler.handle(self)
>>   File "/opt/lib/python2.6/BaseHTTPServer.py", line 329, in handle
>>     self.handle_one_request()
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/Paste-1.7.3dev_r7858-py2.6.egg/paste/httpserver.py",
>>  line 437, in handle_one_request
>>     self.wsgi_execute()
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/Paste-1.7.3dev_r7858-py2.6.egg/paste/httpserver.py",
>>  line 287, in wsgi_execute
>>     self.wsgi_start_response)
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/Paste-1.7.3dev_r7858-py2.6.egg/paste/urlmap.py",
>>  line 202, in __call__
>>     return app(environ, start_response)
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/Paste-1.7.3dev_r7858-py2.6.egg/paste/cascade.py",
>>  line 130, in __call__
>>     return self.apps[-1](environ, start_response)
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/Paste-1.7.3dev_r7858-py2.6.egg/paste/registry.py",
>>  line 375, in __call__
>>     app_iter = self.application(environ, start_response)
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/Paste-1.7.3dev_r7858-py2.6.egg/paste/recursive.py",
>>  line 84, in __call__
>>     return middleware(environ, start_response)
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/Paste-1.7.3dev_r7858-py2.6.egg/paste/recursive.py",
>>  line 47, in __call__
>>     return self.app(environ, start_response)
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/Paste-1.7.3dev_r7858-py2.6.egg/paste/errordocument.py",
>>  line 84, in __call__
>>     return self.app(environ, keep_status_start_response)
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/Paste-1.7.3dev_r7858-py2.6.egg/paste/recursive.py",
>>  line 80, in __call__
>>     return self.application(environ, start_response)
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/Paste-1.7.3dev_r7858-py2.6.egg/paste/errordocument.py",
>>  line 185, in __call__
>>     app_iter = self.application(environ, change_response)
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/Paste-1.7.3dev_r7858-py2.6.egg/paste/exceptions/errormiddleware.py",
>>  line 138, in __call__
>>     return self.application(environ, start_response)
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/repoze.who-1.0.13-py2.6.egg/repoze/who/middleware.py",
>>  line 107, in __call__
>>     app_iter = app(environ, wrapper.wrap_start_response)
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/Pylons-0.9.6.1-py2.6.egg/pylons/wsgiapp.py",
>>  line 315, in __call__
>>     return self.app(environ, start_response)
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/Beaker-0.7.5-py2.6.egg/beaker/cache.py",
>>  line 180, in __call__
>>     return self.app(environ, start_response)
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/Beaker-0.7.5-py2.6.egg/beaker/session.py",
>>  line 405, in __call__
>>     response = self.wrap_app(environ, session_start_response)
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/Routes-1.10.1-py2.6.egg/routes/middleware.py",
>>  line 118, in __call__
>>     response = self.app(environ, start_response)
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/Pylons-0.9.6.1-py2.6.egg/pylons/wsgiapp.py",
>>  line 95, in __call__
>>     response = self.dispatch(controller, environ, start_response)
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/Pylons-0.9.6.1-py2.6.egg/pylons/wsgiapp.py",
>>  line 237, in dispatch
>>     return controller(environ, start_response)
>>   File "/home/kochhar/workspace/argus-trunk/argus/lib/base.py", line 25, in 
>> __call__
>>     abort(401)
>>   File 
>> "/home/kochhar/workspace/argus-trunk/_install/lib/python2.6/site-packages/Pylons-0.9.6.1-py2.6.egg/pylons/controllers/util.py",
>>  line 63, in abort
>>     raise exc
>> HTTPUnauthorized: 401 Unauthorized
>> This server could not verify that you are authorized to
>> access the document you requested.  Either you supplied the
>> wrong credentials (e.g., bad password), or your browser
>> does not understand how to supply the credentials required.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to