Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a dummy project to reproduce the problem:</p> <ol> <li><p>setup a virtualenv environment and install Pyramid in it.</p></li> <li><p>Install a starter project: <code>pcreate -s starter IssueApp</code></p></li> <li><p>Delete all the unnecessary files so that you have this simple tree:</p></li> </ol> <p>Tree</p> <pre><code>. ├── CHANGES.txt ├── development.ini ├── issueapp │   ├── __init__.py │   └── static │   └── pyramid.png ├── README.txt └── setup.py </code></pre> <p>Note that we wil write the entire app in the <code>__init__.py</code> file -- so everything else is removed.</p> <p>Now install the project: <code>(env) $ python setup.py develop</code> This will install your project into virtual environment.</p> <p>The <code>development.ini</code> file:</p> <pre><code>[app:main] use = egg:IssueApp#main pyramid.reload_all = true pyramid.reload_templates = true pyramid.debug_all = true pyramid.debug_notfound = true pyramid.debug_routematch = true pyramid.prevent_http_cache = true pyramid.default_locale_name = en [server:main] use = egg:waitress#main host = 0.0.0.0 port = 7777 [loggers] keys = root, issueapp [handlers] keys = console [formatters] keys = generic [logger_root] level = INFO handlers = console [logger_issueapp] level = INFO handlers = qualname = issueapp [handler_console] class = StreamHandler args = (sys.stderr,) level = NOTSET formatter = generic [formatter_generic] format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s </code></pre> <p>The <code>__init__.py</code> file:</p> <pre><code>from pyramid.config import Configurator from pyramid.view import view_config from pyramid.response import Response from pyramid.authentication import CallbackAuthenticationPolicy from pyramid.authorization import ACLAuthorizationPolicy from pyramid.security import ( Allow, Deny, Everyone, Authenticated, ) def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ config = Configurator(settings=settings) #config.add_static_view('static', 'static', cache_max_age=3600) config.add_static_view(name='static', path='issueapp:static') config.add_route('home', '/') config.set_root_factory(RootFactory) config.set_authentication_policy(DummyAuthPolicy()) config.set_authorization_policy(ACLAuthorizationPolicy()) config.scan() return config.make_wsgi_app() @view_config(route_name='home') def home_view(request): src = request.static_url('issueapp:static/pyramid.png') return Response('&lt;img src='+ src + '&gt;') class RootFactory: __acl__ = [ (Allow, Authenticated, 'edit'), (Deny, Authenticated, 'login'), (Allow, Everyone, 'login'), ] def __init__(self, request): self.request = request class DummyAuthPolicy(CallbackAuthenticationPolicy): def __init__(self, callback=None, debug=False): self.callback = callback self.debug = debug def remember(self, request, principal, **kw): return [] def forget(self, request): return [] def unauthenticated_userid(self, request): # this will print the request url # so we can know which request is causing auth code to be called print('[auth]: ' + request.url) # this means the user is authenticated return "user" </code></pre> <p>Now run the app</p> <pre><code>pserve development.ini --reload Starting subprocess with file monitor Starting server in PID 2303. serving on http://0.0.0.0:7777 </code></pre> <p>Finally, clear all history from your browser (this is important or the issue might not reveal itself) and access the page. this gets printed on the console:</p> <pre><code>[auth]: http://192.168.56.102:7777/static/pyramid.png </code></pre> <p>Which shows that auth code is getting called for static requests.</p> <p>Now, when I set the log level to <code>DEBUG</code>, this is the output of console on accessing the page:</p> <pre> pserve development.ini --reload Starting subprocess with file monitor Starting server in PID 2339. serving on http://0.0.0.0:7777 2013-03-27 03:40:55,539 DEBUG [issueapp][Dummy-2] route matched for url http://192.168.56.102:7777/; route_name: 'home', path_info: '/', pattern: '/', matchdict: {}, predicates: '' 2013-03-27 03:40:55,540 DEBUG [issueapp][Dummy-2] debug_authorization of url http://192.168.56.102:7777/ (view name '' against context ): Allowed (no permission registered) 2013-03-27 03:40:55,685 DEBUG [issueapp][Dummy-3] route matched for url http://192.168.56.102:7777/static/pyramid.png; route_name: '__static/', path_info: '/static/pyramid.png', pattern: 'static/*subpath', matchdict: {'subpath': ('pyramid.png',)}, predicates: '' [auth]: http://192.168.56.102:7777/static/pyramid.png 2013-03-27 03:40:55,687 DEBUG [issueapp][Dummy-3] debug_authorization of url http://192.168.56.102:7777/static/pyramid.png (view name '' against context ): ACLDenied permission '__no_permission_required__' via ACE '' in ACL [('Allow', 'system.Authenticated', 'edit'), ('Deny', 'system.Authenticated', 'login'), ('Allow', 'system.Everyone', 'login')] on context for principals ['system.Everyone', 'system.Authenticated', 'user'] </pre> <hr> <p>Note that the <code>[auth]: ...</code> message is getting printed ONLY ONCE -- for the static asset request, and NOT for the home page request. This is strange because it means that the auth policy is consulted for static assets but not for normal requests. (Unless of course there is a permission involved, which in my view isn't).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload