Re: Problem: Embedding 401 page (not author ized) for "edit" with standard_error_message

Heiko Besemann <[email protected]> Mon, 20 Jul 2009 23:08:45 +0200
Newsgroups gmane.comp.web.zope.silva.devel
Message-ID <1488ecf8fa81ce21fb48ccc46fbbe892@localhost>
Well, the solution was much simpler than I thought but it took me a few
hours to figure out while pdb'ing Zope and Silva classes.

The reason why I get the Zope error is that when an unauthenticated
exception is raised calling "edit" on some Silva object that the context is
like the logfile says "Products.Silva.SilvaObject.Zope3ViewAttribute". In
that context I do not have any "mybeautifulskin" Silva layout object which
is needed to render my skin. On the other hand calling ZMI (manage) will
return a context object which is within my sites Silva cms root (so
"mybeautifulskin" skin object can be called and the 401 page gets rendered
ok).

Now to get a "nice" 401 error page rendered when you use "edit" is simply
to overwrite the "context" attribute with the absolute path to your cms
root in standard_error_message template.

So in my case I put "context here/cms/watt;" into the tal:define block,
like:

<tal:block define="error_type options/error_type | nothing;
error_value options/error_value | nothing;
message_type options/message_type | nothing;
message options/message | nothing;
allow_authentication_requests
here/service_members/allow_authentication_requests | nothing;
context here/cms/watt;
mangle python:modules['Products'].Silva.mangle;"> 

Standard_error_message is located in my publications root, i.e. the virtual
hosts root.

This works for me even if its ugly to have an absolute path within a
template.

Cheers,
Heiko 


On Mon, 20 Jul 2009 14:20:35 +0200, Heiko Besemann <[email protected]>
wrote:
> Hi Kit,
> 
> no its a default Silva / Zope installation with no access protected
pages.
> I simply created a Silva root cms object in my Zope's root folder and
> changed the standard_error_message template for the 401 stuff.
> 
> Well, I will try to pdb today evening and figure out whats wrong with it
> and let you know if I was successfull.
> 
> Cheers,
> Heiko
> 
> 
> On Mon, 20 Jul 2009 07:34:55 +0200, Kit BLAKE <[email protected]>
wrote:
>> Hieko,
>> Tried to reproduce your problem this weekend, and I get the same  
>> messages but not the error with traceback. However I also don't see  
>> the 'nice' 401 page.
>> 
>> Have you set an access restriction on the entire site? When everything  
>> from the root is access protected we've seen problems with 401 errors,  
>> because seemingly innocuous things such as logo and navigation images  
>> are also protected.
>> 
>> Kit
>> 
>> 
>> On 17 Jul 2009, at 17:24, Heiko Besemann wrote:
>> 
>>>
>>> Hi there,
>>>
>>> sorry for bugging the dev-list with my problems. However I run into a
>>> strange thing tonight I can not explain and need someones professional
>>> advice how to get this fixed.
>>>
>>> Well, Silva uses the "standard_error_message" for rendering custom  
>>> errors
>>> like 404 (not found), 500 (system problems) and 401 (not  
>>> authorized). When
>>> one of these errors happends my wish is that Silva will not render the
>>> standard_error_message template but uses my custom skins content  
>>> area to
>>> display the message.
>>>
>>> So for 404, 401 and 500 I did the following thing:
>>>
>>> <tal:block tal:condition="python: error_type == 'NotFound'">
>>> <html metal:use-macro="context/@@mywonderfullcustomskin/main">
>>> <head>
>>> <title metal:fill-slot="title">
>>> 404 – Resource not found
>>> </title>
>>> </head>
>>> <body>
>>> <div metal:fill-slot="body">
>>> <h2>404 – Resource not found</h2>
>>> <p>
>>> Huhu, where is my page gone?
>>> </p>
>>> </div>
>>> </body>
>>> </html>
>>> </tal:block>
>>> </tal:block>
>>>
>>> Now this works if I type something like
>>> "http://www.wattwanderinfo.de/where_is_my_page". The error message  
>>> will get
>>> displayed withing my custom skin.
>>>
>>> Next thing I wanted was to render are "401" errors. The above code  
>>> differs
>>> only for the condition check but everthing else is the same. I use my
>>> context/@@mywonderfullcustomskin macro aso.
>>>
>>> If I try to authenticate as "manager" to get into ZMI and cancel the
>>> authentication request, yes I get that permission denied stuff shown
>>> correctly on my page. However (and this is the thing I dont  
>>> understand) if
>>> I try to authenticate as "edit" and cancel authentication I get some  
>>> error
>>> like the following on my webpage:
>>>
>>> -- snipp --
>>> You are not authorized to access this resource.
>>> Username and password are not correct.
>>>
>>> (Also, the following error occurred while attempting to render the  
>>> standard
>>> error message, please see the event log for full details:
>>> (<Products.Silva.SilvaObject.Zope3ViewAttribute object at 0x01CF2450>,
>>> 'mywonderfullcustomskin'))
>>> -- snapp --
>>>
>>> Zope event logfile shows me:
>>>
>>> -- snipp --
>>> 2009-07-17T17:17:52 ERROR root Exception while rendering an error  
>>> message
>>> Traceback (most recent call last):
>>> File "C:\Zope\2.11.1\Zope\lib\python\OFS\SimpleItem.py", line 227, in
>>> raise_standardErrorMessage
>>> v = s(**kwargs)
>>> File "C:\Zope\2.11.1\Zope\lib\python\Shared\DC\Scripts\Bindings.py",  
>>> line
>>> 313, in __call__
>>> return self._bindAndExec(args, kw, None)
>>> File "C:\Zope\2.11.1\Zope\lib\python\Shared\DC\Scripts\Bindings.py",  
>>> line
>>> 350, in _bindAndExec
>>> return self._exec(bound_data, args, kw)
>>> File
>>> "C:\Zope\2.11.1\Zope\lib\python\Products\PageTemplates 
>>> \ZopePageTemplate.py",
>>> line 330, in _exec
>>> result = self.pt_render(extra_context=bound_names)
>>> File
>>> "C:\Zope\2.11.1\Zope\lib\python\Products\PageTemplates 
>>> \ZopePageTemplate.py",
>>> line 427, in pt_render
>>> result = PageTemplate.pt_render(self, source, extra_context)
>>> File
>>> "C:\Zope\2.11.1\Zope\lib\python\Products\PageTemplates 
>>> \PageTemplate.py",
>>> line 96, in pt_render
>>> showtal=showtal)
>>> File "C:\Zope\2.11.1\Zope\lib\python\zope\pagetemplate 
>>> \pagetemplate.py",
>>> line 115, in pt_render
>>> strictinsert=0, sourceAnnotations=sourceAnnotations)()
>>> File "C:\Zope\2.11.1\Zope\lib\python\zope\tal\talinterpreter.py",  
>>> line 271,
>>> in __call__
>>> self.interpret(self.program)
>>> File "C:\Zope\2.11.1\Zope\lib\python\zope\tal\talinterpreter.py",  
>>> line 346,
>>> in interpret
>>> handlers[opcode](self, args)
>>> File "C:\Zope\2.11.1\Zope\lib\python\zope\tal\talinterpreter.py",  
>>> line 536,
>>> in do_optTag_tal
>>> self.do_optTag(stuff)
>>> File "C:\Zope\2.11.1\Zope\lib\python\zope\tal\talinterpreter.py",  
>>> line 521,
>>> in do_optTag
>>> return self.no_tag(start, program)
>>> File "C:\Zope\2.11.1\Zope\lib\python\zope\tal\talinterpreter.py",  
>>> line 516,
>>> in no_tag
>>> self.interpret(program)
>>> File "C:\Zope\2.11.1\Zope\lib\python\zope\tal\talinterpreter.py",  
>>> line 346,
>>> in interpret
>>> handlers[opcode](self, args)
>>> File "C:\Zope\2.11.1\Zope\lib\python\zope\tal\talinterpreter.py",  
>>> line 855,
>>> in do_condition
>>> self.interpret(block)
>>> File "C:\Zope\2.11.1\Zope\lib\python\zope\tal\talinterpreter.py",  
>>> line 346,
>>> in interpret
>>> handlers[opcode](self, args)
>>> File "C:\Zope\2.11.1\Zope\lib\python\zope\tal\talinterpreter.py",  
>>> line 536,
>>> in do_optTag_tal
>>> self.do_optTag(stuff)
>>> File "C:\Zope\2.11.1\Zope\lib\python\zope\tal\talinterpreter.py",  
>>> line 521,
>>> in do_optTag
>>> return self.no_tag(start, program)
>>> File "C:\Zope\2.11.1\Zope\lib\python\zope\tal\talinterpreter.py",  
>>> line 516,
>>> in no_tag
>>> self.interpret(program)
>>> File "C:\Zope\2.11.1\Zope\lib\python\zope\tal\talinterpreter.py",  
>>> line 346,
>>> in interpret
>>> handlers[opcode](self, args)
>>> File "C:\Zope\2.11.1\Zope\lib\python\zope\tal\talinterpreter.py",  
>>> line 870,
>>> in do_useMacro
>>> macro = self.engine.evaluateMacro(macroExpr)
>>> File "C:\Zope\2.11.1\Zope\lib\python\zope\tales\tales.py", line 696,  
>>> in
>>> evaluate
>>> return expression(self)
>>> File "C:\Zope\2.11.1\Zope\lib\python\zope\tales\expressions.py",  
>>> line 217,
>>> in __call__
>>> return self._eval(econtext)
>>> File
>>> "C:\Zope\2.11.1\Zope\lib\python\Products\PageTemplates 
>>> \Expressions.py",
>>> line 131, in _eval
>>> ob = self._subexprs[-1](econtext)
>>> File "C:\Zope\2.11.1\Zope\lib\python\zope\tales\expressions.py",  
>>> line 124,
>>> in _eval
>>> ob = self._traverser(ob, element, econtext)
>>> File
>>> "C:\Zope\2.11.1\Zope\lib\python\Products\PageTemplates 
>>> \Expressions.py",
>>> line 83, in boboAwareZopeTraverse
>>> request=request)
>>> File "C:\Zope\2.11.1\Zope\lib\python\zope\traversing\adapters.py",  
>>> line
>>> 154, in traversePathElement
>>> return namespaceLookup(ns, nm, obj, request)
>>> File "C:\Zope\2.11.1\Zope\lib\python\zope\traversing\namespace.py",  
>>> line
>>> 112, in namespaceLookup
>>> return traverser.traverse(name, ())
>>> File "C:\Zope\2.11.1\Zope\lib\python\zope\traversing\namespace.py",  
>>> line
>>> 345, in traverse
>>> raise TraversalError(self.context, name)
>>> TraversalError: (<Products.Silva.SilvaObject.Zope3ViewAttribute  
>>> object at
>>> 0x01CF2450>, 'mywonderfullcustomskin')
>>>
>>> -- snapp --
>>>
>>> So why is everything working fine for 404 and 401 (with manage
>>> authentication), but not for 401 with "edit" authentication?
>>>
>>> Cheers,
>>> Heiko
>>>
>>>
>>>
>>> _______________________________________________
>>> silva-dev mailing list
>>> [email protected]
>>> https://lists.infrae.com/mailman/listinfo/silva-dev
> 
> _______________________________________________
> silva-dev mailing list
> [email protected]
> https://lists.infrae.com/mailman/listinfo/silva-dev

_______________________________________________
silva-dev mailing list
[email protected]
https://lists.infrae.com/mailman/listinfo/silva-dev