Skip to content

Commit 28d3fff

Browse files
committed
Add support to retrieve from SAMLResponse the AuthnInstant and AuthnContextClassRef values. See #718
1 parent aa9bf70 commit 28d3fff

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed

CHANGELOG.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Ruby SAML Changelog
22

33
### 2.0.0
4+
* [#718](https://github.com/SAML-Toolkits/ruby-saml/pull/718/) Add support to retrieve from SAMLResponse the AuthnInstant and AuthnContextClassRef values
45
* [#685](https://github.com/SAML-Toolkits/ruby-saml/pull/685) Remove `OneLogin` namespace. The root namespace of the gem is now `RubySaml`.
56
* [#685](https://github.com/SAML-Toolkits/ruby-saml/pull/685) Create namespace alias `OneLogin = Object` for backward compatibility, to be removed in version `2.1.0`.
67
* [#685](https://github.com/SAML-Toolkits/ruby-saml/pull/685) Change directly structure from `lib/onelogin/ruby-saml` to `lib/ruby_saml`.
@@ -28,7 +29,7 @@
2829

2930
### 1.15.0 (Jan 04, 2023)
3031
* [#650](https://github.com/SAML-Toolkits/ruby-saml/pull/650) Replace strip! by strip on compute_digest method
31-
* [#638](https://github.com/SAML-Toolkits/ruby-saml/pull/638) Fix dateTime format for the validUntil attribute of the generated metadata
32+
* [#638](https://github.com/SAML-Toolkits/ruby-saml/pull/638) Fix dateTime format for the validUntil attribute of the generated metadata
3233
* [#576](https://github.com/SAML-Toolkits/ruby-saml/pull/576) Support `Settings#idp_cert_multi` with string keys
3334
* [#567](https://github.com/SAML-Toolkits/ruby-saml/pull/567) Improve Code quality
3435
* Add info about new repo, new maintainer, new security contact
@@ -62,7 +63,7 @@
6263

6364
### 1.12.0 (Feb 18, 2021)
6465
* Support AES-128-GCM, AES-192-GCM, and AES-256-GCM encryptions
65-
* Parse & return SLO ResponseLocation in IDPMetadataParser & Settings
66+
* Parse & return SLO ResponseLocation in IDPMetadataParser & Settings
6667
* Adding idp_sso_service_url and idp_slo_service_url settings
6768
* [#536](https://github.com/SAML-Toolkits/ruby-saml/pull/536) Adding feth method to be able retrieve attributes based on regex
6869
* Reduce size of built gem by excluding the test folder
@@ -192,7 +193,7 @@
192193
* Fix response_test.rb of gem 1.3.0
193194
* Add reference to Security Guidelines
194195
* Update License
195-
* [#334](https://github.com/SAML-Toolkits/ruby-saml/pull/334) Keep API backward-compatibility on IdpMetadataParser fingerprint method.
196+
* [#334](https://github.com/SAML-Toolkits/ruby-saml/pull/334) Keep API backward-compatibility on IdpMetadataParser fingerprint method.
196197

197198
### 1.3.0 (June 24, 2016)
198199
* [Security Fix](https://github.com/SAML-Toolkits/ruby-saml/commit/a571f52171e6bfd87db59822d1d9e8c38fb3b995) Add extra validations to prevent Signature wrapping attacks
@@ -210,7 +211,7 @@
210211
* [#316](https://github.com/SAML-Toolkits/ruby-saml/pull/316) Fix Misspelling of transation_id to transaction_id
211212
* [#321](https://github.com/SAML-Toolkits/ruby-saml/pull/321) Support Attribute Names on IDPSSODescriptor parser
212213
* Changes on empty URI of Signature reference management
213-
* [#320](https://github.com/SAML-Toolkits/ruby-saml/pull/320) Dont mutate document to fix lack of reference URI
214+
* [#320](https://github.com/SAML-Toolkits/ruby-saml/pull/320) Dont mutate document to fix lack of reference URI
214215
* [#306](https://github.com/SAML-Toolkits/ruby-saml/pull/306) Support WantAssertionsSigned
215216

216217
### 1.1.2 (February 15, 2016)
@@ -227,17 +228,17 @@
227228
* [#270](https://github.com/SAML-Toolkits/ruby-saml/pull/270) Allow SAML elements to come from any namespace (at decryption process)
228229
* [#261](https://github.com/SAML-Toolkits/ruby-saml/pull/261) Allow validate_subject_confirmation Response validation to be skipped
229230
* [#258](https://github.com/SAML-Toolkits/ruby-saml/pull/258) Fix allowed_clock_drift on the validate_session_expiration test
230-
* [#256](https://github.com/SAML-Toolkits/ruby-saml/pull/256) Separate the create_authentication_xml_doc in two methods.
231+
* [#256](https://github.com/SAML-Toolkits/ruby-saml/pull/256) Separate the create_authentication_xml_doc in two methods.
231232
* [#255](https://github.com/SAML-Toolkits/ruby-saml/pull/255) Refactor validate signature.
232-
* [#254](https://github.com/SAML-Toolkits/ruby-saml/pull/254) Handle empty URI references
233+
* [#254](https://github.com/SAML-Toolkits/ruby-saml/pull/254) Handle empty URI references
233234
* [#251](https://github.com/SAML-Toolkits/ruby-saml/pull/251) Support qualified and unqualified NameID in attributes
234235
* [#234](https://github.com/SAML-Toolkits/ruby-saml/pull/234) Add explicit support for JRuby
235236

236237
### 1.0.0 (June 30, 2015)
237238
* [#247](https://github.com/SAML-Toolkits/ruby-saml/pull/247) Avoid entity expansion (XEE attacks)
238239
* [#246](https://github.com/SAML-Toolkits/ruby-saml/pull/246) Fix bug generating Logout Response (issuer was at wrong order)
239240
* [#243](https://github.com/SAML-Toolkits/ruby-saml/issues/243) and [#244](https://github.com/SAML-Toolkits/ruby-saml/issues/244) Fix metadata builder errors. Fix metadata xsd.
240-
* [#241](https://github.com/SAML-Toolkits/ruby-saml/pull/241) Add decrypt support (EncryptID and EncryptedAssertion). Improve compatibility with namespaces.
241+
* [#241](https://github.com/SAML-Toolkits/ruby-saml/pull/241) Add decrypt support (EncryptID and EncryptedAssertion). Improve compatibility with namespaces.
241242
* [#240](https://github.com/SAML-Toolkits/ruby-saml/pull/240) and [#238](https://github.com/SAML-Toolkits/ruby-saml/pull/238) Improve test coverage and refactor.
242243
* [#239](https://github.com/SAML-Toolkits/ruby-saml/pull/239) Improve security: Add more validations to SAMLResponse, LogoutRequest and LogoutResponse. Refactor code and improve tests coverage.
243244
* [#237](https://github.com/SAML-Toolkits/ruby-saml/pull/237) Don't pretty print metadata by default.

lib/ruby_saml/response.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,27 @@ def session_expires_at
201201
end
202202
end
203203

204+
# Gets the AuthnInstant from the AuthnStatement.
205+
# Could be used to require re-authentication if a long time has passed
206+
# since the last user authentication.
207+
# @return [String] AuthnInstant value
208+
#
209+
def authn_instant
210+
@authn_instant ||= begin
211+
node = xpath_first_from_signed_assertion('/a:AuthnStatement')
212+
node.nil? ? nil : node.attributes['AuthnInstant']
213+
end
214+
end
215+
216+
# Gets the AuthnContextClassRef from the AuthnStatement
217+
# Could be used to require re-authentication if the assertion
218+
# did not met the requested authentication context class.
219+
# @return [String] AuthnContextClassRef value
220+
#
221+
def authn_context_class_ref
222+
@authn_context_class_ref ||= Utils.element_text(xpath_first_from_signed_assertion('/a:AuthnStatement/a:AuthnContext/a:AuthnContextClassRef'))
223+
end
224+
204225
# Checks if the Status has the "Success" code
205226
# @return [Boolean] True if the StatusCode is Sucess
206227
#

test/response_test.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,27 @@ def generate_audience_error(expected, actual)
13571357
end
13581358
end
13591359

1360+
# Gets the AuthnInstant from the AuthnStatement.
1361+
# Could be used to require re-authentication if a long time has passed
1362+
# since the last user authentication.
1363+
# @return [String] AuthnInstant value
1364+
#
1365+
def authn_instant
1366+
@authn_instant ||= begin
1367+
node = xpath_first_from_signed_assertion('/a:AuthnStatement')
1368+
node.nil? ? nil : node.attributes['AuthnInstant']
1369+
end
1370+
end
1371+
1372+
# Gets the AuthnContextClassRef from the AuthnStatement
1373+
# Could be used to require re-authentication if the assertion
1374+
# did not met the requested authentication context class.
1375+
# @return [String] AuthnContextClassRef value
1376+
#
1377+
def authn_context_class_ref
1378+
@authn_context_class_ref ||= Utils.element_text(xpath_first_from_signed_assertion('/a:AuthnStatement/a:AuthnContext/a:AuthnContextClassRef'))
1379+
end
1380+
13601381
describe "#success" do
13611382
it "find a status code that says success" do
13621383
response.success?

0 commit comments

Comments
 (0)