Skip to content

Commit 16de4a0

Browse files
authored
Merge branch 'master' into add-session-expiration
2 parents 8b19aa0 + 83c8d66 commit 16de4a0

14 files changed

+14
-33
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
before_install:
22
- gem install bundler
33
rvm:
4-
- 1.9.3
5-
- 2.0.0
64
- 2.1.0
75
- 2.2.0
86
- 2.3.0

MIT-LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2012 Lawrence Pit (http://lawrencepit.com)
1+
Copyright (c) 2012 Lawrence Pit (https://github.com/lawrencepit/ruby-saml-idp)
22

33
Permission is hereby granted, free of charge, to any person obtaining
44
a copy of this software and associated documentation files (the

README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Ruby SAML Identity Provider (IdP)
22

33
[![Build Status](https://secure.travis-ci.org/lawrencepit/ruby-saml-idp.png)](http://travis-ci.org/lawrencepit/ruby-saml-idp?branch=master)
4-
[![Code Climate](https://codeclimate.com/github/lawrencepit/ruby-saml-idp/badges/gpa.svg)](https://codeclimate.com/github/lawrencepit/ruby-saml-idp)
54
[![Gem Version](https://fury-badge.herokuapp.com/rb/ruby-saml-idp.png)](http://badge.fury.io/rb/ruby-saml-idp)
65

76
The ruby SAML Identity Provider library is for implementing the server side of SAML authentication. It allows your application to act as an IdP (Identity Provider) using the [SAML v2.0](http://en.wikipedia.org/wiki/Security_Assertion_Markup_Language) protocol. It provides a means for managing authentication requests and confirmation responses for SPs (Service Providers).
@@ -94,12 +93,6 @@ Service Providers
9493
To act as a Service Provider which generates SAML Requests and can react to SAML Responses use the excellent [ruby-saml](https://github.com/onelogin/ruby-saml) gem.
9594

9695

97-
Author
98-
----------
99-
100-
Lawrence Pit, [email protected], [lawrencepit.com](http://lawrencepit.com), [@lawrencepit](http://twitter.com/lawrencepit)
101-
102-
10396
Copyright
10497
-----------
10598

app/controllers/saml_idp/idp_controller.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# encoding: utf-8
21
module SamlIdp
32
class IdpController < ActionController::Base
43
include SamlIdp::Controller

lib/ruby-saml-idp.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# encoding: utf-8
21
module SamlIdp
32
require 'saml_idp/configurator'
43
require 'saml_idp/controller'

lib/saml_idp/configurator.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# encoding: utf-8
21
module SamlIdp
32
class Configurator
43
attr_accessor :x509_certificate, :secret_key, :algorithm, :expires_in

lib/saml_idp/controller.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# encoding: utf-8
2-
31
module SamlIdp
42
module Controller
53
require 'openssl'
@@ -51,7 +49,7 @@ def expires_in
5149
protected
5250

5351
def validate_saml_request(saml_request = params[:SAMLRequest])
54-
decode_SAMLRequest(saml_request)
52+
decode_SAMLRequest(saml_request) rescue false
5553
end
5654

5755
def decode_SAMLRequest(saml_request)
@@ -75,7 +73,7 @@ def encode_SAMLResponse(nameID, opts = {})
7573
session_expiration = %{ SessionNotOnOrAfter="#{(now + expires_in).iso8601}"}
7674
end
7775

78-
assertion = %[<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_#{reference_id}" IssueInstant="#{now.iso8601}" Version="2.0"><saml:Issuer Format="urn:oasis:names:SAML:2.0:nameid-format:entity">#{issuer_uri}</saml:Issuer><saml:Subject><saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">#{nameID}</saml:NameID><saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"><saml:SubjectConfirmationData InResponseTo="#{@saml_request_id}" NotOnOrAfter="#{(now+3*60).iso8601}" Recipient="#{@saml_acs_url}"></saml:SubjectConfirmationData></saml:SubjectConfirmation></saml:Subject><saml:Conditions NotBefore="#{(now-5).iso8601}" NotOnOrAfter="#{(now+60*60).iso8601}"><saml:AudienceRestriction><saml:Audience>#{audience_uri}</saml:Audience></saml:AudienceRestriction></saml:Conditions>#{attributes_statement}<saml:AuthnStatement AuthnInstant="#{now.iso8601}" SessionIndex="_#{reference_id}"#{session_expiration}><saml:AuthnContext><saml:AuthnContextClassRef>urn:federation:authentication:windows</saml:AuthnContextClassRef></saml:AuthnContext></saml:AuthnStatement></saml:Assertion>]
76+
assertion = %[<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_#{reference_id}" IssueInstant="#{now.iso8601}" Version="2.0"><saml:Issuer Format="urn:oasis:names:SAML:2.0:nameid-format:entity">#{issuer_uri}</saml:Issuer><saml:Subject><saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">#{nameID}</saml:NameID><saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"><saml:SubjectConfirmationData#{@saml_request_id.present? ? %[ InResponseTo="#{@saml_request_id}"] : ""} NotOnOrAfter="#{(now+3*60).iso8601}" Recipient="#{@saml_acs_url}"></saml:SubjectConfirmationData></saml:SubjectConfirmation></saml:Subject><saml:Conditions NotBefore="#{(now-5).iso8601}" NotOnOrAfter="#{(now+60*60).iso8601}"><saml:AudienceRestriction><saml:Audience>#{audience_uri}</saml:Audience></saml:AudienceRestriction></saml:Conditions>#{attributes_statement}<saml:AuthnStatement AuthnInstant="#{now.iso8601}" SessionIndex="_#{reference_id}"#{session_expiration}><saml:AuthnContext><saml:AuthnContextClassRef>urn:federation:authentication:windows</saml:AuthnContextClassRef></saml:AuthnContext></saml:AuthnStatement></saml:Assertion>]
7977

8078
digest_value = Base64.encode64(algorithm.digest(assertion)).gsub(/\n/, '')
8179

@@ -87,7 +85,7 @@ def encode_SAMLResponse(nameID, opts = {})
8785

8886
assertion_and_signature = assertion.sub(/Issuer\>\<saml:Subject/, "Issuer>#{signature}<saml:Subject")
8987

90-
xml = %[<samlp:Response ID="_#{response_id}" Version="2.0" IssueInstant="#{now.iso8601}" Destination="#{@saml_acs_url}" Consent="urn:oasis:names:tc:SAML:2.0:consent:unspecified" InResponseTo="#{@saml_request_id}" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"><saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">#{issuer_uri}</saml:Issuer><samlp:Status><samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" /></samlp:Status>#{assertion_and_signature}</samlp:Response>]
88+
xml = %[<samlp:Response ID="_#{response_id}" Version="2.0" IssueInstant="#{now.iso8601}" Destination="#{@saml_acs_url}" Consent="urn:oasis:names:tc:SAML:2.0:consent:unspecified"#{@saml_request_id.present? ? %[ InResponseTo="#{@saml_request_id}"] : ""} xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"><saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">#{issuer_uri}</saml:Issuer><samlp:Status><samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" /></samlp:Status>#{assertion_and_signature}</samlp:Response>]
9189

9290
Base64.encode64(xml)
9391
end

lib/saml_idp/default.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# encoding: utf-8
21
module SamlIdp
32
module Default
43

lib/saml_idp/engine.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# encoding: utf-8
21
module SamlIdp
32
class Engine < Rails::Engine
43
end

lib/saml_idp/version.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# encoding: utf-8
21
module SamlIdp
3-
VERSION = '0.3.2'
2+
VERSION = '0.3.5'
43
end

ruby-saml-idp.gemspec

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- encoding: utf-8 -*-
21
$:.push File.expand_path("../lib", __FILE__)
32
require "saml_idp/version"
43

@@ -11,6 +10,8 @@ Gem::Specification.new do |s|
1110
s.homepage = %q{http://github.com/lawrencepit/ruby-saml-idp}
1211
s.summary = %q{SAML Indentity Provider in ruby}
1312
s.description = %q{SAML IdP (Identity Provider) library in ruby}
13+
s.license = "MIT"
14+
1415
s.date = Time.now.utc.strftime("%Y-%m-%d")
1516
s.files = Dir.glob("app/**/*") + Dir.glob("lib/**/*") + [
1617
"MIT-LICENSE",
@@ -22,10 +23,10 @@ Gem::Specification.new do |s|
2223
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
2324
s.require_paths = ["lib"]
2425
s.rdoc_options = ["--charset=UTF-8"]
25-
s.add_development_dependency "rake"
26-
s.add_development_dependency("nokogiri", "~> 1.6.8")
26+
s.add_development_dependency("rake")
27+
s.add_development_dependency("ruby-saml")
28+
s.add_development_dependency("nokogiri")
2729
s.add_development_dependency("rspec", "~> 3.0")
28-
s.add_development_dependency("ruby-saml", "~> 0.8")
2930
s.add_development_dependency("rails", "~> 3.2")
3031
s.add_development_dependency("capybara", "~> 2.4.1")
3132
s.add_development_dependency("timecop", "~> 0.9.0")

spec/saml_idp/controller_spec.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# encoding: utf-8
21
require 'spec_helper'
32
require 'timecop'
43

@@ -26,17 +25,16 @@ def params
2625
saml_response = encode_SAMLResponse("[email protected]")
2726
response = OneLogin::RubySaml::Response.new(saml_response)
2827
expect(response.name_id).to eq("[email protected]")
29-
expect(response.issuer).to eq("http://example.com")
28+
expect(response.issuers).to eq(["http://example.com"])
3029
response.settings = saml_settings
31-
expect(response.is_valid?).to be true
30+
expect(response.is_valid?).to be_truthy
3231
end
3332

3433
it "should handle custom attribute objects" do
3534
provider = double(to_s: %[<saml:AttributeStatement><saml:Attribute Name="organization"><saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">Organization name</saml:AttributeValue></saml:Attribute></saml:AttributeStatement>])
3635

3736
default_attributes = %[<saml:AttributeStatement><saml:Attribute Name="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"><saml:AttributeValue>[email protected]</saml:AttributeValue></saml:Attribute></saml:AttributeStatement>]
3837

39-
4038
saml_response = encode_SAMLResponse("[email protected]", { attributes_provider: provider })
4139
response = OneLogin::RubySaml::Response.new(saml_response)
4240
expect(response.response).to include provider.to_s
@@ -49,7 +47,7 @@ def params
4947
saml_response = encode_SAMLResponse("[email protected]")
5048
response = OneLogin::RubySaml::Response.new(saml_response)
5149
expect(response.name_id).to eq("[email protected]")
52-
expect(response.issuer).to eq("http://example.com")
50+
expect(response.issuers).to eq(["http://example.com"])
5351
response.settings = saml_settings
5452
expect(response.is_valid?).to be true
5553
end

spec/spec_helper.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# encoding: utf-8
21
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
32
$LOAD_PATH.unshift File.dirname(__FILE__)
43

spec/support/saml_request_macros.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def make_saml_request(requested_saml_acs_url = "https://foo.example.com/saml/con
99
def saml_settings(options = {})
1010
settings = OneLogin::RubySaml::Settings.new
1111
settings.assertion_consumer_service_url = options[:saml_acs_url] || "https://foo.example.com/saml/consume"
12-
settings.issuer = options[:issuer] || "http://example.com/issuer"
12+
settings.issuer = options[:issuer] || "https://foo.example.com/"
1313
settings.idp_sso_target_url = options[:idp_sso_target_url] || "http://idp.com/saml/idp"
1414
settings.idp_cert_fingerprint = SamlIdp::Default::FINGERPRINT
1515
settings.name_identifier_format = SamlIdp::Default::NAME_ID_FORMAT

0 commit comments

Comments
 (0)