Skip to content

Commit

Permalink
Merge pull request SAML-Toolkits#111 from onelogin/namespacing-issue
Browse files Browse the repository at this point in the history
Onelogin:: is OneLogin::
  • Loading branch information
Lordnibbler authored and Lordnibbler committed Feb 25, 2014
2 parents e9a91c1 + a0af20e commit 84c3a6f
Show file tree
Hide file tree
Showing 20 changed files with 140 additions and 140 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Ruby SAML [![Build Status](https://secure.travis-ci.org/onelogin/ruby-saml.png)](http://travis-ci.org/onelogin/ruby-saml)

## Updating from 0.7.x to 0.8.x
Version `0.8.0` changes the namespace of the gem from `Onelogin::Saml` to `Onelogin::RubySaml`. Please update your implementations of the gem accordingly.
Version `0.8.x` changes the namespace of the gem from `OneLogin::Saml` to `OneLogin::RubySaml`. Please update your implementations of the gem accordingly.

## Overview

Expand All @@ -15,7 +15,7 @@ This is the first request you will get from the identity provider. It will hit y

```ruby
def init
request = Onelogin::RubySaml::Authrequest.new
request = OneLogin::RubySaml::Authrequest.new
redirect_to(request.create(saml_settings))
end
```
Expand All @@ -24,7 +24,7 @@ Once you've redirected back to the identity provider, it will ensure that the us

```ruby
def consume
response = Onelogin::RubySaml::Response.new(params[:SAMLResponse])
response = OneLogin::RubySaml::Response.new(params[:SAMLResponse])
response.settings = saml_settings

if response.is_valid? && user = current_account.users.find_by_email(response.name_id)
Expand All @@ -39,7 +39,7 @@ In the above there are a few assumptions in place, one being that the response.n

```ruby
def saml_settings
settings = Onelogin::RubySaml::Settings.new
settings = OneLogin::RubySaml::Settings.new

settings.assertion_consumer_service_url = "http://#{request.host}/saml/finalize"
settings.issuer = request.host
Expand All @@ -59,12 +59,12 @@ What's left at this point, is to wrap it all up in a controller and point the in
# This controller expects you to use the URLs /saml/init and /saml/consume in your OneLogin application.
class SamlController < ApplicationController
def init
request = Onelogin::RubySaml::Authrequest.new
request = OneLogin::RubySaml::Authrequest.new
redirect_to(request.create(saml_settings))
end

def consume
response = Onelogin::RubySaml::Response.new(params[:SAMLResponse])
response = OneLogin::RubySaml::Response.new(params[:SAMLResponse])
response.settings = saml_settings

if response.is_valid? && user = current_account.users.find_by_email(response.name_id)
Expand All @@ -77,7 +77,7 @@ class SamlController < ApplicationController
private

def saml_settings
settings = Onelogin::RubySaml::Settings.new
settings = OneLogin::RubySaml::Settings.new

settings.assertion_consumer_service_url = "http://#{request.host}/saml/consume"
settings.issuer = request.host
Expand All @@ -96,7 +96,7 @@ If are using saml:AttributeStatement to transfare metadata, like the user name,
contains all the saml:AttributeStatement with its 'Name' as a indifferent key and the one saml:AttributeValue as value.

```ruby
response = Onelogin::RubySaml::Response.new(params[:SAMLResponse])
response = OneLogin::RubySaml::Response.new(params[:SAMLResponse])
response.settings = saml_settings

response.attributes[:username]
Expand All @@ -107,7 +107,7 @@ response.attributes[:username]
To form a trusted pair relationship with the IdP, the SP (you) need to provide metadata XML
to the IdP for various good reasons. (Caching, certificate lookups, relaying party permissions, etc)

The class Onelogin::RubySaml::Metadata takes care of this by reading the Settings and returning XML. All
The class OneLogin::RubySaml::Metadata takes care of this by reading the Settings and returning XML. All
you have to do is add a controller to return the data, then give this URL to the IdP administrator.
The metdata will be polled by the IdP every few minutes, so updating your settings should propagate
to the IdP settings.
Expand All @@ -117,7 +117,7 @@ class SamlController < ApplicationController
# ... the rest of your controller definitions ...
def metadata
settings = Account.get_saml_settings
meta = Onelogin::RubySaml::Metadata.new
meta = OneLogin::RubySaml::Metadata.new
render :xml => meta.generate(settings)
end
end
Expand All @@ -132,7 +132,7 @@ First, ensure that both systems synchronize their clocks, using for example the
Even then you may experience intermittent issues though, because the clock of the Identity Provider may drift slightly ahead of your system clocks. To allow for a small amount of clock drift you can initialize the response passing in an option named `:allowed_clock_drift`. Its value must be given in a number (and/or fraction) of seconds. The value given is added to the current time at which the response is validated before it's tested against the `NotBefore` assertion. For example:

```ruby
response = Onelogin::RubySaml::Response.new(params[:SAMLResponse], :allowed_clock_drift => 1)
response = OneLogin::RubySaml::Response.new(params[:SAMLResponse], :allowed_clock_drift => 1)
```

Make sure to keep the value as comfortably small as possible to keep security risks to a minimum.
Expand Down
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# RubySaml Changelog

### 0.8.0 (Feb 21, 2014)
Changed namespace of the gem from `Onelogin::Saml` to `Onelogin::RubySaml`. Please update your implementations of the gem accordingly.
Changed namespace of the gem from `OneLogin::Saml` to `OneLogin::RubySaml`. Please update your implementations of the gem accordingly.

### 0.7.3 (Feb 20, 2014)
Updated gem dependencies to be compatible with Ruby 1.8.7-p374 and 1.9.3-p448. Removed unnecessary `canonix` gem dependency.
2 changes: 1 addition & 1 deletion lib/onelogin/ruby-saml/authrequest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require "rexml/document"
require "rexml/xpath"

module Onelogin
module OneLogin
module RubySaml
include REXML
class Authrequest
Expand Down
2 changes: 1 addition & 1 deletion lib/onelogin/ruby-saml/logging.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Simplistic log class when we're running in Rails
module Onelogin
module OneLogin
module RubySaml
class Logging
def self.debug(message)
Expand Down
2 changes: 1 addition & 1 deletion lib/onelogin/ruby-saml/logoutrequest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "zlib"
require "cgi"

module Onelogin
module OneLogin
module RubySaml
include REXML
class Logoutrequest
Expand Down
2 changes: 1 addition & 1 deletion lib/onelogin/ruby-saml/logoutresponse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "base64"
require "zlib"

module Onelogin
module OneLogin
module RubySaml
class Logoutresponse

Expand Down
2 changes: 1 addition & 1 deletion lib/onelogin/ruby-saml/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Return this XML in a controller, then give that URL to the the
# IdP administrator. The IdP will poll the URL and your settings
# will be updated automatically
module Onelogin
module OneLogin
module RubySaml
include REXML
class Metadata
Expand Down
2 changes: 1 addition & 1 deletion lib/onelogin/ruby-saml/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "nokogiri"

# Only supports SAML 2.0
module Onelogin
module OneLogin
module RubySaml

class Response
Expand Down
2 changes: 1 addition & 1 deletion lib/onelogin/ruby-saml/settings.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Onelogin
module OneLogin
module RubySaml
class Settings
def initialize(overrides = {})
Expand Down
2 changes: 1 addition & 1 deletion lib/onelogin/ruby-saml/validation_error.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Onelogin
module OneLogin
module RubySaml
class ValidationError < StandardError
end
Expand Down
4 changes: 2 additions & 2 deletions lib/onelogin/ruby-saml/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Onelogin
module OneLogin
module RubySaml
VERSION = '0.8.0'
VERSION = '0.8.1'
end
end
8 changes: 4 additions & 4 deletions lib/xml_security.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def initialize(response)
def validate_document(idp_cert_fingerprint, soft = true)
# get cert from response
cert_element = REXML::XPath.first(self, "//ds:X509Certificate", { "ds"=>DSIG })
raise Onelogin::RubySaml::ValidationError.new("Certificate element missing in response (ds:X509Certificate)") unless cert_element
raise OneLogin::RubySaml::ValidationError.new("Certificate element missing in response (ds:X509Certificate)") unless cert_element
base64_cert = cert_element.text
cert_text = Base64.decode64(base64_cert)
cert = OpenSSL::X509::Certificate.new(cert_text)
Expand All @@ -56,7 +56,7 @@ def validate_document(idp_cert_fingerprint, soft = true)
fingerprint = Digest::SHA1.hexdigest(cert.to_der)

if fingerprint != idp_cert_fingerprint.gsub(/[^a-zA-Z0-9]/,"").downcase
return soft ? false : (raise Onelogin::RubySaml::ValidationError.new("Fingerprint mismatch"))
return soft ? false : (raise OneLogin::RubySaml::ValidationError.new("Fingerprint mismatch"))
end

validate_signature(base64_cert, soft)
Expand Down Expand Up @@ -102,7 +102,7 @@ def validate_signature(base64_cert, soft = true)
digest_value = Base64.decode64(REXML::XPath.first(ref, "//ds:DigestValue", {"ds"=>DSIG}).text)

unless digests_match?(hash, digest_value)
return soft ? false : (raise Onelogin::RubySaml::ValidationError.new("Digest mismatch"))
return soft ? false : (raise OneLogin::RubySaml::ValidationError.new("Digest mismatch"))
end
end

Expand All @@ -117,7 +117,7 @@ def validate_signature(base64_cert, soft = true)
signature_algorithm = algorithm(REXML::XPath.first(signed_info_element, "//ds:SignatureMethod", {"ds"=>DSIG}))

unless cert.public_key.verify(signature_algorithm.new, signature, canon_string)
return soft ? false : (raise Onelogin::RubySaml::ValidationError.new("Key validation error"))
return soft ? false : (raise OneLogin::RubySaml::ValidationError.new("Key validation error"))
end

return true
Expand Down
2 changes: 1 addition & 1 deletion ruby-saml.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require 'onelogin/ruby-saml/version'

Gem::Specification.new do |s|
s.name = 'ruby-saml'
s.version = Onelogin::RubySaml::VERSION
s.version = OneLogin::RubySaml::VERSION

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["OneLogin LLC"]
Expand Down
30 changes: 15 additions & 15 deletions test/logoutrequest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
class RequestTest < Test::Unit::TestCase

context "Logoutrequest" do
settings = Onelogin::RubySaml::Settings.new
settings = OneLogin::RubySaml::Settings.new

should "create the deflated SAMLRequest URL parameter" do
settings.idp_slo_target_url = "http://unauth.com/logout"
settings.name_identifier_value = "f00f00"

unauth_url = Onelogin::RubySaml::Logoutrequest.new.create(settings)
unauth_url = OneLogin::RubySaml::Logoutrequest.new.create(settings)
assert unauth_url =~ /^http:\/\/unauth\.com\/logout\?SAMLRequest=/

inflated = decode_saml_request_payload(unauth_url)
Expand All @@ -19,10 +19,10 @@ class RequestTest < Test::Unit::TestCase

should "support additional params" do

unauth_url = Onelogin::RubySaml::Logoutrequest.new.create(settings, { :hello => nil })
unauth_url = OneLogin::RubySaml::Logoutrequest.new.create(settings, { :hello => nil })
assert unauth_url =~ /&hello=$/

unauth_url = Onelogin::RubySaml::Logoutrequest.new.create(settings, { :foo => "bar" })
unauth_url = OneLogin::RubySaml::Logoutrequest.new.create(settings, { :foo => "bar" })
assert unauth_url =~ /&foo=bar$/
end

Expand All @@ -31,64 +31,64 @@ class RequestTest < Test::Unit::TestCase
sessionidx = UUID.new.generate
settings.sessionindex = sessionidx

unauth_url = Onelogin::RubySaml::Logoutrequest.new.create(settings, { :name_id => "there" })
unauth_url = OneLogin::RubySaml::Logoutrequest.new.create(settings, { :name_id => "there" })
inflated = decode_saml_request_payload(unauth_url)

assert_match /<samlp:SessionIndex/, inflated
assert_match %r(#{sessionidx}</samlp:SessionIndex>), inflated
end

should "set name_identifier_value" do
settings = Onelogin::RubySaml::Settings.new
settings = OneLogin::RubySaml::Settings.new
settings.idp_slo_target_url = "http://example.com"
settings.name_identifier_format = "transient"
name_identifier_value = "abc123"
settings.name_identifier_value = name_identifier_value

unauth_url = Onelogin::RubySaml::Logoutrequest.new.create(settings, { :name_id => "there" })
unauth_url = OneLogin::RubySaml::Logoutrequest.new.create(settings, { :name_id => "there" })
inflated = decode_saml_request_payload(unauth_url)

assert_match /<saml:NameID/, inflated
assert_match %r(#{name_identifier_value}</saml:NameID>), inflated
end

should "require name_identifier_value" do
settings = Onelogin::RubySaml::Settings.new
settings = OneLogin::RubySaml::Settings.new
settings.idp_slo_target_url = "http://example.com"
settings.name_identifier_format = nil

assert_raises(Onelogin::RubySaml::ValidationError) { Onelogin::RubySaml::Logoutrequest.new.create(settings) }
assert_raises(OneLogin::RubySaml::ValidationError) { OneLogin::RubySaml::Logoutrequest.new.create(settings) }
end

context "when the target url doesn't contain a query string" do
should "create the SAMLRequest parameter correctly" do
settings = Onelogin::RubySaml::Settings.new
settings = OneLogin::RubySaml::Settings.new
settings.idp_slo_target_url = "http://example.com"
settings.name_identifier_value = "f00f00"

unauth_url = Onelogin::RubySaml::Logoutrequest.new.create(settings)
unauth_url = OneLogin::RubySaml::Logoutrequest.new.create(settings)
assert unauth_url =~ /^http:\/\/example.com\?SAMLRequest/
end
end

context "when the target url contains a query string" do
should "create the SAMLRequest parameter correctly" do
settings = Onelogin::RubySaml::Settings.new
settings = OneLogin::RubySaml::Settings.new
settings.idp_slo_target_url = "http://example.com?field=value"
settings.name_identifier_value = "f00f00"

unauth_url = Onelogin::RubySaml::Logoutrequest.new.create(settings)
unauth_url = OneLogin::RubySaml::Logoutrequest.new.create(settings)
assert unauth_url =~ /^http:\/\/example.com\?field=value&SAMLRequest/
end
end

context "consumation of logout may need to track the transaction" do
should "have access to the request uuid" do
settings = Onelogin::RubySaml::Settings.new
settings = OneLogin::RubySaml::Settings.new
settings.idp_slo_target_url = "http://example.com?field=value"
settings.name_identifier_value = "f00f00"

unauth_req = Onelogin::RubySaml::Logoutrequest.new
unauth_req = OneLogin::RubySaml::Logoutrequest.new
unauth_url = unauth_req.create(settings)

inflated = decode_saml_request_payload(unauth_url)
Expand Down
Loading

0 comments on commit 84c3a6f

Please sign in to comment.