Exemplo n.º 1
0
class BrainSecuritiesConfiguration(BaseSectionConfigurationData):
    def __init__(self):
        BaseSectionConfigurationData.__init__(self, "security")
        self._authorisation = None
        self._authentication = None

    @property
    def authorisation(self):
        return self._authorisation

    @property
    def authentication(self):
        return self._authentication

    def load_config_section(self, configuration_file, configuration, bot_root):
        securities = configuration_file.get_section(self.section_name,
                                                    configuration)
        if securities is not None:
            self._authentication = BrainSecurityConfiguration("authentication")
            self._authentication.load_config_section(configuration_file,
                                                     securities, bot_root)

            self._authorisation = BrainSecurityConfiguration("authorisation")
            self._authorisation.load_config_section(configuration_file,
                                                    securities, bot_root)
Exemplo n.º 2
0
    def test_authentication_with_data_denied_srai(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
            security:
                authentication:
                    classname: programy.security.authenticate.passthrough.PassThroughAuthenticationService
                    denied_srai: AUTHENTICATION_FAILED
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")
        self.assertIsNotNone(brain_config)
        services_config = yaml.get_section("security", brain_config)
        self.assertIsNotNone(services_config)

        service_config = BrainSecurityConfiguration("authentication")
        service_config.load_config_section(yaml, services_config, ".")

        self.assertEqual(
            "programy.security.authenticate.passthrough.PassThroughAuthenticationService",
            service_config.classname)
        self.assertEqual("AUTHENTICATION_FAILED", service_config.denied_srai)
        self.assertEqual(BrainSecurityConfiguration.DEFAULT_ACCESS_DENIED,
                         service_config.denied_text)
Exemplo n.º 3
0
    def test_authorisation_with_data_denied_text(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
        brain:
            security:
                authorisation:
                    classname: programy.security.authorise.passthrough.PassThroughAuthorisationService
                    denied_text: Authorisation Failed
        """, ConsoleConfiguration(), ".")

        brain_config = yaml.get_section("brain")
        self.assertIsNotNone(brain_config)
        services_config = yaml.get_section("security", brain_config)
        self.assertIsNotNone(services_config)

        service_config = BrainSecurityConfiguration("authorisation")
        service_config.load_config_section(yaml, services_config, ".")

        self.assertEqual(
            "programy.security.authorise.passthrough.PassThroughAuthorisationService",
            service_config.classname)
        self.assertEqual("Authorisation Failed", service_config.denied_text)
        self.assertIsNone(service_config.denied_srai)
Exemplo n.º 4
0
    def load_config_section(self, file_config, brain_config, bot_root):
        securities = file_config.get_section(self.section_name, brain_config)
        if securities is not None:
            self._authentication = BrainSecurityConfiguration("authentication")
            self._authentication.load_config_section(file_config, securities,
                                                     bot_root)

            self._authorisation = BrainSecurityConfiguration("authorisation")
            self._authorisation.load_config_section(file_config, securities,
                                                    bot_root)
Exemplo n.º 5
0
    def load_config_section(self, configuration_file, configuration, bot_root):
        securities = configuration_file.get_section(self.section_name,
                                                    configuration)
        if securities is not None:
            self._authentication = BrainSecurityConfiguration("authentication")
            self._authentication.load_config_section(configuration_file,
                                                     securities, bot_root)

            self._authorisation = BrainSecurityConfiguration("authorisation")
            self._authorisation.load_config_section(configuration_file,
                                                    securities, bot_root)
Exemplo n.º 6
0
    def test_usersgroups(self):
        service_config = BrainSecurityConfiguration("authorisation")
        service_config._usergroups = os.path.dirname(__file__) + os.sep + "test_usergroups.yaml"

        service = BasicUserGroupAuthorisationService(service_config)
        self.assertIsNotNone(service)

        self.assertTrue(service.authorise("console", "root"))
        self.assertFalse(service.authorise("console", "uber"))

        with self.assertRaises(AuthorisationException):
            service.authorise("anyone", "root")
Exemplo n.º 7
0
 def load_configuration(self, arguments):
     super(AuthoriseTestClient, self).load_configuration(arguments)
     self.configuration.brain_configuration.files.aiml_files._files = [os.path.dirname(__file__)]
     self.configuration.brain_configuration.security._authorisation = BrainSecurityConfiguration("authorisation")
     self.configuration.brain_configuration.security.authorisation._classname = "programy.security.authorise.usergroupsauthorisor.BasicUserGroupAuthorisationService"
     self.configuration.brain_configuration.security.authorisation._denied_srai = "ACCESS_DENIED"
     self.configuration.brain_configuration.security.authorisation._usergroups = os.path.dirname(__file__) + os.sep + "usergroups.yaml"
Exemplo n.º 8
0
    def test_authorise_exception(self):
        testbot = Bot(Brain(BrainConfiguration()), BotConfiguration())

        service = MockClientIdAuthenticationService(BrainSecurityConfiguration("authentication"))
        service.should_authorised = True
        service.raise_exception = True
        self.assertFalse(service.authenticate(testbot, "unknown"))
Exemplo n.º 9
0
    def test_init(self):
        testbot = Bot(Brain(BrainConfiguration()), BotConfiguration())

        service = ClientIdAuthenticationService(BrainSecurityConfiguration("authentication"))
        self.assertIsNotNone(service)
        self.assertTrue(service.authenticate(testbot, "console"))
        self.assertFalse(service.authenticate(testbot, "anyone"))
Exemplo n.º 10
0
 def test_authenticator_with_empty_config(self):
     testbot = Bot(Brain(BrainConfiguration()), BotConfiguration())
     service = Authenticator(BrainSecurityConfiguration("authentication"))
     self.assertIsNotNone(service)
     self.assertIsNotNone(service.configuration)
     self.assertIsNone(service.get_default_denied_srai())
     self.assertFalse(service.authenticate(testbot, "console"))
 def get_brain_config(self):
     brain_config = BrainConfiguration()
     brain_config.security._authorisation = BrainSecurityConfiguration("authorisation")
     brain_config.security.authorisation._classname = "programy.security.authorise.usergroupsauthorisor.BasicUserGroupAuthorisationService"
     brain_config.security.authorisation._denied_srai = "ACCESS_DENIED"
     brain_config.security.authorisation._usergroups = "$BOT_ROOT/usergroups.yaml"
     return brain_config
Exemplo n.º 12
0
 def load_configuration(self, arguments):
     super(AuthenticateTestClient, self).load_configuration(arguments)
     self.configuration.brain_configuration.files.aiml_files._files = [
         os.path.dirname(__file__)
     ]
     self.configuration.brain_configuration.security._authentication = BrainSecurityConfiguration(
         "authentication")
     self.configuration.brain_configuration.security.authentication._classname = "programytest.aiml_tests.authenticate_tests.test_authenticate_aiml.MockAuthenticationService"
     self.configuration.brain_configuration.security.authentication._denied_srai = "AUTHENTICATED_FAILED"
Exemplo n.º 13
0
 def test_authorise_success(self):
     service = MockClientIdAuthenticationService(
         BrainSecurityConfiguration("authentication"))
     service.should_authorised = True
     self.assertTrue("console" in service.authorised)
     self.assertTrue(service.authenticate("console"))
     self.assertFalse("unknown" in service.authorised)
     self.assertTrue(service.authenticate("unknown"))
     self.assertTrue("unknown" in service.authorised)
 def test_service(self):
     service = ClientIdAuthenticationService(
         BrainSecurityConfiguration("authentication"))
     self.assertIsNotNone(service)
     self.assertTrue(service.authenticate("console"))
     self.assertFalse(service.authenticate("anyone"))
Exemplo n.º 15
0
 def test_authorise_failure(self):
     service = MockClientIdAuthenticationService(
         BrainSecurityConfiguration("authentication"))
     service.should_authorised = False
     self.assertFalse("unknown" in service.authorised)
     self.assertFalse(service.authenticate("unknown"))