Class: SAML2::AuthnRequest

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ AuthnRequest

Returns a new instance of AuthnRequest.



28
29
30
# File 'lib/saml2/authn_request.rb', line 28

def initialize(document)
  @document = document
end

Instance Attribute Details

#assertion_consumer_serviceObject (readonly)

Returns the value of attribute assertion_consumer_service.



86
87
88
# File 'lib/saml2/authn_request.rb', line 86

def assertion_consumer_service
  @assertion_consumer_service
end

#attribute_consuming_serviceObject (readonly)

Returns the value of attribute attribute_consuming_service.



86
87
88
# File 'lib/saml2/authn_request.rb', line 86

def attribute_consuming_service
  @attribute_consuming_service
end

Class Method Details

.decode(authnrequest) ⇒ Object



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

def self.decode(authnrequest)
  begin
    zstream  = Zlib::Inflate.new(-Zlib::MAX_WBITS)
    authnrequest = zstream.inflate(Base64.decode64(authnrequest))
    zstream.finish
    zstream.close
  rescue Zlib::BufError
  end
  parse(authnrequest)
end

.parse(authnrequest) ⇒ Object



24
25
26
# File 'lib/saml2/authn_request.rb', line 24

def self.parse(authnrequest)
  new(Nokogiri::XML(authnrequest))
end

Instance Method Details

#assertion_consumer_service_indexObject



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

def assertion_consumer_service_index
  @document.root['AssertionConsumerServiceIndex'] && @document.root['AssertionConsumerServiceIndex'].to_i
end

#assertion_consumer_service_urlObject



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

def assertion_consumer_service_url
  @document.root['AssertionConsumerServiceURL']
end

#attribute_consuming_service_indexObject



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

def attribute_consuming_service_index
  @document.root['AttributeConsumerServiceIndex'] && @document.root['AttributeConsumerServiceIndex'].to_i
end

#force_authn?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/saml2/authn_request.rb', line 100

def force_authn?
  @document.root['ForceAuthn']
end

#idObject



82
83
84
# File 'lib/saml2/authn_request.rb', line 82

def id
  @document.root['ID']
end

#issuerObject



74
75
76
# File 'lib/saml2/authn_request.rb', line 74

def issuer
  @issuer ||= NameID.from_xml(@document.root.at_xpath('saml:Issuer', Namespaces::ALL))
end

#name_id_policyObject



78
79
80
# File 'lib/saml2/authn_request.rb', line 78

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

#passive?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/saml2/authn_request.rb', line 104

def passive?
  @document.root['IsPassive']
end

#protocol_bindingObject



108
109
110
# File 'lib/saml2/authn_request.rb', line 108

def protocol_binding
  @document.root['ProtocolBinding']
end

#resolve(service_provider) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/saml2/authn_request.rb', line 58

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



112
113
114
# File 'lib/saml2/authn_request.rb', line 112

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

#valid_interoperable_profile?Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
55
56
# File 'lib/saml2/authn_request.rb', line 47

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)


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

def valid_schema?
  return false unless Schemas.protocol.valid?(@document)
  # Check for the correct root element
  return false unless @document.at_xpath('/samlp:AuthnRequest', Namespaces::ALL)

  true
end

#valid_web_browser_sso_profile?Boolean

Returns:

  • (Boolean)


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

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

  true
end