# HG changeset patch # User paulb # Date 1085851544 0 # Node ID 12735bb3eedf68bbfdd6ad0cc5c37cc0e1491d6f # Parent 59bfcff46a3d992fdc6cdd6e47568703c819a679 [project @ 2004-05-29 17:25:44 by paulb] Added a set_user method which is used to override the user identity provided in the request sent in to WebStack. This is useful for providing alternative authentication systems which act like the standard HTTP mechanisms. diff -r 59bfcff46a3d -r 12735bb3eedf WebStack/BaseHTTPRequestHandler.py --- a/WebStack/BaseHTTPRequestHandler.py Thu May 27 22:18:00 2004 +0000 +++ b/WebStack/BaseHTTPRequestHandler.py Sat May 29 17:25:44 2004 +0000 @@ -33,6 +33,7 @@ self.content = StringIO() self.headers_out = {} self.cookies_out = Cookie.SimpleCookie() + self.user = None # Define the incoming cookies. @@ -217,6 +218,9 @@ Returns a username as a string or None if no user is defined. """ + if self.user is not None: + return self.user + auth_header = self.get_headers().get("authorization") if auth_header: return UserInfo(auth_header).username @@ -346,4 +350,16 @@ self.cookies_out[cookie_name]["expires"] = 0 self.cookies_out[cookie_name]["max-age"] = 0 + # Application-specific methods. + + def set_user(self, username): + + """ + An application-specific method which sets the user information with + 'username' in the transaction. This affects subsequent calls to + 'get_user'. + """ + + self.user = username + # vim: tabstop=4 expandtab shiftwidth=4 diff -r 59bfcff46a3d -r 12735bb3eedf WebStack/CGI.py --- a/WebStack/CGI.py Thu May 27 22:18:00 2004 +0000 +++ b/WebStack/CGI.py Sat May 29 17:25:44 2004 +0000 @@ -38,6 +38,7 @@ self.content = StringIO() self.headers_out = {} self.cookies_out = Cookie.SimpleCookie() + self.user = None # Define the incoming cookies. @@ -213,7 +214,10 @@ Returns a username as a string or None if no user is defined. """ - return self.env.get("REMOTE_USER") + if self.user is not None: + return self.user + else: + return self.env.get("REMOTE_USER") def get_cookies(self): @@ -340,4 +344,16 @@ self.cookies_out[cookie_name]["expires"] = 0 self.cookies_out[cookie_name]["max-age"] = 0 + # Application-specific methods. + + def set_user(self, username): + + """ + An application-specific method which sets the user information with + 'username' in the transaction. This affects subsequent calls to + 'get_user'. + """ + + self.user = username + # vim: tabstop=4 expandtab shiftwidth=4 diff -r 59bfcff46a3d -r 12735bb3eedf WebStack/Generic.py --- a/WebStack/Generic.py Thu May 27 22:18:00 2004 +0000 +++ b/WebStack/Generic.py Sat May 29 17:25:44 2004 +0000 @@ -355,6 +355,18 @@ raise NotImplementedError, "delete_cookie" + # Application-specific methods. + + def set_user(self, username): + + """ + An application-specific method which sets the user information with + 'username' in the transaction. This affects subsequent calls to + 'get_user'. + """ + + raise NotImplementedError, "set_user" + class Resource: "A generic resource interface." diff -r 59bfcff46a3d -r 12735bb3eedf WebStack/JavaServlet.py --- a/WebStack/JavaServlet.py Thu May 27 22:18:00 2004 +0000 +++ b/WebStack/JavaServlet.py Sat May 29 17:25:44 2004 +0000 @@ -55,6 +55,7 @@ self.request = request self.response = response self.status = None + self.user = None # Remember the cookies received in the request. # NOTE: Discarding much of the information received. @@ -233,7 +234,10 @@ Returns a username as a string or None if no user is defined. """ - return self.request.getRemoteUser() + if self.user is not None: + return self.user + else: + return self.request.getRemoteUser() def get_cookies(self): @@ -353,4 +357,16 @@ cookie.setMaxAge(0) self.response.addCookie(cookie) + # Application-specific methods. + + def set_user(self, username): + + """ + An application-specific method which sets the user information with + 'username' in the transaction. This affects subsequent calls to + 'get_user'. + """ + + self.user = username + # vim: tabstop=4 expandtab shiftwidth=4 diff -r 59bfcff46a3d -r 12735bb3eedf WebStack/ModPython.py --- a/WebStack/ModPython.py Thu May 27 22:18:00 2004 +0000 +++ b/WebStack/ModPython.py Sat May 29 17:25:44 2004 +0000 @@ -25,6 +25,7 @@ self.trans = trans self.response_code = apache.OK + self.user = None # Request-related methods. @@ -167,7 +168,10 @@ Returns a username as a string or None if no user is defined. """ - return self.trans.user + if self.user is not None: + return self.user + else: + return self.trans.user def get_cookies(self): @@ -300,4 +304,16 @@ # NOTE: Should raise an exception or provide an implementation. pass + # Application-specific methods. + + def set_user(self, username): + + """ + An application-specific method which sets the user information with + 'username' in the transaction. This affects subsequent calls to + 'get_user'. + """ + + self.user = username + # vim: tabstop=4 expandtab shiftwidth=4 diff -r 59bfcff46a3d -r 12735bb3eedf WebStack/Twisted.py --- a/WebStack/Twisted.py Thu May 27 22:18:00 2004 +0000 +++ b/WebStack/Twisted.py Sat May 29 17:25:44 2004 +0000 @@ -20,6 +20,7 @@ "Initialise the transaction using the Twisted transaction 'trans'." self.trans = trans + self.user = None # Request-related methods. @@ -160,7 +161,10 @@ Returns a username as a string or None if no user is defined. """ - # NOTE: Twisted makes headers lower case, for some reason. + # Twisted makes headers lower case. + + if self.user is not None: + return self.user auth_header = self.get_headers().get("authorization") if auth_header: @@ -287,4 +291,16 @@ self.trans.addCookie(cookie_name, "", expires=0, path="/", max_age=0) + # Application-specific methods. + + def set_user(self, username): + + """ + An application-specific method which sets the user information with + 'username' in the transaction. This affects subsequent calls to + 'get_user'. + """ + + self.user = username + # vim: tabstop=4 expandtab shiftwidth=4 diff -r 59bfcff46a3d -r 12735bb3eedf WebStack/Webware.py --- a/WebStack/Webware.py Thu May 27 22:18:00 2004 +0000 +++ b/WebStack/Webware.py Sat May 29 17:25:44 2004 +0000 @@ -21,6 +21,7 @@ "Initialise the transaction using the Webware transaction 'trans'." self.trans = trans + self.user = None # Request-related methods. @@ -188,6 +189,9 @@ # NOTE: actual headers are not available. Therefore, the Web server must # NOTE: itself be set up to provide user support. + if self.user is not None: + return self.user + try: return self.trans.request().remoteUser() except KeyError, exc: @@ -311,4 +315,16 @@ self.trans.response().delCookie(cookie_name) + # Application-specific methods. + + def set_user(self, username): + + """ + An application-specific method which sets the user information with + 'username' in the transaction. This affects subsequent calls to + 'get_user'. + """ + + self.user = username + # vim: tabstop=4 expandtab shiftwidth=4