Commit a8e31f8995ee487fcf8ef364e1f5ae344c406e91
1 parent
0d6e5db8
created an authentication container. This could initialize the needed authentica…
…tions and then be injected as a single object into the application class
Showing
4 changed files
with
173 additions
and
4 deletions
1 | 1 | /** |
2 | 2 | * \file |
3 | + * Container for authentication modules. | |
4 | + * | |
5 | + * This is a single point of authentication no matter how much | |
6 | + * authentication modules are in place. Thus it prevents adding | |
7 | + * more and more authentication modules to the application. | |
8 | + * This is an auth module itself but this one returns 0 if | |
9 | + * the authentication has failed otherwise the id of the | |
10 | + * successfull auth module. Thus we can identify by what method | |
11 | + * the user has been authenticated. | |
12 | + * | |
13 | + * This can't authenticate by its own. It has to be initialized | |
14 | + * with other auth modules by calling authCreate at least once. | |
15 | + * | |
16 | + * origin intend ... never implemented (but maybe a good idea) | |
17 | + * | |
3 | 18 | * Authenticatio module factory |
4 | 19 | * |
5 | 20 | * A factory to get a specific authentication module. |
... | ... | @@ -28,17 +43,23 @@ |
28 | 43 | #define __AUTH_AUTH_H__ |
29 | 44 | |
30 | 45 | #include "class.h" |
31 | -#include "auth/ldap.h" | |
46 | +#include "uuid.h" | |
47 | +#include "auth.h" | |
48 | +#include "auth/credential.h" | |
49 | + | |
32 | 50 | |
33 | 51 | typedef enum e_AuthModule { |
34 | - AUTH_LDAP = 0 | |
52 | + AUTH_LDAP = 1, | |
53 | + AUTH_STORAGE = 2 | |
35 | 54 | } AuthModule; |
36 | 55 | |
56 | +#define MAX_AUTH AUTH_STORAGE | |
57 | + | |
37 | 58 | CLASS(Auth) { |
59 | + void * auth[MAX_AUTH + 1]; | |
38 | 60 | }; |
39 | 61 | |
40 | -void * authCreateById(Auth, int); | |
41 | -AuthLdap authCreateLdap(Auth); | |
62 | +int authCreate(Auth, AuthModule, ...); | |
42 | 63 | |
43 | 64 | #endif // __AUTH_AUTH_H__ |
44 | 65 | ... | ... |
src/auth/auth.c
0 → 100644
1 | +/** | |
2 | + * \file | |
3 | + * | |
4 | + * \author Georg Hopp | |
5 | + * | |
6 | + * \copyright | |
7 | + * Copyright © 2013 Georg Hopp | |
8 | + * | |
9 | + * This program is free software: you can redistribute it and/or modify | |
10 | + * it under the terms of the GNU General Public License as published by | |
11 | + * the Free Software Foundation, either version 3 of the License, or | |
12 | + * (at your option) any later version. | |
13 | + * | |
14 | + * This program is distributed in the hope that it will be useful, | |
15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | + * GNU General Public License for more details. | |
18 | + * | |
19 | + * You should have received a copy of the GNU General Public License | |
20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 | + */ | |
22 | + | |
23 | +#include <stdarg.h> | |
24 | +#include <stdlib.h> | |
25 | +#include <string.h> | |
26 | +#include <stdio.h> | |
27 | +#include <ldap.h> | |
28 | + | |
29 | +#include "class.h" | |
30 | +#include "uuid.h" | |
31 | +#include "utils/memory.h" | |
32 | +#include "commons.h" | |
33 | + | |
34 | +#include "auth.h" | |
35 | +#include "auth/credential.h" | |
36 | +#include "auth/interface/auth.h" | |
37 | + | |
38 | +static | |
39 | +int | |
40 | +authCtor(void * _this, va_list * params) | |
41 | +{ | |
42 | + Auth this = _this; | |
43 | + int i; | |
44 | + | |
45 | + for (i=0; i<=MAX_AUTH; i++) { | |
46 | + this->auth[i] = NULL; | |
47 | + } | |
48 | + | |
49 | + return 0; | |
50 | +} | |
51 | + | |
52 | +static | |
53 | +void | |
54 | +authDtor(void * _this) | |
55 | +{ | |
56 | + Auth this = _this; | |
57 | + int i; | |
58 | + | |
59 | + for (i=1; i<=MAX_AUTH; i++) { | |
60 | + delete(this->auth[i]); | |
61 | + } | |
62 | +} | |
63 | + | |
64 | +static | |
65 | +int | |
66 | +authAuthenticate(void * _this, Credential cred, Uuid user_index) | |
67 | +{ | |
68 | + Auth this = _this; | |
69 | + int i; | |
70 | + | |
71 | + for (i=1; i<=MAX_AUTH; i++) { | |
72 | + if (authenticate(this->auth[i], cred, user_index)) { | |
73 | + return i; | |
74 | + } | |
75 | + } | |
76 | + | |
77 | + return FALSE; | |
78 | +} | |
79 | + | |
80 | +INIT_IFACE(Class, authCtor, authDtor, NULL); | |
81 | +INIT_IFACE(Auth, authAuthenticate); | |
82 | +CREATE_CLASS(Auth, NULL, IFACE(Class), IFACE(Auth)); | |
83 | + | |
84 | +// vim: set ts=4 sw=4: | ... | ... |
src/auth/create.c
0 → 100644
1 | +/** | |
2 | + * \file | |
3 | + * | |
4 | + * \author Georg Hopp | |
5 | + * | |
6 | + * \copyright | |
7 | + * Copyright © 2013 Georg Hopp | |
8 | + * | |
9 | + * This program is free software: you can redistribute it and/or modify | |
10 | + * it under the terms of the GNU General Public License as published by | |
11 | + * the Free Software Foundation, either version 3 of the License, or | |
12 | + * (at your option) any later version. | |
13 | + * | |
14 | + * This program is distributed in the hope that it will be useful, | |
15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | + * GNU General Public License for more details. | |
18 | + * | |
19 | + * You should have received a copy of the GNU General Public License | |
20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 | + */ | |
22 | + | |
23 | +#include <stdarg.h> | |
24 | +#include <sys/types.h> | |
25 | + | |
26 | +#include "class.h" | |
27 | +#include "auth.h" | |
28 | +#include "auth/ldap.h" | |
29 | +#include "auth/storage.h" | |
30 | +#include "commons.h" | |
31 | + | |
32 | +int | |
33 | +authCreate(Auth this, AuthModule module, ...) | |
34 | +{ | |
35 | + va_list params; | |
36 | + | |
37 | + if (NULL != this->auth[module]) { | |
38 | + delete(this->auth[module]); | |
39 | + } | |
40 | + | |
41 | + va_start(params, module); | |
42 | + | |
43 | + switch (module) { | |
44 | + case AUTH_LDAP: | |
45 | + this->auth[module] = newParams(AuthLdap, ¶ms); | |
46 | + break; | |
47 | + | |
48 | + case AUTH_STORAGE: | |
49 | + this->auth[module] = newParams(AuthStorage, ¶ms); | |
50 | + break; | |
51 | + } | |
52 | + | |
53 | + va_end(params); | |
54 | + | |
55 | + if (NULL == this->auth[module]) { | |
56 | + return FALSE; | |
57 | + } | |
58 | + | |
59 | + return module; | |
60 | +} | |
61 | + | |
62 | +// vim: set ts=4 sw=4: | ... | ... |
Please
register
or
login
to post a comment