This commit is contained in:
Feng Lee 2015-05-12 22:39:27 +08:00
parent ebf04c86d4
commit e93f4cf077
4 changed files with 13 additions and 13 deletions

View File

@ -1,4 +1,3 @@
## Overview ## Overview
Authentication with LDAP. Authentication with LDAP.
@ -16,7 +15,6 @@ Authentication with LDAP.
{"certfile", "ssl.crt"}, {"certfile", "ssl.crt"},
{"keyfile", "ssl.key"}]} {"keyfile", "ssl.key"}]}
]} ]}
``` ```
## Load Plugin ## Load Plugin

View File

@ -1,6 +1,6 @@
{application, emqttd_auth_ldap, {application, emqttd_auth_ldap,
[ [
{description, "emqttd LDA Authentication Plugin"}, {description, "emqttd LDAP Authentication Plugin"},
{vsn, "1.0"}, {vsn, "1.0"},
{registered, []}, {registered, []},
{applications, [ {applications, [

View File

@ -30,6 +30,8 @@
-include_lib("emqttd/include/emqttd.hrl"). -include_lib("emqttd/include/emqttd.hrl").
-import(proplists, [get_value/2, get_value/3]).
-behaviour(emqttd_auth_mod). -behaviour(emqttd_auth_mod).
-export([init/1, check/3, description/0]). -export([init/1, check/3, description/0]).
@ -37,14 +39,14 @@
-record(state, {servers, user_dn, options}). -record(state, {servers, user_dn, options}).
init(Opts) -> init(Opts) ->
Servers = proplists:get_value(servers, Opts, ["localhost"]), Servers = get_value(servers, Opts, ["localhost"]),
Port = proplists:get_value(port, Opts, 389), Port = get_value(port, Opts, 389),
Timeout = proplists:get_value(timeout, Opts, 30), Timeout = get_value(timeout, Opts, 30),
UserDn = proplists:get_value(user_dn, Opts), UserDn = get_value(user_dn, Opts),
LdapOpts = LdapOpts =
case proplists:get_value(ssl, Opts, false) of case get_value(ssl, Opts, false) of
true -> true ->
SslOpts = proplists:get_value(sslopts, Opts), SslOpts = get_value(sslopts, Opts),
[{port, Port}, {timeout, Timeout}, {sslopts, SslOpts}]; [{port, Port}, {timeout, Timeout}, {sslopts, SslOpts}];
false -> false ->
[{port, Port}, {timeout, Timeout}] [{port, Port}, {timeout, Timeout}]
@ -67,8 +69,6 @@ check(#mqtt_client{username = Username}, Password,
{error, Reason} {error, Reason}
end. end.
description() -> "LDAP Authentication Module".
ldap_bind(LDAP, UserDn, Password) -> ldap_bind(LDAP, UserDn, Password) ->
case catch eldap:simple_bind(LDAP, UserDn, Password) of case catch eldap:simple_bind(LDAP, UserDn, Password) of
ok -> ok ->
@ -87,3 +87,6 @@ fill(Username, UserDn) ->
(S) -> S (S) -> S
end, string:tokens(UserDn, ",="))). end, string:tokens(UserDn, ",="))).
description() ->
"LDAP Authentication Module".

View File

@ -20,7 +20,7 @@
%%% SOFTWARE. %%% SOFTWARE.
%%%----------------------------------------------------------------------------- %%%-----------------------------------------------------------------------------
%%% @doc %%% @doc
%%% LDAP Authentication APP. %%% LDAP Authentication Plugin.
%%% %%%
%%% @end %%% @end
%%%----------------------------------------------------------------------------- %%%-----------------------------------------------------------------------------
@ -56,4 +56,3 @@ stop(_State) ->
init([]) -> init([]) ->
{ok, { {one_for_one, 5, 10}, []} }. {ok, { {one_for_one, 5, 10}, []} }.