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
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.2
2.6
20 changes: 15 additions & 5 deletions lib/rack-cas/saml_validation_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(url, ticket)

def user
if success?
xml.at('//Response/Assertion/AuthenticationStatement/Subject/NameIdentifier').text
xml_text_at('//Response/Assertion/AuthenticationStatement/Subject/NameIdentifier')
else
raise AuthenticationFailure, failure_message
end
Expand All @@ -26,11 +26,14 @@ def extra_attributes

raise AuthenticationFailure, failure_message unless success?

xml.at('//Response/Assertion/AttributeStatement').children.each do |node|
attribute_statement = xml.at('//Response/Assertion/AttributeStatement')
return unless attribute_statement

attribute_statement.children.each do |node|
key = node.at('@AttributeName')

if key
values = node.xpath('AttributeValue').map { |n| n.text }
values = node.xpath('AttributeValue').map(&:text)

values = values.first if values.size == 1

Expand All @@ -44,7 +47,7 @@ def extra_attributes
protected

def success?
@success ||= xml.at('//Response/Status/StatusCode/@Value').text =~ /saml1?p:Success/
@success ||= xml_text_at('//Response/Status/StatusCode/@Value') =~ /saml1?p:Success/
end

def authentication_failure
Expand All @@ -53,7 +56,7 @@ def authentication_failure

def failure_message
if authentication_failure
xml.at('//Response/Status/StatusMessage').text.strip
xml_text_at('//Response/Status/StatusMessage').strip
end
end

Expand Down Expand Up @@ -96,6 +99,13 @@ def xml
@xml = Nokogiri::XML(response.body).remove_namespaces!
end

def xml_text_at(path)
element = xml.at(path)
return unless element

element.text
end

def ip_address
require 'socket'

Expand Down