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

@@ -16,3 +16,9 @@ wfd_authenticator_authenticate(
credentials, authenticator.data);
}
char const *
wfd_authenticator_get_type(
struct wfd_authenticator authenticator)
{
return authenticator.vtable->get_type(authenticator.data);
}

View File

@@ -12,10 +12,15 @@ typedef void
wfd_authenticator_dispose_fn(
void * data);
typedef char const *
wfd_authenticator_get_type_fn(
void * data);
struct wfd_authenticator_vtable
{
wfd_authenticator_dispose_fn * dispose;
wf_authenticate_fn * authenticate;
wfd_authenticator_get_type_fn * get_type;
};
struct wfd_authenticator
@@ -33,6 +38,10 @@ wfd_authenticator_authenticate(
struct wfd_authenticator authenticator,
struct wf_credentials * credentials);
extern char const *
wfd_authenticator_get_type(
struct wfd_authenticator authenticator);
#ifdef __cplusplus
}
#endif

View File

@@ -48,11 +48,20 @@ wfd_file_authenticator_authenticate(
return result;
}
static char const *
wfd_file_authenticator_get_type(
void * data)
{
(void) data;
return "username";
}
static struct wfd_authenticator_vtable
wfd_file_authenticator_vtable =
{
.dispose = &wfd_file_authenticator_dispose,
.authenticate = &wfd_file_authenticator_authenticate
.authenticate = &wfd_file_authenticator_authenticate,
.get_type = &wfd_file_authenticator_get_type
};
bool

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);
}