Skip to content
Open
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
10 changes: 5 additions & 5 deletions lib/samly/idp_data.ex
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ defmodule Samly.IdpData do
@spec save_idp_config(%IdpData{}, map()) :: %IdpData{}
defp save_idp_config(idp_data, %{id: id, sp_id: sp_id} = opts_map)
when is_binary(id) and is_binary(sp_id) do
%IdpData{idp_data | id: id, sp_id: sp_id, base_url: Map.get(opts_map, :base_url)}
%{idp_data | id: id, sp_id: sp_id, base_url: Map.get(opts_map, :base_url)}
|> set_metadata(opts_map)
|> set_pipeline(opts_map)
|> set_allowed_target_urls(opts_map)
Expand Down Expand Up @@ -156,9 +156,9 @@ defmodule Samly.IdpData do
defp update_esaml_recs(idp_data, service_providers, opts_map) do
case Map.get(service_providers, idp_data.sp_id) do
%SpData{} = sp ->
idp_data = %IdpData{idp_data | esaml_idp_rec: to_esaml_idp_metadata(idp_data, opts_map)}
idp_data = %IdpData{idp_data | esaml_sp_rec: get_esaml_sp(sp, idp_data)}
%IdpData{idp_data | valid?: cert_config_ok?(idp_data, sp)}
idp_data = %{idp_data | esaml_idp_rec: to_esaml_idp_metadata(idp_data, opts_map)}
idp_data = %{idp_data | esaml_sp_rec: get_esaml_sp(sp, idp_data)}
%{idp_data | valid?: cert_config_ok?(idp_data, sp)}

_ ->
Logger.error("[Samly] Unknown/invalid sp_id: #{idp_data.sp_id}")
Expand Down Expand Up @@ -271,7 +271,7 @@ defmodule Samly.IdpData do
md_xml = SweetXml.parse(metadata_xml, xml_opts)
signing_certs = get_signing_certs(md_xml)

%IdpData{
%{
idp_data
| entity_id: get_entity_id(md_xml),
signed_requests: get_req_signed(md_xml),
Expand Down
18 changes: 13 additions & 5 deletions lib/samly/sp_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ defmodule Samly.SPHandler do

with {:ok, assertion} <- Helper.decode_idp_auth_resp(sp, saml_encoding, saml_response),
:ok <- validate_authresp(conn, assertion, relay_state),
assertion = %Assertion{assertion | idp_id: idp_id},
assertion = %{assertion | idp_id: idp_id},
conn = conn |> put_private(:samly_assertion, assertion),
{:halted, %Conn{halted: false} = conn} <- {:halted, pipethrough(conn, pipeline)} do
updated_assertion = conn.private[:samly_assertion]
computed = updated_assertion.computed
assertion = %Assertion{assertion | computed: computed, idp_id: idp_id}
assertion = %{assertion | computed: computed, idp_id: idp_id}

nameid = assertion.subject.name
assertion_key = {idp_id, nameid}
Expand All @@ -53,17 +53,25 @@ defmodule Samly.SPHandler do
|> put_session("samly_assertion_key", assertion_key)
|> redirect(302, target_url)
else
{:halted, conn} -> conn
{:halted, conn} ->
conn

{:error, reason} ->
case idp do
%IdpData{debug_mode: true} ->
conn
|> put_resp_header("content-type", "text/html")
|> send_resp(403, "<html><body><div><h1>access_denied</h1><p><b>Error:</b><br /><pre><code>#{inspect(reason)}</code></pre></p><p><b>Raw Response:</b><br /><pre><code>#{saml_response}</code></pre></p></div></body></html")
|> send_resp(
403,
"<html><body><div><h1>access_denied</h1><p><b>Error:</b><br /><pre><code>#{inspect(reason)}</code></pre></p><p><b>Raw Response:</b><br /><pre><code>#{saml_response}</code></pre></p></div></body></html"
)

_ ->
conn |> send_resp(403, "access_denied #{inspect(reason)}")
end
_ -> conn |> send_resp(403, "access_denied")

_ ->
conn |> send_resp(403, "access_denied")
end

# rescue
Expand Down