예제 #1
0
    def decorated(self, *args, **kwargs):
        """
        """

        # Fetch auth options from args
        auth_options = {}
        nipap_args = {}

        # validate function arguments
        if len(args) == 1:
            nipap_args = args[0]
        else:
            #logger.info("Malformed request: got %d parameters" % len(args))
            raise Fault(
                1000,
                ("NIPAP API functions take exactly 1 argument (%d given)") %
                len(args))

        if type(nipap_args) != dict:
            raise Fault(1000, (
                "Function argument must be XML-RPC struct/Python dict (Python %s given)."
                % type(nipap_args).__name__))

        # fetch auth options
        try:
            auth_options = nipap_args['auth']
            if type(auth_options) is not dict:
                raise ValueError()
        except (KeyError, ValueError):
            raise Fault(1000,
                        ("Missing/invalid authentication options in request."))

        # fetch authoritative source
        try:
            auth_source = auth_options['authoritative_source']
        except KeyError:
            raise Fault(1000,
                        ("Missing authoritative source in auth options."))

        if not request.authorization:
            return authenticate()

        # init AuthFacory()
        af = AuthFactory()
        auth = af.get_auth(request.authorization.username,
                           request.authorization.password, auth_source,
                           auth_options or {})

        # authenticated?
        if not auth.authenticate():
            raise Fault(1510, ("Incorrect username or password."))

        # Replace auth options in API call arguments with auth object
        new_args = dict(args[0])
        new_args['auth'] = auth

        return f(self, *(new_args, ), **kwargs)
예제 #2
0
파일: xmlrpc.py 프로젝트: Dhyrule/NIPAP
    def decorated(self, *args, **kwargs):
        """
        """

        # Fetch auth options from args
        auth_options = {}
        nipap_args = {}

        # validate function arguments
        if len(args) == 1:
            nipap_args = args[0]
        else:
            self.logger.debug("Malformed request: got %d parameters" % len(args))
            raise Fault(1000, ("NIPAP API functions take exactly 1 argument (%d given)") % len(args))

        if type(nipap_args) != dict:
            self.logger.debug("Function argument is not struct")
            raise Fault(1000, ("Function argument must be XML-RPC struct/Python dict (Python %s given)." %
                type(nipap_args).__name__ ))

        # fetch auth options
        try:
            auth_options = nipap_args['auth']
            if type(auth_options) is not dict:
                raise ValueError()
        except (KeyError, ValueError):
            self.logger.debug("Missing/invalid authentication options in request.")
            raise Fault(1000, ("Missing/invalid authentication options in request."))

        # fetch authoritative source
        try:
            auth_source = auth_options['authoritative_source']
        except KeyError:
            self.logger.debug("Missing authoritative source in auth options.")
            raise Fault(1000, ("Missing authoritative source in auth options."))

        if not request.authorization:
            return authenticate()

        # init AuthFacory()
        af = AuthFactory()
        auth = af.get_auth(request.authorization.username,
                request.authorization.password, auth_source, auth_options or {})

        # authenticated?
        if not auth.authenticate():
            self.logger.debug("Incorrect username or password.")
            raise Fault(1510, ("Incorrect username or password."))

        # Replace auth options in API call arguments with auth object
        new_args = dict(args[0])
        new_args['auth'] = auth

        return f(self, *(new_args,), **kwargs)
예제 #3
0
파일: xmlrpc.py 프로젝트: tobbakko/NIPAP
    def __init__(self):
        xmlrpc.XMLRPC.__init__(self)
        self.allowNone = True
        self.request = None
        self.logger = logging.getLogger(self.__class__.__name__)
        self.logger.info("Initialising NIPAP Protocol")

        self.nipap = nipap.Nipap()
        self._auth_fact = AuthFactory()
예제 #4
0
파일: xmlrpc.py 프로젝트: hetznerZA/NIPAP
    def __init__(self):
        xmlrpc.XMLRPC.__init__(self)
        # Allow None values over XML-RPC. NULL values are not defined in the
        # XML-RPC standard but is a addition supported by many implementations.
        self.allowNone = True
        self.request = None
        self.logger = logging.getLogger(self.__class__.__name__)
        self.logger.info("Initialising NIPAP Protocol")

        self.nipap = Nipap()
        self._auth_fact = AuthFactory()
예제 #5
0
파일: xmlrpc.py 프로젝트: tobbakko/NIPAP
class NipapProtocol(xmlrpc.XMLRPC):
    """ Class to allow XML-RPC access to the lovely NIPAP system.
    """

    _auth_fact = None

    def __init__(self):
        xmlrpc.XMLRPC.__init__(self)
        self.allowNone = True
        self.request = None
        self.logger = logging.getLogger(self.__class__.__name__)
        self.logger.info("Initialising NIPAP Protocol")

        self.nipap = nipap.Nipap()
        self._auth_fact = AuthFactory()


    def render(self, request):

        request.content.seek(0, 0)
        args, functionPath = xmlrpclib.loads(request.content.read())

        # Authentication
        #
        # Fetch auth options from args
        auth_options = {}
        nipap_args = {}

        # validate function arguments
        if len(args) == 1:
            nipap_args = args[0]
        else:
            self.logger.info("Malformed request: got %d parameters" % len(args))
            f = xmlrpclib.Fault(1000, ("NIPAP API functions take exactly 1 "
                "argument (%d given)") % len(args))
            self._cbRender(f, request)
            return server.NOT_DONE_YET

        if type(nipap_args) != dict:
            f = xmlrpclib.Fault(1000, ("Function argument must be XML-RPC "
                "struct/Python dict (Python %s given)." %
                type(nipap_args).__name__ ))
            self._cbRender(f, request)
            return server.NOT_DONE_YET

        # fetch auth options
        try:
            auth_options = nipap_args['auth']
        except KeyError:
            f = xmlrpclib.Fault(1000,
                ("Missing authentication options in request."))
            self._cbRender(f, request)
            return server.NOT_DONE_YET

        # fetch authoritative source
        try:
            auth_source = auth_options['authoritative_source']
        except KeyError:
            f = xmlrpclib.Fault(1000,
                ("Missing authoritative source in auth options."))
            self._cbRender(f, request)
            return server.NOT_DONE_YET

        # fetch auth object for session
        try:
            auth = self._auth_fact.get_auth(request.getUser(), request.getPassword(), auth_source, auth_options or {})
        except AuthError, exp:
            self.logger.error("Authentication failed: %s" % str(exp))
            request.setResponseCode(http.UNAUTHORIZED)
            return "Authentication error."

        # authenticated?
        if not auth.authenticate():
            request.setResponseCode(http.UNAUTHORIZED)
            return "Authentication failed."

        # Replace auth options in API call arguments with auth object
        try:
            args[0]['auth'] = auth
        except:
            pass

        # Authentication done
        ver = twisted.python.versions.Version('twisted', 11, 1, 0)
        try:
            if twisted._version.version >= ver:
                function = self.lookupProcedure(functionPath)
            else:
                function = self._getFunction(functionPath)
        except xmlrpclib.Fault, f:
            self._cbRender(f, request)
예제 #6
0
    def decorated(self, *args, **kwargs):
        """
        """
        # small hack
        args = args + (combine_request_args(), )

        # Fetch auth options from args
        auth_options = {}
        nipap_args = {}

        # validate function arguments
        if len(args) == 1:
            nipap_args = args[0]
        else:
            self.logger.debug("Malformed request: got %d parameters" %
                              len(args))
            abort(401,
                  error={
                      "code": 401,
                      "message":
                      "Malformed request: got %d parameters" % len(args)
                  })

        if type(nipap_args) != dict:
            self.logger.debug("Function argument is not struct")
            abort(401,
                  error={
                      "code": 401,
                      "message": "Function argument is not struct"
                  })

        # fetch auth options
        try:
            auth_options = nipap_args['auth']
            if type(auth_options) is not dict:
                raise ValueError()
        except (KeyError, ValueError):
            self.logger.debug(
                "Missing/invalid authentication options in request.")
            abort(401,
                  error={
                      "code":
                      401,
                      "message":
                      "Missing/invalid authentication options in request."
                  })

        # fetch authoritative source
        try:
            auth_source = auth_options['authoritative_source']
        except KeyError:
            self.logger.debug("Missing authoritative source in auth options.")
            abort(401,
                  error={
                      "code": 401,
                      "message":
                      "Missing authoritative source in auth options."
                  })

        if not request.authorization:
            return authenticate()

        # init AuthFacory()
        af = AuthFactory()
        auth = af.get_auth(request.authorization.username,
                           request.authorization.password, auth_source,
                           auth_options or {})

        # authenticated?
        if not auth.authenticate():
            self.logger.debug("Incorrect username or password.")
            abort(401,
                  error={
                      "code": 401,
                      "message": "Incorrect username or password"
                  })

        # Replace auth options in API call arguments with auth object
        new_args = dict(args[0])
        new_args['auth'] = auth

        return f(self, *(new_args, ), **kwargs)