Upon unauthorized access, Plone by default provides a redirect to login form. I need to prevent this for certain subpaths (ie. not globally), and instead return 403 Forbidden, with a custom (short) HTML page, after the (otherwise) normal Plone authentication & authorization has taken place.
I looked into ITraversable but using that takes place too early in the request processing chain - ie. before auth etc.
One possible yet unexplored method is having a custom view injected to URL path that performs auth checks on the object that maps to the remaining subpath. So there could be a request with URL something like http://myplone/somepath/customview/withcustom403
, where:
- The
customview
view implementsIPublishTraverse
, and itspublishTraverse()
returns itself - The same view then next validates, in its
__call__
method, the access towithcustom403
object, ie. by callinggetSecurityManager().validate()
- If validation fails, the view sets response to 403 and returns the custom HTML
Would this work? Or is there some event triggered after auth takes place, but before Plone calls response.Unauthorized()
(triggering redirect), that would provide a cleaner solution?
This is for current Plone 4.3.4.