fix: saml callback should check saml state

This commit is contained in:
JimMoen 2023-09-27 17:35:08 +08:00
parent 1f8985d09e
commit af9e87c025
No known key found for this signature in database
GPG Key ID: 87A520B4F76BA86D
2 changed files with 9 additions and 9 deletions

View File

@ -4,5 +4,5 @@
{deps, [ {deps, [
{emqx_ldap, {path, "../../apps/emqx_ldap"}}, {emqx_ldap, {path, "../../apps/emqx_ldap"}},
{emqx_dashboard, {path, "../../apps/emqx_dashboard"}}, {emqx_dashboard, {path, "../../apps/emqx_dashboard"}},
{esaml, {git, "https://github.com/emqx/esaml", {tag, "v1.1.1"}}} {esaml, {git, "https://github.com/emqx/esaml", {tag, "v1.1.2"}}}
]}. ]}.

View File

@ -82,19 +82,17 @@ schema("/sso/saml/metadata") ->
sp_saml_metadata(get, _Req) -> sp_saml_metadata(get, _Req) ->
case emqx_dashboard_sso_manager:lookup_state(saml) of case emqx_dashboard_sso_manager:lookup_state(saml) of
undefined -> #{enable := true, sp := SP} = _State ->
{404, #{code => ?BACKEND_NOT_FOUND, message => <<"Backend not found">>}};
#{sp := SP} = _State ->
SignedXml = esaml_sp:generate_metadata(SP), SignedXml = esaml_sp:generate_metadata(SP),
Metadata = xmerl:export([SignedXml], xmerl_xml), Metadata = xmerl:export([SignedXml], xmerl_xml),
{200, #{<<"Content-Type">> => <<"text/xml">>}, erlang:iolist_to_binary(Metadata)} {200, #{<<"Content-Type">> => <<"text/xml">>}, erlang:iolist_to_binary(Metadata)};
_ ->
{404, #{code => ?BACKEND_NOT_FOUND, message => <<"Backend not found">>}}
end. end.
sp_saml_callback(post, Req) -> sp_saml_callback(post, Req) ->
case emqx_dashboard_sso_manager:lookup_state(saml) of case emqx_dashboard_sso_manager:lookup_state(saml) of
undefined -> State = #{enable := true} ->
{404, #{code => ?BACKEND_NOT_FOUND, message => <<"Backend not found">>}};
State ->
case (provider(saml)):callback(Req, State) of case (provider(saml)):callback(Req, State) of
{redirect, Redirect} -> {redirect, Redirect} ->
Redirect; Redirect;
@ -105,7 +103,9 @@ sp_saml_callback(post, Req) ->
reason => Reason reason => Reason
}), }),
{403, #{code => <<"UNAUTHORIZED">>, message => Reason}} {403, #{code => <<"UNAUTHORIZED">>, message => Reason}}
end end;
_ ->
{404, #{code => ?BACKEND_NOT_FOUND, message => <<"Backend not found">>}}
end. end.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------