spid 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1abf8d3050f0829891601311959388cab3234dc5d75edd59e6dd19bc7de26c7f
4
- data.tar.gz: c4668cb869d0ffc65438aa4a30ee70fcf2611c7c4b07274791d0683acf215471
3
+ metadata.gz: a69cfce2f0a7c237e36061186e9dfda86bdecc85c91163105518b4daebc6cc5c
4
+ data.tar.gz: 31aba1da1bab837c92fe3245754f1b6cb158dfb860ead66384dcf915a1fb5e4f
5
5
  SHA512:
6
- metadata.gz: f3b6676b2941c3eba7cb55f80e0a04310467a244a8c52bae620dd3c2fbcad63ab4933fb1948f80f6b6ade12502125fbddf6ff0105c2f31fec04521c0dfd1cf70
7
- data.tar.gz: 52981e148719b87079cb6e6aba5cf583552b92306a8e9c4b10673fd699214cbaaa1967adf6c1241efa2cba6e75ec58ad8d94018b7ef434da2f151218ee37c79e
6
+ metadata.gz: bac0ea1030e71bef7980e019b54bce8ee9dee96aa324cc2001be28b9cbf01676b699311fb412527633dedf3c3b28ef20b7c13da6aee32b43faae53d0c3f9415c
7
+ data.tar.gz: 8b4ddc12d9566e40f9622dba9d276ea413e0fb1e7bd2c715e2b0aed0d7f593327c83e27413748400c42d9d2b273049d6e341cb67d752e9ea9bc7a9428808aa92
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.15.0] - 2018-08-31
6
+ ### Fixed
7
+ - [IDP-Initiated SLO was not full implemented](https://github.com/italia/spid-ruby/issues/54)
8
+
5
9
  ## [0.14.0] - 2018-08-30
6
10
  ### Added
7
11
  - IDP-Initiated SLO management
data/README.md CHANGED
@@ -72,14 +72,14 @@ gem "spid"
72
72
  |verification of `Destination`|✓|
73
73
  |PartialLogout detection||
74
74
  |**LogoutRequest parsing (for third-party-initiated logout):**||
75
- |parsing of LogoutRequest XML||
75
+ |parsing of LogoutRequest XML|✓|
76
76
  |verification of `Response/Signature` value (if any)||
77
77
  |verification of `Response/Signature` certificate (if any) against IdP metadata||
78
- |verification of `Issuer`||
79
- |verification of `Destination`||
80
- |parsing of `NameID`||
78
+ |verification of `Issuer`|✓|
79
+ |verification of `Destination`|✓|
80
+ |parsing of `NameID`|✓|
81
81
  |**LogoutResponse generation (for third-party-initiated logout):**||
82
- |generation of LogoutResponse XML||
82
+ |generation of LogoutResponse XML|✓|
83
83
  |HTTP-Redirect binding||
84
84
  |HTTP-POST binding||
85
85
  |PartialLogout customization||
@@ -30,7 +30,7 @@ module Spid
30
30
  end
31
31
 
32
32
  def response
33
- session["sso_request_uuid"] = sso_request.uuid
33
+ session["sso_request_uuid"] = responser.uuid
34
34
  [
35
35
  302,
36
36
  { "Location" => sso_url },
@@ -39,11 +39,11 @@ module Spid
39
39
  end
40
40
 
41
41
  def sso_url
42
- sso_request.url
42
+ responser.url
43
43
  end
44
44
 
45
- def sso_request
46
- @sso_request ||=
45
+ def responser
46
+ @responser ||=
47
47
  begin
48
48
  Spid::Sso::Request.new(
49
49
  idp_name: idp_name,
@@ -26,7 +26,7 @@ module Spid
26
26
  end
27
27
 
28
28
  def response
29
- session["slo_request_uuid"] = slo_request.uuid
29
+ session["slo_request_uuid"] = responser.uuid
30
30
  [
31
31
  302,
32
32
  { "Location" => slo_url },
@@ -39,11 +39,11 @@ module Spid
39
39
  end
40
40
 
41
41
  def slo_url
42
- slo_request.url
42
+ responser.url
43
43
  end
44
44
 
45
- def slo_request
46
- @slo_request ||=
45
+ def responser
46
+ @responser ||=
47
47
  begin
48
48
  Spid::Slo::Request.new(
49
49
  idp_name: idp_name,
data/lib/spid/rack/slo.rb CHANGED
@@ -35,22 +35,35 @@ module Spid
35
35
  end
36
36
 
37
37
  def store_session_failure
38
- session["errors"] = slo_response.errors
38
+ session["errors"] = responser.errors
39
39
  end
40
40
 
41
- def response
42
- if valid_response?
43
- clear_session
44
- else
45
- store_session_failure
46
- end
41
+ def response_sp_initiated
47
42
  [
48
43
  302,
49
44
  { "Location" => relay_state },
50
- []
45
+ responser.response
46
+ ]
47
+ end
48
+
49
+ def response_idp_initiated
50
+ [
51
+ 200,
52
+ {},
53
+ responser.response
51
54
  ]
52
55
  end
53
56
 
57
+ def validate_session
58
+ valid_response? ? clear_session : store_session_failure
59
+ end
60
+
61
+ def response
62
+ validate_session
63
+ return response_idp_initiated if idp_initiated?
64
+ response_sp_initiated
65
+ end
66
+
54
67
  def relay_state
55
68
  if !request.params["RelayState"].nil? &&
56
69
  request.params["RelayState"] != ""
@@ -79,7 +92,7 @@ module Spid
79
92
  end
80
93
 
81
94
  def valid_response?
82
- slo_response.valid?
95
+ responser.valid?
83
96
  end
84
97
 
85
98
  def valid_request?
@@ -90,8 +103,36 @@ module Spid
90
103
  request.params["SAMLResponse"]
91
104
  end
92
105
 
93
- def slo_response
94
- @slo_response ||= ::Spid::Slo::Response.new(
106
+ def saml_request
107
+ request.params["SAMLRequest"]
108
+ end
109
+
110
+ def idp_initiated?
111
+ !saml_request.nil?
112
+ end
113
+
114
+ def responser
115
+ @responser ||=
116
+ begin
117
+ if idp_initiated?
118
+ idp_initiated_slo_request
119
+ else
120
+ sp_initiated_slo_response
121
+ end
122
+ end
123
+ end
124
+
125
+ private
126
+
127
+ def idp_initiated_slo_request
128
+ ::Spid::Slo::IdpRequest.new(
129
+ body: saml_request,
130
+ session_index: session["session_index"]
131
+ )
132
+ end
133
+
134
+ def sp_initiated_slo_response
135
+ ::Spid::Slo::Response.new(
95
136
  body: saml_response,
96
137
  request_uuid: session["slo_request_uuid"],
97
138
  session_index: session["session_index"]
data/lib/spid/rack/sso.rb CHANGED
@@ -31,13 +31,13 @@ module Spid
31
31
  end
32
32
 
33
33
  def store_session_success
34
- session["attributes"] = sso_response.attributes
35
- session["session_index"] = sso_response.session_index
34
+ session["attributes"] = responser.attributes
35
+ session["session_index"] = responser.session_index
36
36
  session.delete("sso_request_uuid")
37
37
  end
38
38
 
39
39
  def store_session_failure
40
- session["errors"] = sso_response.errors
40
+ session["errors"] = responser.errors
41
41
  end
42
42
 
43
43
  def response
@@ -85,15 +85,15 @@ module Spid
85
85
  end
86
86
 
87
87
  def valid_response?
88
- sso_response.valid?
88
+ responser.valid?
89
89
  end
90
90
 
91
91
  def valid_request?
92
92
  valid_path? && valid_http_verb?
93
93
  end
94
94
 
95
- def sso_response
96
- @sso_response ||= ::Spid::Sso::Response.new(
95
+ def responser
96
+ @responser ||= ::Spid::Sso::Response.new(
97
97
  body: saml_response,
98
98
  request_uuid: session["sso_request_uuid"]
99
99
  )
data/lib/spid/saml2.rb CHANGED
@@ -14,6 +14,7 @@ require "spid/saml2/utils"
14
14
  require "spid/saml2/idp_metadata_parser"
15
15
  require "spid/saml2/response_validator"
16
16
  require "spid/saml2/logout_response_validator"
17
+ require "spid/saml2/idp_logout_request_validator"
17
18
 
18
19
  module Spid
19
20
  module Saml2 # :nodoc:
@@ -29,6 +29,10 @@ module Spid
29
29
  ]&.value
30
30
  end
31
31
 
32
+ def name_id
33
+ document.elements["/samlp:LogoutRequest/saml:NameID/text()"]&.value
34
+ end
35
+
32
36
  def name_id_name_qualifier
33
37
  document.elements[
34
38
  "/samlp:LogoutRequest/saml:NameID/@NameQualifier"
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spid
4
+ module Saml2
5
+ class IdpLogoutRequestValidator # :nodoc:
6
+ attr_reader :request
7
+
8
+ def initialize(request:)
9
+ @request = request
10
+ end
11
+
12
+ def call
13
+ true
14
+ end
15
+ end
16
+ end
17
+ end
data/lib/spid/slo.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "spid/slo/request"
4
4
  require "spid/slo/response"
5
+ require "spid/slo/idp_request"
5
6
 
6
7
  module Spid
7
8
  module Slo # :nodoc:
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spid
4
+ module Slo
5
+ class IdpRequest # :nodoc:
6
+ include Spid::Saml2::Utils
7
+
8
+ attr_reader :body
9
+ attr_reader :saml_message
10
+ attr_reader :session_index
11
+
12
+ def initialize(body:, session_index:)
13
+ @body = body
14
+ @saml_message = decode_and_inflate(body)
15
+ @session_index = session_index
16
+ end
17
+
18
+ def response
19
+ [
20
+ idp_logout_response.to_saml
21
+ ]
22
+ end
23
+
24
+ def valid?
25
+ validator.call
26
+ end
27
+
28
+ def identity_provider
29
+ @identity_provider ||=
30
+ IdentityProviderManager.find_by_entity(issuer)
31
+ end
32
+
33
+ def service_provider
34
+ @service_provider ||=
35
+ Spid.configuration.service_provider
36
+ end
37
+
38
+ def issuer
39
+ idp_logout_request.issuer
40
+ end
41
+
42
+ def settings
43
+ @settings ||= Spid::Saml2::Settings.new(
44
+ service_provider: service_provider,
45
+ identity_provider: identity_provider
46
+ )
47
+ end
48
+
49
+ def validator
50
+ @validator ||=
51
+ begin
52
+ Spid::Saml2::IdpLogoutRequestValidator.new(
53
+ request: idp_logout_request
54
+ )
55
+ end
56
+ end
57
+
58
+ def idp_logout_request
59
+ @idp_logout_request ||=
60
+ begin
61
+ Spid::Saml2::IdpLogoutRequest.new(
62
+ saml_message: saml_message
63
+ )
64
+ end
65
+ end
66
+
67
+ def idp_logout_response
68
+ @idp_logout_response ||=
69
+ begin
70
+ Spid::Saml2::IdpLogoutResponse.new(
71
+ settings: settings,
72
+ request_uuid: idp_logout_request.id
73
+ )
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -17,6 +17,10 @@ module Spid
17
17
  validator.call
18
18
  end
19
19
 
20
+ def response
21
+ []
22
+ end
23
+
20
24
  def errors
21
25
  validator.errors
22
26
  end
data/lib/spid/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spid
4
- VERSION = "0.14.0"
4
+ VERSION = "0.15.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Librera
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-30 00:00:00.000000000 Z
11
+ date: 2018-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -325,6 +325,7 @@ files:
325
325
  - lib/spid/saml2/authn_request.rb
326
326
  - lib/spid/saml2/identity_provider.rb
327
327
  - lib/spid/saml2/idp_logout_request.rb
328
+ - lib/spid/saml2/idp_logout_request_validator.rb
328
329
  - lib/spid/saml2/idp_logout_response.rb
329
330
  - lib/spid/saml2/idp_metadata_parser.rb
330
331
  - lib/spid/saml2/logout_request.rb
@@ -338,6 +339,7 @@ files:
338
339
  - lib/spid/saml2/utils.rb
339
340
  - lib/spid/saml2/utils/query_params_signer.rb
340
341
  - lib/spid/slo.rb
342
+ - lib/spid/slo/idp_request.rb
341
343
  - lib/spid/slo/request.rb
342
344
  - lib/spid/slo/response.rb
343
345
  - lib/spid/sso.rb