Skip to content

Commit c8f0e97

Browse files
Merge pull request #243 from gerardo-navarro/gerardo-navarro-remove-changes-unrelated-to-slo_enabled
Add option :slo_enabled to opt-out (diable) from SLO endpoints completely
2 parents f82193a + 1d6a0a5 commit c8f0e97

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ Note that when [integrating with Devise](#devise-integration), the URL path will
103103
instance will be passed to this callable if it has an arity of 1. If the value is a string,
104104
the string will be returned, when the `RelayState` is called. Optional.
105105

106+
* `:slo_enabled` - Enables or disables Single Logout (SLO). Set to `false` to disable SLO. Defaults to `true`. Optional.
107+
106108
* `:idp_sso_service_url_runtime_params` - A dynamic mapping of request params that exist
107109
during the request phase of OmniAuth that should to be sent to the IdP after a specific
108110
mapping. So for example, a param `original_request_param` with value `original_param_value`,
@@ -112,7 +114,7 @@ Note that when [integrating with Devise](#devise-integration), the URL path will
112114
* `:idp_cert` - The identity provider's certificate in PEM format. Takes precedence
113115
over the fingerprint option below. This option or `:idp_cert_multi` or `:idp_cert_fingerprint` must
114116
be present.
115-
117+
116118
* `:idp_cert_multi` - Multiple identity provider certificates in PEM format. Takes precedence
117119
over the fingerprint option below. This option `:idp_cert` or `:idp_cert_fingerprint` must
118120
be present.
@@ -192,7 +194,9 @@ Single Logout can be Service Provider initiated or Identity Provider initiated.
192194
For SP initiated logout, the `idp_slo_service_url` option must be set to the logout url on the IdP,
193195
and users directed to `user_saml_omniauth_authorize_path + '/spslo'` after logging out locally. For
194196
IdP initiated logout, logout requests from the IdP should go to `/auth/saml/slo` (this can be
195-
advertised in metadata by setting the `single_logout_service_url` config option).
197+
advertised in metadata by setting the `single_logout_service_url` config option). If you wish to
198+
disable Single Logout entirely (both SP and IdP initiated), set `:slo_enabled => false`; the `/auth/saml/slo`
199+
and `/auth/saml/spslo` endpoints will then respond with HTTP 501 Not Implemented.
196200

197201
When using Devise as an authentication solution, the SP initiated flow can be integrated
198202
in the `SessionsController#destroy` action.

lib/omniauth/strategies/saml.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def self.inherited(subclass)
2828
last_name: ["last_name", "lastname", "lastName"]
2929
}
3030
option :slo_default_relay_state
31+
option :slo_enabled, true
3132
option :uid_attribute
3233
option :idp_slo_session_destroy, proc { |_env, session| session.clear }
3334

@@ -73,8 +74,12 @@ def other_phase
7374
if on_subpath?(:metadata)
7475
other_phase_for_metadata
7576
elsif on_subpath?(:slo)
77+
return slo_disabled_response unless slo_enabled?
78+
7679
other_phase_for_slo
7780
elsif on_subpath?(:spslo)
81+
return slo_disabled_response unless slo_enabled?
82+
7883
other_phase_for_spslo
7984
else
8085
call_app!
@@ -259,6 +264,14 @@ def other_phase_for_spslo
259264
end
260265
end
261266

267+
def slo_enabled?
268+
!!options[:slo_enabled]
269+
end
270+
271+
def slo_disabled_response
272+
Rack::Response.new("Not Implemented", 501, { "Content-Type" => "text/html" }).finish
273+
end
274+
262275
def add_request_attributes_to(settings)
263276
settings.attribute_consuming_service.service_name options.attribute_service_name
264277
settings.sp_entity_id = options.sp_entity_id

spec/omniauth/strategies/saml_spec.rb

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ def post_xml(xml = :example_response, opts = {})
268268
expect(last_request.env['omniauth.error'].message).to eq("SAML response missing 'missing_attribute' attribute")
269269
end
270270
end
271-
272271
end
273272

274273
describe 'POST /auth/saml/slo' do
@@ -333,6 +332,18 @@ def post_xml(xml = :example_response, opts = {})
333332
end
334333
end
335334
end
335+
336+
context "when SLO is disabled" do
337+
before do
338+
saml_options[:slo_enabled] = false
339+
post "/auth/saml/slo"
340+
end
341+
342+
it "should return not implemented" do
343+
expect(last_response.status).to eq 501
344+
expect(last_response.body).to eq "Not Implemented"
345+
end
346+
end
336347
end
337348

338349
describe 'POST /auth/saml/spslo' do
@@ -368,6 +379,18 @@ def test_default_relay_state(static_default_relay_state = nil, &block_default_re
368379
expect(last_response.status).to eq 501
369380
expect(last_response.body).to match /Not Implemented/
370381
end
382+
383+
context "when SLO is disabled" do
384+
before do
385+
saml_options[:slo_enabled] = false
386+
post "/auth/saml/spslo"
387+
end
388+
389+
it "should return not implemented" do
390+
expect(last_response.status).to eq 501
391+
expect(last_response.body).to eq "Not Implemented"
392+
end
393+
end
371394
end
372395

373396
describe 'POST /auth/saml/metadata' do

0 commit comments

Comments
 (0)