From cbac77110ee1d7b9abc5a23f973dab27e8b32015 Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Wed, 20 Mar 2013 14:22:36 -0400 Subject: [PATCH] Fix for configuring non-default auth plugins properly Make sure we pick up CONF.auth.methods from configuration files. Added a test case to make sure the we don't regress Fixes LP# 1157515 Change-Id: I70290c37b2a5378b5247a14e3bfa20d50bf8fe74 --- keystone/auth/controllers.py | 1 + keystone/common/config.py | 7 +++++++ keystone/config.py | 1 + tests/test_auth.py | 8 ++++++++ 4 files changed, 17 insertions(+) diff --git a/keystone/auth/controllers.py b/keystone/auth/controllers.py index 113655db4a..67a86442c1 100644 --- a/keystone/auth/controllers.py +++ b/keystone/auth/controllers.py @@ -277,6 +277,7 @@ class Auth(controller.V3Controller): def __init__(self, *args, **kw): super(Auth, self).__init__(*args, **kw) self.token_controllers_ref = token.controllers.Auth() + config.setup_authentication() def authenticate_for_token(self, context, auth=None): """ Authenticate user and issue a token. """ diff --git a/keystone/common/config.py b/keystone/common/config.py index fce333dd97..f749300d5e 100644 --- a/keystone/common/config.py +++ b/keystone/common/config.py @@ -124,6 +124,13 @@ def setup_logging(conf): root_logger.addHandler(handler) +def setup_authentication(): + # register any non-default auth methods here (used by extensions, etc) + for method_name in CONF.auth.methods: + if method_name not in _DEFAULT_AUTH_METHODS: + register_str(method_name, group="auth") + + def register_str(*args, **kw): conf = kw.pop('conf', CONF) group = kw.pop('group', None) diff --git a/keystone/config.py b/keystone/config.py index 6414ad641f..e2ff6f4e87 100644 --- a/keystone/config.py +++ b/keystone/config.py @@ -30,3 +30,4 @@ register_bool = config.register_bool register_cli_bool = config.register_cli_bool register_int = config.register_int register_cli_int = config.register_cli_int +setup_authentication = config.setup_authentication diff --git a/tests/test_auth.py b/tests/test_auth.py index 85cc22124f..e78176075e 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -790,3 +790,11 @@ class TokenExpirationTest(AuthTest): def test_maintain_uuid_token_expiration(self): self.opt_in_group('signing', token_format='UUID') self._maintain_token_expiration() + + +class NonDefaultAuthTest(test.TestCase): + + def test_add_non_default_auth_method(self): + self.opt_in_group('auth', methods=['password', 'token', 'custom']) + config.setup_authentication() + self.assertTrue(hasattr(CONF.auth, 'custom'))