Пример #1
0
    def __init__(self, **conf):
        """
        Construct a concrete object with a set of keyword configuration
        options.

        :param **conf:

            external_authn_callable: Either an actual callable, or a string
                                     in dotted-notation
                                     or module.function that will be used
                                     to authenticate. This function will
                                     accept as its only argument the
                                     `talons.interfaces.auth.Identity` object.
            external_sets_roles: Boolean (defaults to False) of whether the
                                 external authentication function will set the
                                 roles attribute of the Identity object.
            external_sets_groups: Boolean (defaults to False) of whether the
                                  external authentication function will set
                                  the groups attribute of the Identity object.

        :raises `talons.exc.BadConfiguration` if configuration options
                are not valid or conflict with each other.
        """
        authfn = conf.pop(
            'external_authn_callable',
            conf.pop('external_authfn', None)
        )  # Backwards-compat

        if not authfn:
            msg = ("Missing required external_authn_callable "
                   "configuration option.")
            LOG.error(msg)
            raise exc.BadConfiguration(msg)

        if not callable(authfn):
            # Try import'ing the auth function to ensure that it exists
            try:
                self.authfn = helpers.import_function(authfn)
            except (TypeError, ImportError):
                msg = ("external_authn_callable either could not be found "
                       "or was not callable.")
                LOG.error(msg)
                raise exc.BadConfiguration(msg)
        else:
            self.authfn = authfn

        # Ensure that the auth function signature is what we expect
        spec = inspect.getargspec(self.authfn)
        if len(spec[0]) != 1:
            msg = ("external_authn_callable has an invalid function "
                   "signature. The function must take only a single "
                   "parameter.")
            LOG.error(msg)
            raise exc.BadConfiguration(msg)

        self._sets_roles = conf.get('external_sets_roles', False)
        self._sets_groups = conf.get('external_sets_groups', False)
Пример #2
0
    def __init__(self, **conf):
        """
        Construct a concrete object with a set of keyword configuration
        options.

        :param **conf:

            external_authn_callable: Dotted-notation module.class.method
                             or module.function that will be used
                             to authenticate. This function will
                             accept as its only argument the
                             `talons.interfaces.auth.Identity` object.
            external_sets_roles: Boolean (defaults to False) of whether the
                                 external authentication function will set the
                                 roles attribute of the Identity object.
            external_sets_groups: Boolean (defaults to False) of whether the
                                  external authentication function will set
                                  the groups attribute of the Identity object.

        :raises `talons.exc.BadConfiguration` if configuration options
                are not valid or conflict with each other.
        """
        authfn = conf.pop('external_authn_callable',
                          conf.pop('external_authfn',
                                   None))  # Backwards-compat
        if not authfn:
            msg = ("Missing required external_authfn " "configuration option.")
            LOG.error(msg)
            raise exc.BadConfiguration(msg)

        # Try import'ing the auth function to ensure that it exists
        try:
            self.authfn = helpers.import_function(authfn)
        except (TypeError, ImportError):
            msg = ("external_authfn either could not be found "
                   "or was not callable.")
            LOG.error(msg)
            raise exc.BadConfiguration(msg)

        # Ensure that the auth function signature is what we expect
        spec = inspect.getargspec(self.authfn)
        if len(spec[0]) != 1:
            msg = ("external_authfn has an invalid function "
                   "signature. The function must take only a single "
                   "parameter.")
            LOG.error(msg)
            raise exc.BadConfiguration(msg)

        self._sets_roles = conf.get('external_sets_roles', False)
        self._sets_groups = conf.get('external_sets_groups', False)
Пример #3
0
    def __init__(self, **conf):
        """
        Construct a concrete object with a set of keyword configuration
        options.

        :param **conf:

            external_authz_callable: An actual callable or a string in
                                     dotted-notation module.function that will
                                     be used to authorize. This function will
                                     accept as its only two arguments a
                                     `talons.interfaces.auth.Identity` object
                                     and a
                                     `talons.interfaces.auth.RequestAction`
                                     object.

        :raises `talons.exc.BadConfiguration` if configuration options
                are not valid or conflict with each other.
        """
        authfn = conf.pop('external_authz_callable', None)
        if not authfn:
            msg = ("Missing required external_authz_callable "
                   "configuration option.")
            LOG.error(msg)
            raise exc.BadConfiguration(msg)

        if not callable(authfn):
            # Try import'ing the auth function to ensure that it exists
            try:
                self.authfn = helpers.import_function(authfn)
            except (TypeError, ImportError):
                msg = ("external_authz_callable either could not be found "
                       "or was not callable.")
                LOG.error(msg)
                raise exc.BadConfiguration(msg)
        else:
            self.authfn = authfn

        # Ensure that the auth function signature is what we expect
        spec = inspect.getargspec(self.authfn)
        if len(spec[0]) != 2:
            msg = ("external_authz_callable has an invalid function "
                   "signature. The function must take two arguments: "
                   "an identity and a request action.")
            LOG.error(msg)
            raise exc.BadConfiguration(msg)
Пример #4
0
    def __init__(self, **conf):
        """
        Construct a concrete object with a set of keyword configuration
        options.

        :param **conf:

            external_authz_callable: Dotted-notation module.class.method
                              or module.function that will be used
                              to authorize. This function will
                              accept as its only two arguments a
                              `talons.interfaces.auth.Identity` object
                              and a `talons.interfaces.auth.RequestAction`
                              object.

        :raises `talons.exc.BadConfiguration` if configuration options
                are not valid or conflict with each other.
        """
        authfn = conf.pop('external_authzfn', None)
        if not authfn:
            msg = ("Missing required external_authzfn "
                   "configuration option.")
            LOG.error(msg)
            raise exc.BadConfiguration(msg)

        # Try import'ing the auth function to ensure that it exists
        try:
            self.authfn = helpers.import_function(authfn)
        except (TypeError, ImportError):
            msg = ("external_authzfn either could not be found "
                   "or was not callable.")
            LOG.error(msg)
            raise exc.BadConfiguration(msg)

        # Ensure that the auth function signature is what we expect
        spec = inspect.getargspec(self.authfn)
        if len(spec[0]) != 2:
            msg = ("external_authzfn has an invalid function "
                   "signature. The function must take two arguments: "
                   "an identity and a request action.")
            LOG.error(msg)
            raise exc.BadConfiguration(msg)
Пример #5
0
 def test_not_callable(self):
     with testtools.ExpectedException(TypeError):
         helpers.import_function('sys.stdout')
Пример #6
0
 def test_no_function_in_module(self):
     with testtools.ExpectedException(ImportError):
         helpers.import_function('sys.noexisting')
Пример #7
0
 def test_bad_import(self):
     with testtools.ExpectedException(ImportError):
         helpers.import_function('not.exist.function')
Пример #8
0
 def test_return_function(self):
     fn = helpers.import_function('os.path.join')
     self.assertEqual(callable(fn), True)
Пример #9
0
 def test_not_callable(self):
     with testtools.ExpectedException(TypeError):
         helpers.import_function('sys.stdout')
Пример #10
0
 def test_no_function_in_module(self):
     with testtools.ExpectedException(ImportError):
         helpers.import_function('sys.noexisting')
Пример #11
0
 def test_bad_import(self):
     with testtools.ExpectedException(ImportError):
         helpers.import_function('not.exist.function')
Пример #12
0
 def test_return_function(self):
     fn = helpers.import_function('os.path.join')
     self.assertEqual(callable(fn), True)