mirror of
https://github.com/falk-werner/webfused
synced 2024-10-27 20:44:08 +00:00
allow specification of multiple authenticators
This commit is contained in:
parent
b37e95f724
commit
46ba61e97d
14
README.md
14
README.md
@ -37,15 +37,15 @@ server:
|
|||||||
}
|
}
|
||||||
|
|
||||||
authentication:
|
authentication:
|
||||||
{
|
(
|
||||||
# name of authenticaton provider
|
|
||||||
provider = "file"
|
|
||||||
|
|
||||||
settings:
|
|
||||||
{
|
{
|
||||||
file = "/etc/webfused/passwd"
|
provider = "file"
|
||||||
|
settings:
|
||||||
|
{
|
||||||
|
file = "/etc/webfused/passwd"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
|
|
||||||
filesystems:
|
filesystems:
|
||||||
(
|
(
|
||||||
|
@ -17,13 +17,15 @@ server:
|
|||||||
}
|
}
|
||||||
|
|
||||||
authentication:
|
authentication:
|
||||||
{
|
(
|
||||||
provider = "file"
|
|
||||||
settings:
|
|
||||||
{
|
{
|
||||||
file = "/etc/webfused/passwd"
|
provider = "file"
|
||||||
|
settings:
|
||||||
|
{
|
||||||
|
file = "/etc/webfused/passwd"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
|
|
||||||
filesystems:
|
filesystems:
|
||||||
(
|
(
|
||||||
|
@ -151,6 +151,47 @@ wfd_config_read_server(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
wfd_config_read_authenticator(
|
||||||
|
config_setting_t * authenticator,
|
||||||
|
struct wfd_config_builder builder)
|
||||||
|
{
|
||||||
|
bool result = (NULL != authenticator);
|
||||||
|
|
||||||
|
char const * provider_name = NULL;
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
int rc = config_setting_lookup_string(authenticator, "provider", &provider_name);
|
||||||
|
if (CONFIG_TRUE != rc)
|
||||||
|
{
|
||||||
|
WFD_ERROR("missing authentication provider");
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct config_setting_t * settings = NULL;
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
settings = config_setting_lookup(authenticator, "settings");
|
||||||
|
if (NULL == settings)
|
||||||
|
{
|
||||||
|
WFD_ERROR("missing authentication settings");
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
struct wfd_settings auth_settings;
|
||||||
|
wfd_settings_init(&auth_settings, settings);
|
||||||
|
|
||||||
|
result = wfd_config_builder_add_auth_provider(builder, provider_name, &auth_settings);
|
||||||
|
wfd_settings_cleanup(&auth_settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
wfd_config_read_authentication(
|
wfd_config_read_authentication(
|
||||||
config_t * config,
|
config_t * config,
|
||||||
@ -158,37 +199,14 @@ wfd_config_read_authentication(
|
|||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
|
||||||
bool hasAuthentication = (NULL != config_lookup(config, "authentication"));
|
config_setting_t * authentication = config_lookup(config, "authentication");
|
||||||
if (hasAuthentication)
|
if (NULL != authentication)
|
||||||
{
|
{
|
||||||
char const * provider_name = NULL;
|
int length = config_setting_length(authentication);
|
||||||
|
for (int i = 0; (result) && (i < length); i++)
|
||||||
{
|
{
|
||||||
int rc = config_lookup_string(config, "authentication.provider", &provider_name);
|
config_setting_t * authenticator = config_setting_get_elem(authentication, i);
|
||||||
if (CONFIG_TRUE != rc)
|
result = wfd_config_read_authenticator(authenticator, builder);
|
||||||
{
|
|
||||||
WFD_ERROR("missing authentication provider");
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct config_setting_t * settings = NULL;
|
|
||||||
if (result)
|
|
||||||
{
|
|
||||||
settings = config_lookup(config, "authentication.settings");
|
|
||||||
if (NULL == settings)
|
|
||||||
{
|
|
||||||
WFD_ERROR("missing authentication settings");
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result)
|
|
||||||
{
|
|
||||||
struct wfd_settings auth_settings;
|
|
||||||
wfd_settings_init(&auth_settings, settings);
|
|
||||||
|
|
||||||
result = wfd_config_builder_add_auth_provider(builder, provider_name, &auth_settings);
|
|
||||||
wfd_settings_cleanup(&auth_settings);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,10 +268,12 @@ TEST(config, authentication)
|
|||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = 1, minor = 0 }\n"
|
||||||
"authentication:\n"
|
"authentication:\n"
|
||||||
"{\n"
|
"(\n"
|
||||||
" provider = \"test\"\n"
|
" {\n"
|
||||||
" settings: { }\n"
|
" provider = \"test\"\n"
|
||||||
"}\n"
|
" settings: { }\n"
|
||||||
|
" }\n"
|
||||||
|
")\n"
|
||||||
;
|
;
|
||||||
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
|
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
|
||||||
ASSERT_TRUE(result);
|
ASSERT_TRUE(result);
|
||||||
@ -289,10 +291,12 @@ TEST(config, failed_create_authenticator)
|
|||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = 1, minor = 0 }\n"
|
||||||
"authentication:\n"
|
"authentication:\n"
|
||||||
"{\n"
|
"(\n"
|
||||||
" provider = \"test\"\n"
|
" {\n"
|
||||||
" settings: { }\n"
|
" provider = \"test\"\n"
|
||||||
"}\n"
|
" settings: { }\n"
|
||||||
|
" }\n"
|
||||||
|
")\n"
|
||||||
;
|
;
|
||||||
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
|
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
|
||||||
ASSERT_FALSE(result);
|
ASSERT_FALSE(result);
|
||||||
@ -309,9 +313,11 @@ TEST(config, failed_missing_auth_provider)
|
|||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = 1, minor = 0 }\n"
|
||||||
"authentication:\n"
|
"authentication:\n"
|
||||||
"{\n"
|
"(\n"
|
||||||
" settings: { }\n"
|
" {\n"
|
||||||
"}\n"
|
" settings: { }\n"
|
||||||
|
" }\n"
|
||||||
|
")\n"
|
||||||
;
|
;
|
||||||
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
|
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
|
||||||
ASSERT_FALSE(result);
|
ASSERT_FALSE(result);
|
||||||
@ -328,9 +334,11 @@ TEST(config, failed_missing_auth_settings)
|
|||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = 1, minor = 0 }\n"
|
||||||
"authentication:\n"
|
"authentication:\n"
|
||||||
"{\n"
|
"(\n"
|
||||||
" provider = \"test\"\n"
|
" {\n"
|
||||||
"}\n"
|
" provider = \"test\"\n"
|
||||||
|
" }\n"
|
||||||
|
")\n"
|
||||||
;
|
;
|
||||||
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
|
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
|
||||||
ASSERT_FALSE(result);
|
ASSERT_FALSE(result);
|
||||||
|
Loading…
Reference in New Issue
Block a user