paulb@187 | 1 | #!/usr/bin/env python |
paulb@187 | 2 | |
paulb@187 | 3 | """ |
paulb@187 | 4 | Zope adapter. |
paulb@187 | 5 | """ |
paulb@187 | 6 | |
paulb@187 | 7 | import WebStack.Zope |
paulb@187 | 8 | |
paulb@187 | 9 | from Globals import Persistent |
paulb@187 | 10 | from OFS.SimpleItem import Item |
paulb@187 | 11 | from AccessControl import ClassSecurityInfo |
paulb@277 | 12 | import Acquisition |
paulb@187 | 13 | #from ZPublisher.HTTPResponse import status_reasons |
paulb@187 | 14 | |
paulb@277 | 15 | class WebStackAdapterProduct(Persistent, Acquisition.Implicit, Item): |
paulb@187 | 16 | |
paulb@187 | 17 | "A WebStack adapter product superclass." |
paulb@187 | 18 | |
paulb@277 | 19 | security = ClassSecurityInfo() |
paulb@277 | 20 | security.declareObjectProtected("View") |
paulb@277 | 21 | security.declareProtected("View", "index_html") |
paulb@277 | 22 | |
paulb@277 | 23 | def __init__(self, id, resource, authenticator=None): |
paulb@187 | 24 | |
paulb@187 | 25 | """ |
paulb@187 | 26 | Initialise with an 'id', a WebStack 'resource', and an optional |
paulb@277 | 27 | 'authenticator'. |
paulb@187 | 28 | """ |
paulb@187 | 29 | |
paulb@187 | 30 | self.id = id |
paulb@187 | 31 | self.webstack_resource = resource |
paulb@187 | 32 | self.webstack_authenticator = authenticator |
paulb@187 | 33 | |
paulb@189 | 34 | def __bobo_traverse__(self, request, entry_name): |
paulb@189 | 35 | if entry_name == "index_html": |
paulb@189 | 36 | return getattr(self, "index_html") |
paulb@189 | 37 | return self |
paulb@187 | 38 | |
paulb@187 | 39 | def index_html(self, REQUEST=None): |
paulb@187 | 40 | |
paulb@187 | 41 | """ |
paulb@187 | 42 | Dispatch the given 'REQUEST' to the root application-specific WebStack |
paulb@187 | 43 | resource. |
paulb@187 | 44 | """ |
paulb@187 | 45 | |
paulb@187 | 46 | if REQUEST is not None: |
paulb@187 | 47 | trans = WebStack.Zope.Transaction(REQUEST) |
paulb@187 | 48 | else: |
paulb@187 | 49 | raise "Internal Error" |
paulb@187 | 50 | |
paulb@187 | 51 | if self.webstack_authenticator is None or self.webstack_authenticator.authenticate(trans): |
paulb@187 | 52 | self.webstack_resource.respond(trans) |
paulb@187 | 53 | else: |
paulb@271 | 54 | #trans.set_header_value("WWW-Authenticate", '%s realm="%s"' % ( |
paulb@271 | 55 | # self.webstack_authenticator.get_auth_type(), self.webstack_authenticator.get_realm())) |
paulb@187 | 56 | raise "Unauthorized" |
paulb@187 | 57 | |
paulb@187 | 58 | trans.commit() |
paulb@187 | 59 | #raise status_reasons[trans.get_response_code()] |
paulb@187 | 60 | |
paulb@187 | 61 | # vim: tabstop=4 expandtab shiftwidth=4 |