+ def GetAuthRealm(self, req):
+ """Override the auth realm for queries.
+
+ """
+ ctx = self._GetRequestContext(req)
+ if ctx.handler_access:
+ return self.AUTH_REALM
+ else:
+ return None
+
+ def Authenticate(self, req, username, password):
+ """Checks whether a user can access a resource.
+
+ """
+ ctx = self._GetRequestContext(req)
+
+ # Check username and password
+ valid_user = False
+ if self._users:
+ user = self._users.get(username, None)
+ if user and user.password == password:
+ valid_user = True
+
+ if not valid_user:
+ # Unknown user or password wrong
+ return False
+
+ if (not ctx.handler_access or
+ set(user.options).intersection(ctx.handler_access)):
+ # Allow access
+ return True
+
+ # Access forbidden
+ raise http.HttpForbidden()
+
+ def HandleRequest(self, req):
+ """Handles a request.
+
+ """
+ ctx = self._GetRequestContext(req)