ruby-saml-mod 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9b8339af98b853334c4cd343eff1454a9ed537a
4
- data.tar.gz: 7702ec985b556013a1d812f646e415ec16cfe58f
3
+ metadata.gz: 70a7eb538a2bbed9d2269ccf27a1ae560a40734c
4
+ data.tar.gz: dca9f7dd1a7e5e7d3a7e8967af606b3688144c09
5
5
  SHA512:
6
- metadata.gz: 1e1accc268ecc2fad5023f99552d8c2a53cca7ddd548092236534bcb0d6016ec51a40d0960b8706afceacd9fe5ecfeb204751985f0b15c90e78e1bbaeeb5cade
7
- data.tar.gz: 868e76914f77d9766ebc31449b9262c28dd689a4ea815ed23c6269ada3a0e4422ec2941e73c87bfd3e9d53671ee0e5c0c1f6b58ab2151ba969cee116a3599f7d
6
+ metadata.gz: 1be665813508c314582bebac318758085c74ca7fd3621c58e6df191df83639981eb48fa3b3d6cbad8047765962abddd6fb920a8b8d0f9062d2075293f1ba8d87
7
+ data.tar.gz: a9d34492f6c2e8feb08a1bccccb2a53545c88ef336bc1cfb8345fff663ccbee7857bc338970d233877a8b295b44d03779b5f5cadcdeaa2655b5af57acb24e134
@@ -1,47 +1,53 @@
1
- module Onelogin::Saml
2
- class AuthRequest < BaseAssertion
3
- attr_accessor :requested_authn_context,
4
- :assertion_consumer_service_url,
5
- :name_identifier_format
6
-
7
- def self.parse(raw_assertion, settings = nil)
8
- raise NotImplementedError
1
+ module Onelogin::Saml
2
+ class AuthRequest
3
+
4
+ attr_reader :settings, :id, :request_xml, :forward_url
5
+
6
+ def initialize(settings)
7
+ @settings = settings
9
8
  end
10
-
11
- def self.generate(settings)
12
- super(settings, {
13
- destination: settings.idp_sso_target_url,
14
- requested_authn_context: settings.requested_authn_context,
15
- assertion_consumer_service_url: Array(settings.assertion_consumer_service_url).first,
16
- name_identifier_format: settings.name_identifier_format
17
- })
9
+
10
+ def self.create(settings)
11
+ ar = AuthRequest.new(settings)
12
+ ar.generate_request
18
13
  end
14
+
15
+ def generate_request
16
+ @id = Onelogin::Saml::AuthRequest.generate_unique_id(42)
17
+ issue_instant = Onelogin::Saml::AuthRequest.get_timestamp
19
18
 
20
- def generate
21
- if self.requested_authn_context
22
- xml = <<-XML
23
- <samlp:RequestedAuthnContext Comparison="exact">
24
- <saml:AuthnContextClassRef>#{self.requested_authn_context}</saml:AuthnContextClassRef>
25
- </samlp:RequestedAuthnContext>
26
- XML
19
+ @request_xml =
20
+ "<samlp:AuthnRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" ID=\"#{@id}\" Version=\"2.0\" IssueInstant=\"#{issue_instant}\" ProtocolBinding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST\" AssertionConsumerServiceURL=\"#{Array(settings.assertion_consumer_service_url).first}\">" +
21
+ "<saml:Issuer xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\">#{@settings.issuer}</saml:Issuer>\n" +
22
+ "<samlp:NameIDPolicy xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" Format=\"#{@settings.name_identifier_format}\" AllowCreate=\"true\"></samlp:NameIDPolicy>\n"
23
+
24
+ if @settings.requested_authn_context
25
+ @request_xml += "<samlp:RequestedAuthnContext xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" Comparison=\"exact\">"
26
+ @request_xml += "<saml:AuthnContextClassRef xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\">#{@settings.requested_authn_context}</saml:AuthnContextClassRef>"
27
+ @request_xml += "</samlp:RequestedAuthnContext>\n"
27
28
  end
29
+
30
+ @request_xml += "</samlp:AuthnRequest>"
28
31
 
29
- <<-XML
30
- <samlp:AuthnRequest
31
- xmlns:samlp="#{Onelogin::NAMESPACES['samlp']}"
32
- xmlns:saml="#{Onelogin::NAMESPACES['saml']}"
33
- ID="#{self.id}"
34
- Version="2.0"
35
- ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
36
- AssertionConsumerServiceURL=\"#{self.assertion_consumer_service_url}\"
37
- IssueInstant="#{self.issue_instant}">
38
-
39
- <saml:Issuer>#{self.issuer}</saml:Issuer>
40
- <samlp:NameIDPolicy Format="#{self.name_identifier_format}" AllowCreate="true"></samlp:NameIDPolicy>
32
+ deflated_request = Zlib::Deflate.deflate(@request_xml, 9)[2..-5]
33
+ base64_request = Base64.strict_encode64(deflated_request)
34
+ encoded_request = CGI.escape(base64_request)
41
35
 
42
- #{xml}
43
- </samlp:AuthnRequest>
44
- XML
36
+ @forward_url = @settings.idp_sso_target_url + (@settings.idp_sso_target_url.include?("?") ? "&" : "?") + "SAMLRequest=" + encoded_request
37
+ end
38
+
39
+ private
40
+
41
+ def self.generate_unique_id(length)
42
+ chars = ("a".."f").to_a + ("0".."9").to_a
43
+ chars_len = chars.size
44
+ unique_id = ("a".."f").to_a[rand(6)]
45
+ 2.upto(length) { |i| unique_id << chars[rand(chars_len)] }
46
+ unique_id
47
+ end
48
+
49
+ def self.get_timestamp
50
+ Time.new.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
45
51
  end
46
52
  end
47
53
  end
@@ -164,9 +164,9 @@ describe Onelogin::Saml::Response do
164
164
  :idp_slo_target_url => "http://example.com/logout.php"
165
165
  )
166
166
 
167
- request = Onelogin::Saml::AuthRequest::generate(settings)
167
+ forward_url = Onelogin::Saml::AuthRequest::create(settings)
168
168
  prefix = "http://example.com/login.php?SAMLRequest="
169
- expect(request.forward_url[0...prefix.size]).to eql(prefix)
169
+ expect(forward_url[0...prefix.size]).to eql(prefix)
170
170
 
171
171
  request = Onelogin::Saml::LogoutRequest::generate(name_qualifier, name_id, session_index, settings)
172
172
  prefix = "http://example.com/logout.php?SAMLRequest="
@@ -181,9 +181,9 @@ describe Onelogin::Saml::Response do
181
181
  :idp_slo_target_url => "http://example.com/logout.php?param=foo"
182
182
  )
183
183
 
184
- request = Onelogin::Saml::AuthRequest::generate(settings)
184
+ forward_url = Onelogin::Saml::AuthRequest::create(settings)
185
185
  prefix = "http://example.com/login.php?param=foo&SAMLRequest="
186
- expect(request.forward_url[0...prefix.size]).to eql(prefix)
186
+ expect(forward_url[0...prefix.size]).to eql(prefix)
187
187
 
188
188
  request = Onelogin::Saml::LogoutRequest::generate(name_qualifier, name_id, session_index, settings)
189
189
  prefix = "http://example.com/logout.php?param=foo&SAMLRequest="
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-saml-mod
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - OneLogin LLC
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2014-10-31 00:00:00.000000000 Z
17
+ date: 2014-11-06 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: libxml-ruby