1
0
mirror of https://github.com/falk-werner/webfused synced 2026-03-02 04:09:19 +00:00

add authenticator to server config

This commit is contained in:
Falk Werner
2020-03-17 16:49:17 +01:00
parent d90afed1b2
commit 7e7cbd5d42
9 changed files with 268 additions and 96 deletions

View File

@@ -1,5 +1,7 @@
#include "webfused/config/config.h"
#include "webfuse/adapter/server_config.h"
#include "webfused/auth/factory.h"
#include "webfused/auth/authenticator.h"
#include <stdlib.h>
@@ -9,6 +11,8 @@
struct wfd_config
{
struct wf_server_config * server;
bool has_authenticator;
struct wfd_authenticator authenticator;
};
static void
@@ -56,6 +60,33 @@ wfd_config_set_server_document_root(
wf_server_config_set_documentroot(config->server, document_root);
}
static bool
wfd_config_add_auth_provider(
void * data,
struct wfd_auth_settings * settings)
{
bool result = false;
struct wfd_config * config = data;
if (!config->has_authenticator)
{
result = wfd_authenticator_create(settings, &config->authenticator);
if (result)
{
wf_server_config_add_authenticator(
config->server,
wfd_authenticator_get_type(config->authenticator),
config->authenticator.vtable->authenticate,
config->authenticator.data);
config->has_authenticator = true;
}
}
return result;
}
static const struct wfd_config_builder_vtable
wfd_config_vtable_config_builder =
{
@@ -63,17 +94,21 @@ wfd_config_vtable_config_builder =
.set_server_port = &wfd_config_set_server_port,
.set_server_key = &wfd_config_set_server_key,
.set_server_cert = &wfd_config_set_server_cert,
.set_server_document_root = &wfd_config_set_server_document_root
.set_server_document_root = &wfd_config_set_server_document_root,
.add_auth_provider = &wfd_config_add_auth_provider
};
struct wfd_config *
wfd_config_create(void)
{
struct wfd_config * config = malloc(sizeof(struct wfd_config));
config->server = wf_server_config_create();
wf_server_config_set_vhostname(config->server, WFD_CONFIG_DEFAULT_VHOSTNAME);
wf_server_config_set_port(config->server, WFD_CONFIG_DEFAULT_PORT);
config->has_authenticator = false;
return config;
}
@@ -82,6 +117,11 @@ wfd_config_dispose(
struct wfd_config * config)
{
wf_server_config_dispose(config->server);
if (config->has_authenticator)
{
wfd_authenticator_dispose(config->authenticator);
}
free(config);
}