1 |
|
%%%============================================================================= |
2 |
|
%%% @copyright (C) 1999-2018, Erlang Solutions Ltd |
3 |
|
%%% @author Denys Gonchar <denys.gonchar@erlang-solutions.com> |
4 |
|
%%% @doc demo PKI auth backend. |
5 |
|
%%% |
6 |
|
%%% it authorises all the certificates with Common Name (used as client's |
7 |
|
%%% "username"), assuming that all of the certificates are valid. |
8 |
|
%%% |
9 |
|
%%% certificate verification can be configured for c2s listener. |
10 |
|
%%% |
11 |
|
%%% as we cannot track properly the list of valid user, does_user_exist/2 |
12 |
|
%%% function is stubbed to true (this one is used by MAM) |
13 |
|
%%% @end |
14 |
|
%%%============================================================================= |
15 |
|
-module(ejabberd_auth_pki). |
16 |
|
-copyright("2018, Erlang Solutions Ltd."). |
17 |
|
-author('denys.gonchar@erlang-solutions.com'). |
18 |
|
|
19 |
|
-include("jlib.hrl"). |
20 |
|
|
21 |
|
-behaviour(mongoose_gen_auth). |
22 |
|
|
23 |
|
%% mongoose_gen_auth API |
24 |
|
-export([start/1, |
25 |
|
stop/1, |
26 |
|
supports_sasl_module/2, |
27 |
|
authorize/1, |
28 |
|
does_user_exist/3, |
29 |
|
supported_features/0 |
30 |
|
]). |
31 |
|
|
32 |
|
-spec start(HostType :: mongooseim:host_type()) -> ok. |
33 |
45 |
start(_) -> ok. |
34 |
|
|
35 |
|
-spec stop(HostType :: mongooseim:host_type()) -> ok. |
36 |
:-( |
stop(_) -> ok. |
37 |
|
|
38 |
|
-spec supports_sasl_module(binary(), cyrsasl:sasl_module()) -> boolean(). |
39 |
258 |
supports_sasl_module(_, Module) -> Module =:= cyrsasl_external. |
40 |
|
|
41 |
|
-spec authorize(mongoose_credentials:t()) -> {ok, mongoose_credentials:t()} | {error, any()}. |
42 |
|
authorize(Creds) -> |
43 |
34 |
{ok, mongoose_credentials:extend(Creds, [{auth_module, ?MODULE}])}. |
44 |
|
|
45 |
|
-spec does_user_exist(mongooseim:host_type(), jid:luser(), jid:lserver()) -> boolean(). |
46 |
:-( |
does_user_exist(_, _, _) -> true. |
47 |
|
|
48 |
|
-spec supported_features() -> [atom()]. |
49 |
15 |
supported_features() -> [dynamic_domains]. |