1 #!/usr/bin/env python 2 3 "A test of authentication/authorisation." 4 5 import WebStack.Generic 6 7 class AuthResource: 8 9 "A resource demanding authentication." 10 11 def respond(self, trans): 12 trans.set_content_type(WebStack.Generic.ContentType("text/html")) 13 14 # Write out confirmation, otherwise. 15 16 out = trans.get_response_stream() 17 out.write(""" 18 <html> 19 <body> 20 <h1>Authorised</h1> 21 <p>Hello user %s!</p> 22 </body> 23 </html> 24 """ % ( 25 trans.get_user(), 26 )) 27 28 class AuthAuthenticator: 29 30 "An authenticator for the application." 31 32 def authenticate(self, trans): 33 user = trans.get_user() 34 return user == "badger" 35 36 def get_auth_type(self): 37 return "Basic" 38 39 def get_realm(self): 40 return "AuthResource" 41 42 # vim: tabstop=4 expandtab shiftwidth=4