Exemple #1
0
class AuthResource(resource.ResourceBase):
    
    implements(interface.IAuthResource)
    
    def __init__(self, service):
        resource.ResourceBase.__init__(self, service)
        self.auth_service = IAuthService(service)
        
    def get_response(self, request):
        d = self.auth_user(request)
        d.addCallback(self.check_and_auth, request)
        return d
    
    def check_and_auth(self, authUser, request):
        d = self.check(authUser, request)
        d.addCallback(self.checked, authUser, request)
        return d
    
    def check(self, authUser, request):
        m_check = getattr(self, "check_" + request.method, None)
        if not m_check:
            return defer.succeed(True)
        return m_check(authUser, request)
    
    def checked(self, result, authUser, request):
        if result:
            return self.auth(authUser, request)
        return defer.fail(Exception("Access denied"))
    
    def auth(self, authUser, request):
        m_auth = getattr(self, "auth_" + request.method, None)
        if not m_auth:
            return defer.fail(Exception("Unsupported method"))
        return m_auth(authUser, request)
    
    def auth_user(self, request):
        return self.auth_service.auth_user(request)
Exemple #2
0
 def __init__(self, service):
     resource.ResourceBase.__init__(self, service)
     self.auth_service = IAuthService(service)