Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MUC http auth #894

Merged
merged 14 commits into from
Aug 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/ejabberd/include/mod_muc_room.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@
just_created = false :: boolean(),
activity = treap:empty() :: treap:treap(),
room_shaper :: shaper:shaper(),
room_queue = queue:new()
room_queue = queue:new(),
http_auth_pool = none :: none | mongoose_http_client:pool(),
http_auth_pids = [] :: [pid()]
}).

-record(muc_online_users, {
Expand Down
1 change: 1 addition & 0 deletions apps/ejabberd/src/ejabberd_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ start(normal, _Args) ->
{ok, _} = Sup = ejabberd_sup:start_link(),
ejabberd_rdbms:start(),
mongoose_riak:start(),
mongoose_http_client:start(),
ejabberd_auth:start(),
cyrsasl:start(),
%% Profiling
Expand Down
2 changes: 2 additions & 0 deletions apps/ejabberd/src/ejabberd_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,8 @@ process_term(Term, State) ->
add_option(max_fsm_queue, N, State);
{sasl_mechanisms, Mechanisms} ->
add_option(sasl_mechanisms, Mechanisms, State);
{http_connections, HttpConnections} ->
add_option(http_connections, HttpConnections, State);
{_Opt, _Val} ->
lists:foldl(fun(Host, S) -> process_host_term(Term, Host, S) end,
State, State#state.hosts)
Expand Down
51 changes: 30 additions & 21 deletions apps/ejabberd/src/mod_muc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@
access,
history_size :: integer(),
default_room_opts :: list(),
room_shaper :: shaper:shaper()
room_shaper :: shaper:shaper(),
http_auth_pool :: mongoose_http_client:pool()
}).

-type state() :: #state{}.
Expand Down Expand Up @@ -284,16 +285,21 @@ init([Host, Opts]) ->
AccessCreate = gen_mod:get_opt(access_create, Opts, all),
AccessAdmin = gen_mod:get_opt(access_admin, Opts, none),
AccessPersistent = gen_mod:get_opt(access_persistent, Opts, all),
HttpAuthPool = case gen_mod:get_opt(http_auth_pool, Opts, none) of
none -> none;
PoolName -> mongoose_http_client:get_pool(PoolName)
end,
HistorySize = gen_mod:get_opt(history_size, Opts, 20),
DefRoomOpts = gen_mod:get_opt(default_room_options, Opts, []),
RoomShaper = gen_mod:get_opt(room_shaper, Opts, none),

State = #state{host = MyHost,
server_host = Host,
access = {Access, AccessCreate, AccessAdmin, AccessPersistent},
default_room_opts = DefRoomOpts,
history_size = HistorySize,
room_shaper = RoomShaper},
server_host = Host,
access = {Access, AccessCreate, AccessAdmin, AccessPersistent},
default_room_opts = DefRoomOpts,
history_size = HistorySize,
room_shaper = RoomShaper,
http_auth_pool = HttpAuthPool},

ejabberd_hooks:add(is_muc_room_owner, MyHost, ?MODULE, is_room_owner, 50),
ejabberd_hooks:add(muc_room_pid, MyHost, ?MODULE, muc_room_pid, 50),
Expand All @@ -306,8 +312,7 @@ init([Host, Opts]) ->

load_permanent_rooms(MyHost, Host,
{Access, AccessCreate, AccessAdmin, AccessPersistent},
HistorySize,
RoomShaper),
HistorySize, RoomShaper, HttpAuthPool),
{ok, State}.

%%--------------------------------------------------------------------
Expand All @@ -333,7 +338,8 @@ handle_call({create_instant, Room, From, Nick, Opts},
access = Access,
default_room_opts = DefOpts,
history_size = HistorySize,
room_shaper = RoomShaper} = State) ->
room_shaper = RoomShaper,
http_auth_pool = HttpAuthPool} = State) ->
?DEBUG("MUC: create new room '~s'~n", [Room]),
NewOpts = case Opts of
default -> DefOpts;
Expand All @@ -342,7 +348,7 @@ handle_call({create_instant, Room, From, Nick, Opts},
{ok, Pid} = mod_muc_room:start(
Host, ServerHost, Access,
Room, HistorySize,
RoomShaper, From,
RoomShaper, HttpAuthPool, From,
Nick, [{instant, true}|NewOpts]),
register_room(Host, Room, Pid),
{reply, ok, State}.
Expand Down Expand Up @@ -486,13 +492,14 @@ route_to_nonexistent_room(Room, {From, To, Packet},
case check_user_can_create_room(ServerHost, AccessCreate,
From, Room) of
true ->
HistorySize = State#state.history_size,
RoomShaper = State#state.room_shaper,
DefRoomOpts = State#state.default_room_opts,
#state{history_size = HistorySize,
room_shaper = RoomShaper,
http_auth_pool = HttpAuthPool,
default_room_opts = DefRoomOpts} = State,
{_, _, Nick} = jid:to_lower(To),
{ok, Pid} = start_new_room(Host, ServerHost, Access, Room,
HistorySize, RoomShaper, From,
Nick, DefRoomOpts),
HistorySize, RoomShaper, HttpAuthPool,
From, Nick, DefRoomOpts),
register_room(Host, Room, Pid),
mod_muc_room:route(Pid, From, Nick, Packet),
ok;
Expand Down Expand Up @@ -620,8 +627,8 @@ check_user_can_create_room(ServerHost, AccessCreate, From, RoomID) ->

-spec load_permanent_rooms(Host :: ejabberd:server(), Srv :: ejabberd:server(),
Access :: access(), HistorySize :: 'undefined' | integer(),
RoomShaper :: shaper:shaper()) -> 'ok'.
load_permanent_rooms(Host, ServerHost, Access, HistorySize, RoomShaper) ->
RoomShaper :: shaper:shaper(), HttpAuthPool :: none | mongoose_http_client:pool()) -> 'ok'.
load_permanent_rooms(Host, ServerHost, Access, HistorySize, RoomShaper, HttpAuthPool) ->
case catch mnesia:dirty_select(
muc_room, [{#muc_room{name_host = {'_', Host}, _ = '_'},
[],
Expand All @@ -642,6 +649,7 @@ load_permanent_rooms(Host, ServerHost, Access, HistorySize, RoomShaper) ->
Room,
HistorySize,
RoomShaper,
HttpAuthPool,
R#muc_room.opts),
register_room(Host, Room, Pid);
_ ->
Expand All @@ -654,25 +662,26 @@ load_permanent_rooms(Host, ServerHost, Access, HistorySize, RoomShaper) ->
-spec start_new_room(Host :: 'undefined' | ejabberd:server(),
Srv :: ejabberd:server(), Access :: access(), room(),
HistorySize :: 'undefined' | integer(), RoomShaper :: shaper:shaper(),
From :: ejabberd:jid(), nick(), DefRoomOpts :: 'undefined' | [any()])
HttpAuthPool :: none | mongoose_http_client:pool(), From :: ejabberd:jid(), nick(),
DefRoomOpts :: 'undefined' | [any()])
-> {'error',_}
| {'ok','undefined' | pid()}
| {'ok','undefined' | pid(),_}.
start_new_room(Host, ServerHost, Access, Room,
HistorySize, RoomShaper, From,
HistorySize, RoomShaper, HttpAuthPool, From,
Nick, DefRoomOpts) ->
case mnesia:dirty_read(muc_room, {Room, Host}) of
[] ->
?DEBUG("MUC: open new room '~s'~n", [Room]),
mod_muc_room:start(Host, ServerHost, Access,
Room, HistorySize,
RoomShaper, From,
RoomShaper, HttpAuthPool, From,
Nick, DefRoomOpts);
[#muc_room{opts = Opts}|_] ->
?DEBUG("MUC: restore room '~s'~n", [Room]),
mod_muc_room:start(Host, ServerHost, Access,
Room, HistorySize,
RoomShaper, Opts)
RoomShaper, HttpAuthPool, Opts)
end.


Expand Down
Loading