1.1 --- a/WebStack/Adapters/Webware.py Sun Feb 29 00:04:53 2004 +0000
1.2 +++ b/WebStack/Adapters/Webware.py Sun Feb 29 00:05:02 2004 +0000
1.3 @@ -28,14 +28,15 @@
1.4 instantiation.
1.5 """
1.6
1.7 - def __init__(self, resource):
1.8 + def __init__(self, resource, authenticator=None):
1.9
1.10 """
1.11 Initialise the parser object with the given root application-specific
1.12 - 'resource'.
1.13 + 'resource' and optional 'authenticator'.
1.14 """
1.15
1.16 self.webstack_resource = resource
1.17 + self.webstack_authenticator = authenticator
1.18
1.19 def parse(self, trans, requestPath):
1.20
1.21 @@ -50,7 +51,7 @@
1.22 should be available elsewhere.
1.23 """
1.24
1.25 - return WebStackServlet(self.webstack_resource)
1.26 + return WebStackServlet(self.webstack_resource, self.webstack_authenticator)
1.27
1.28 # For Webware 0.8.1 and earlier, employ servlet factories and servlets.
1.29
1.30 @@ -64,17 +65,19 @@
1.31 application-specific resources.
1.32 """
1.33
1.34 - def __init__(self, application, resource, file_extensions):
1.35 + def __init__(self, application, resource, file_extensions, authenticator=None):
1.36
1.37 """
1.38 Initialise the servlet factory with the Webware 'application' and the
1.39 WebStack root application-specific 'resource'. The 'file_extensions'
1.40 - specified indicate for which files this factory is invoked.
1.41 + specified indicate for which files this factory is invoked. An optional
1.42 + 'authenticator' is used to control access to the resource.
1.43 """
1.44
1.45 ServletFactory.__init__(self, application)
1.46 self.webstack_resource = resource
1.47 self.file_extensions = file_extensions
1.48 + self.webstack_authenticator = authenticator
1.49
1.50 def uniqueness(self):
1.51
1.52 @@ -101,7 +104,7 @@
1.53 method is invoked on the servlet.
1.54 """
1.55
1.56 - return WebStackServlet(self.webstack_resource)
1.57 + return WebStackServlet(self.webstack_resource, self.webstack_authenticator)
1.58
1.59 # Servlets are common to both solutions.
1.60
1.61 @@ -109,12 +112,16 @@
1.62
1.63 "A servlet which dispatches transactions to application-specific resources."
1.64
1.65 - def __init__(self, resource):
1.66 + def __init__(self, resource, authenticator):
1.67
1.68 - "Initialise the servlet with an application-specific 'resource'."
1.69 + """
1.70 + Initialise the servlet with an application-specific 'resource' and
1.71 + 'authenticator'.
1.72 + """
1.73
1.74 Servlet.__init__(self)
1.75 self.webstack_resource = resource
1.76 + self.webstack_authenticator = authenticator
1.77
1.78 def respond(self, trans):
1.79
1.80 @@ -124,7 +131,13 @@
1.81 """
1.82
1.83 new_trans = WebStack.Webware.Transaction(trans)
1.84 - self.webstack_resource.respond(new_trans)
1.85 + if self.webstack_authenticator is None or self.webstack_authenticator.authenticate(new_trans):
1.86 + self.webstack_resource.respond(new_trans)
1.87 + else:
1.88 + new_trans.set_response_code(401) # Unauthorized
1.89 + new_trans.set_header_value("WWW-Authenticate", '%s realm="%s"' % (
1.90 + self.webstack_authenticator.get_auth_type(), self.webstack_authenticator.get_realm()))
1.91 +
1.92 new_trans.commit()
1.93
1.94 # vim: tabstop=4 expandtab shiftwidth=4