Class: SAML2::AuthnRequest

Inherits:
Request show all
Defined in:
lib/saml2/authn_request.rb

Instance Attribute Summary collapse

Attributes inherited from Message

#destination, #id, #issue_instant, #issuer

Attributes inherited from Base

#xml

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Message

#from_xml, from_xml, inherited, #initialize, parse

Methods inherited from Base

from_xml, #from_xml, load_object_array, load_string_array, lookup_qname, #to_s, #to_xml

Constructor Details

This class inherits a constructor from SAML2::Message

Instance Attribute Details

#assertion_consumer_serviceObject (readonly)

Returns the value of attribute assertion_consumer_service.



70
71
72
# File 'lib/saml2/authn_request.rb', line 70

def assertion_consumer_service
  @assertion_consumer_service
end

#attribute_consuming_serviceObject (readonly)

Returns the value of attribute attribute_consuming_service.



70
71
72
# File 'lib/saml2/authn_request.rb', line 70

def attribute_consuming_service
  @attribute_consuming_service
end

Class Method Details

.decode(authnrequest) ⇒ Object

deprecated; takes just the SAMLRequest parameter’s value



16
17
18
19
20
21
22
# File 'lib/saml2/authn_request.rb', line 16

def self.decode(authnrequest)
  result, _relay_state = Bindings::HTTPRedirect.decode("http://host/?SAMLRequest=#{authnrequest}")
  return nil unless result.is_a?(AuthnRequest)
  result
rescue CorruptMessage
  AuthnRequest.from_xml(Nokogiri::XML('<xml></xml>').root)
end

Instance Method Details

#assertion_consumer_service_indexObject



76
77
78
# File 'lib/saml2/authn_request.rb', line 76

def assertion_consumer_service_index
  xml['AssertionConsumerServiceIndex'] && xml['AssertionConsumerServiceIndex'].to_i
end

#assertion_consumer_service_urlObject



72
73
74
# File 'lib/saml2/authn_request.rb', line 72

def assertion_consumer_service_url
  xml['AssertionConsumerServiceURL']
end

#attribute_consuming_service_indexObject



80
81
82
# File 'lib/saml2/authn_request.rb', line 80

def attribute_consuming_service_index
  xml['AttributeConsumerServiceIndex'] && xml['AttributeConsumerServiceIndex'].to_i
end

#force_authn?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/saml2/authn_request.rb', line 84

def force_authn?
  xml['ForceAuthn']
end

#name_id_policyObject



66
67
68
# File 'lib/saml2/authn_request.rb', line 66

def name_id_policy
  @name_id_policy ||= NameID::Policy.from_xml(xml.at_xpath('samlp:NameIDPolicy', Namespaces::ALL))
end

#passive?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/saml2/authn_request.rb', line 88

def passive?
  xml['IsPassive']
end

#protocol_bindingObject



92
93
94
# File 'lib/saml2/authn_request.rb', line 92

def protocol_binding
  xml['ProtocolBinding']
end

#resolve(service_provider) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/saml2/authn_request.rb', line 50

def resolve(service_provider)
  # TODO: check signature if present

  if assertion_consumer_service_url
    @assertion_consumer_service = service_provider.assertion_consumer_services.find { |acs| acs.location == assertion_consumer_service_url }
  else
    @assertion_consumer_service  = service_provider.assertion_consumer_services.resolve(assertion_consumer_service_index)
  end
  @attribute_consuming_service = service_provider.attribute_consuming_services.resolve(attribute_consuming_service_index)

  return false unless @assertion_consumer_service
  return false if attribute_consuming_service_index && !@attribute_consuming_service

  true
end

#subjectObject



96
97
98
# File 'lib/saml2/authn_request.rb', line 96

def subject
  @subject ||= Subject.from_xml(xml.at_xpath('saml:Subject', Namespaces::ALL))
end

#valid_interoperable_profile?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
47
48
# File 'lib/saml2/authn_request.rb', line 39

def valid_interoperable_profile?
  # It's a subset of Web Browser SSO profile
  return false unless valid_web_browser_sso_profile?

  return false unless assertion_consumer_service_url
  return false if protocol_binding && protocol_binding != Endpoint::Bindings::HTTP_POST
  return false if subject

  true
end

#valid_schema?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
# File 'lib/saml2/authn_request.rb', line 24

def valid_schema?
  return false unless super
  # Check for the correct root element
  return false unless xml.at_xpath('/samlp:AuthnRequest', Namespaces::ALL)

  true
end

#valid_web_browser_sso_profile?Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
# File 'lib/saml2/authn_request.rb', line 32

def valid_web_browser_sso_profile?
  return false unless issuer
  return false if issuer.format && issuer.format != NameID::Format::ENTITY

  true
end