48 lines
924 B
Python
Executable File
48 lines
924 B
Python
Executable File
import itertools
|
|
|
|
from lnwsgi.exceptions import Unauthorized,Unauthenticated
|
|
|
|
class Identity:
|
|
|
|
def __init__(self, name, rights):
|
|
self.__name = name
|
|
self.__rights = dict( rights )
|
|
|
|
def name(self):
|
|
return self.__name
|
|
|
|
def rights(self):
|
|
return dict(self.__rights)
|
|
|
|
def authorizePath(self, request, rpath):
|
|
|
|
print("authorizePath(): {0} => {1}".format(rpath, request.path))
|
|
|
|
p = itertools.zip_longest(rpath.split("/"),request.path.split("/"))
|
|
for pi in p:
|
|
if pi[1] is None:
|
|
return True
|
|
if pi[0] == pi[1]:
|
|
continue
|
|
if pi[0] == "*":
|
|
continue
|
|
if pi[0] == "**":
|
|
return True
|
|
|
|
return False
|
|
return True
|
|
|
|
def authorize(self, request):
|
|
for r in self.__rights:
|
|
if self.authorizePath( request, r ):
|
|
return self.__rights[r]
|
|
|
|
if self.__name == "":
|
|
raise Unauthenticated( request )
|
|
raise Unauthorized( request )
|
|
|
|
def __str__(self):
|
|
return self.__name
|
|
|
|
|