1.1 --- a/WebStack/Adapters/Twisted.py Sun Feb 29 00:04:53 2004 +0000
1.2 +++ b/WebStack/Adapters/Twisted.py Sun Feb 29 00:05:02 2004 +0000
1.3 @@ -13,12 +13,16 @@
1.4
1.5 isLeaf = 1
1.6
1.7 - def __init__(self, resource):
1.8 + def __init__(self, resource, authenticator=None):
1.9
1.10 - "Initialise the root application-specific 'resource'."
1.11 + """
1.12 + Initialise the root application-specific 'resource' and optional
1.13 + 'authenticator'.
1.14 + """
1.15
1.16 twisted.web.resource.Resource.__init__(self)
1.17 self.webstack_resource = resource
1.18 + self.webstack_authenticator = authenticator
1.19
1.20 def getChild(self, path, request):
1.21 raise NotImplementedError, "getChild"
1.22 @@ -28,7 +32,13 @@
1.23 "Dispatch the given 'request' to the root application-specific resource."
1.24
1.25 trans = WebStack.Twisted.Transaction(request)
1.26 - self.webstack_resource.respond(trans)
1.27 + if self.webstack_authenticator is None or self.webstack_authenticator.authenticate(trans):
1.28 + self.webstack_resource.respond(trans)
1.29 + else:
1.30 + trans.set_response_code(401) # Unauthorized
1.31 + trans.set_header_value("WWW-Authenticate", '%s realm="%s"' % (
1.32 + self.webstack_authenticator.get_auth_type(), self.webstack_authenticator.get_realm()))
1.33 +
1.34 trans.commit()
1.35 request.finish()
1.36 return twisted.web.server.NOT_DONE_YET