def setUp(self): def check(self): self.user = self.who_am_i return self.user def default_forbidden(): return "this is default 403" acl_init(check, default_forbidden) @acl(["jedi", "sith"]) class TheEndOfTheGalaxyPub(object): def get(self): return "Yeah, it's working" def forbidden(self): if self.user == "pony": return "No ponies allowed here!" raise Exception(44) self.test1 = TheEndOfTheGalaxyPub() @acl(["sith"]) class DeathStar(object): def get(self): return "Yeah, it's working and you are using the Dark Force!" self.test2 = DeathStar()
def setUp(self): def check(self): return False acl_init(check) @acl(True) class BlackHole(object): def get(self): return "Yeah, it's working" self.test1 = BlackHole()
if user_agent.lower().find("chrome") != -1: self.user = "******" elif user_agent.lower().find("ie") != -1: self.user = "******" else: self.user = "******" return self.user # Default behaviour when user is not permitted to access the resource def forbidden(): raise HTTPError(403, "To enter this area you are allowed not") # Initialize the Access Control List checker! acl_init(check, forbidden) class StartPoint(tornado.web.RequestHandler): def get(self): self.finish( "Welcome <b>" + check(self) + "</b>" + "<h1>Everyone can acess this area</h1>Choose a place to go: " + "<ul><li><a href='/potentium'>Potentium (Sith & Jedi)</a></li>" + "<li><a href='/lightside_hq'>GalacticCity (Jedi only)</a></li>" + "<li><a href='/darkside_hq'> DeathStar (Sith only)</a></li>" + "</ul>") # Let's say all Force users can access it freely class Potentium(tornado.web.RequestHandler):
# IE user as the Sith - hey! no bad feelings! if user_agent.lower().find("chrome") != -1: self.user = "******" elif user_agent.lower().find("ie") != -1: self.user = "******" else: self.user = "******" return self.user # Default behaviour when user is not permitted to access the resource def forbidden(): raise HTTPError(403, "To enter this area you are allowed not") # Initialize the Access Control List checker! acl_init(check, forbidden) class StartPoint(tornado.web.RequestHandler): def get(self): self.finish( "Welcome <b>" + check(self) + "</b>" + "<h1>Everyone can acess this area</h1>Choose a place to go: " + "<ul><li><a href='/potentium'>Potentium (Sith & Jedi)</a></li>" + "<li><a href='/lightside_hq'>GalacticCity (Jedi only)</a></li>" + "<li><a href='/darkside_hq'> DeathStar (Sith only)</a></li>" + "</ul>") # Let's say all Force users can access it freely class Potentium(tornado.web.RequestHandler):