omniauth-shibboleth-passive 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+
20
+ # Ignore the Gemfile.lock
21
+ /Gemfile.lock
22
+
23
+ # Ignore .ruby-version
24
+ .ruby-version
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - jruby-19mode
7
+ - rbx
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
3
+
4
+ gem "coveralls", "~> 0.7.0", require: false, group: :test
5
+ gem "pry-debugger", group: :development, platform: :mri
6
+ gem "pry", group: :development, platforms: [:jruby, :rbx]
7
+
8
+ platforms :rbx do
9
+ gem 'rubysl', '~> 2.0' # if using anything in the ruby standard library
10
+ gem 'json', '~> 1.8.1'
11
+ gem 'rubinius-coverage'
12
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Scot Dalton
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+
2
+ [![Gem Version](https://badge.fury.io/rb/omniauth-shibboleth-passive.png)](http://badge.fury.io/rb/omniauth-shibboleth-passive)
3
+ [![Build Status](https://api.travis-ci.org/scotdalton/omniauth-shibboleth-passive.png?branch=master)](https://travis-ci.org/scotdalton/omniauth-shibboleth-passive)
4
+ [![Dependency Status](https://gemnasium.com/scotdalton/omniauth-shibboleth-passive.png)](https://gemnasium.com/scotdalton/omniauth-shibboleth-passive)
5
+ [![Code Climate](https://codeclimate.com/github/scotdalton/omniauth-shibboleth-passive.png)](https://codeclimate.com/github/scotdalton/omniauth-shibboleth-passive)
6
+ [![Coverage Status](https://coveralls.io/repos/scotdalton/omniauth-shibboleth-passive/badge.png?branch=master)](https://coveralls.io/r/scotdalton/omniauth-shibboleth-passive)
7
+
8
+ OmniAuth strategy for Shibboleth in ["passive mode"](https://wiki.shibboleth.net/confluence/display/SHIB2/NativeSPProtectContent).
9
+
10
+ ## Overview
11
+ The OmniAuth "Passive" Shibboleth Strategy extends [`OmniAuth::Shibboleth`](https://github.com/toyokazu/omniauth-shibboleth/) to
12
+ provide support for Shibboleth configured in ["passive mode"](https://wiki.shibboleth.net/confluence/display/SHIB2/NativeSPProtectContent).
13
+
14
+ In cases where there is no SP Shibboleth session the strategy will redirect to the IdP to try to establish a SP session.
15
+
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc 'Default: run specs.'
6
+ task :default => :spec
7
+
8
+ desc "Run specs"
9
+ RSpec::Core::RakeTask.new
@@ -0,0 +1 @@
1
+ require "omniauth/shibboleth-passive"
@@ -0,0 +1,2 @@
1
+ require 'omniauth/shibboleth/passive/version'
2
+ require 'omniauth/strategies/shibboleth_passive'
@@ -0,0 +1,7 @@
1
+ module OmniAuth
2
+ module Shibboleth
3
+ module Passive
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,50 @@
1
+ require 'omniauth-shibboleth'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class ShibbolethPassive < Shibboleth
6
+ option :name, :shibboleth_passive
7
+
8
+ # Override callback phase to not fail
9
+ # where there isn't a Shibboleth session
10
+ def callback_phase
11
+ if shibboleth_session? || shibboleth_idp_called?
12
+ unset_shibboleth_idp_called_param
13
+ (shibboleth_session?) ? super : silent_fail
14
+ else
15
+ set_shibboleth_idp_called_param
16
+ redirect(shibboleth_idp_url)
17
+ end
18
+ end
19
+
20
+ def silent_fail
21
+ OmniAuth.config.on_failure.call(env)
22
+ end
23
+
24
+ def shibboleth_idp_url
25
+ "/Shibboleth.sso/Login?isPassive=true&target=#{URI.escape(callback_url)}"
26
+ end
27
+
28
+ def shibboleth_session?
29
+ (request_param(options.shib_session_id_field.to_s) ||
30
+ request_param(options.shib_application_id_field.to_s))
31
+ end
32
+
33
+ def shibboleth_idp_called?
34
+ shibboleth_idp_called_param == true
35
+ end
36
+
37
+ def set_shibboleth_idp_called_param
38
+ session[:shibboleth_idp_called] = true
39
+ end
40
+
41
+ def unset_shibboleth_idp_called_param
42
+ session[:shibboleth_idp_called] = nil
43
+ end
44
+
45
+ def shibboleth_idp_called_param
46
+ session[:shibboleth_idp_called]
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth/shibboleth/passive/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'omniauth-shibboleth-passive'
6
+ gem.version = OmniAuth::Shibboleth::Passive::VERSION
7
+ gem.authors = ['Scot Dalton']
8
+ gem.email = ['scotdalton@gmail.edu']
9
+ gem.summary = 'OmniAuth strategy for Shibboleth in "passive mode"'
10
+ gem.homepage = 'https://github.com/scotdalton/omniauth-shibboleth-passive'
11
+ gem.license = 'MIT'
12
+
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
16
+ gem.require_paths = ['lib']
17
+
18
+ gem.add_runtime_dependency 'omniauth-shibboleth', '~> 1.1.0'
19
+
20
+ gem.add_development_dependency 'omniauth', '~> 1.2.0'
21
+ gem.add_development_dependency 'rake', '~> 10.1.0'
22
+ gem.add_development_dependency 'rspec', '~> 2.14.0'
23
+ gem.add_development_dependency 'rack-test', '~> 0.6.2'
24
+ gem.add_development_dependency 'activesupport', '~> 4.0.2'
25
+ end
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+ describe "OmniAuth::Strategies::ShibbolethPassive" do
3
+ let(:config) { {} }
4
+ let(:every_request_config) { { passive_idp_callback_frequency: :every_request } }
5
+ let(:first_request_config) { { passive_idp_callback_frequency: :first_request } }
6
+ let(:every_5_minutes_config) { { passive_idp_callback_frequency: -> { 5.minutes.ago } } }
7
+ let(:invalid_config) { { passive_idp_callback_frequency: :invalid_config } }
8
+ let(:shibboleth_idp_called) { nil }
9
+ let(:shib_session_id_field) { strategy.options.shib_session_id_field.to_s }
10
+ let(:shib_application_id_field) { strategy.options.shib_application_id_field.to_s }
11
+ let(:shib_session_id) { nil }
12
+ let(:shib_application_id) { nil }
13
+ before do
14
+ strategy.env[shib_session_id_field] = shib_session_id
15
+ strategy.env[shib_application_id_field] = shib_application_id
16
+ end
17
+ subject(:strategy) do
18
+ OmniAuth::Strategies::ShibbolethPassive.new(->(env) {}, config).tap do |s|
19
+ s.instance_variable_set(:@env, { 'rack.session' => { shibboleth_idp_called: shibboleth_idp_called } })
20
+ allow(s).to receive(:fail!).and_return(true)
21
+ end
22
+ end
23
+ describe '#name' do
24
+ subject { strategy.name }
25
+ it { should eq(:shibboleth_passive)}
26
+ end
27
+ describe '#shibboleth_idp_called_param' do
28
+ subject { strategy.shibboleth_idp_called_param }
29
+ context "when Shibboleth hasn't been called" do
30
+ it { should be_nil }
31
+ end
32
+ context "when Shibboleth hasn been called" do
33
+ let(:shibboleth_idp_called) { true }
34
+ it { should_not be_nil }
35
+ it { should be_true }
36
+ end
37
+ end
38
+ describe '#set_shibboleth_idp_called_param' do
39
+ it "should set the IdP called back session variable to true" do
40
+ strategy.set_shibboleth_idp_called_param
41
+ expect(strategy.shibboleth_idp_called_param).not_to be_nil
42
+ expect(strategy.shibboleth_idp_called_param).to be_true
43
+ end
44
+ end
45
+ describe '#unset_shibboleth_idp_called_param' do
46
+ let(:shibboleth_idp_called) { true }
47
+ it "should set the IdP called back session variable to nil" do
48
+ strategy.unset_shibboleth_idp_called_param
49
+ expect(strategy.shibboleth_idp_called_param).to be_nil
50
+ end
51
+ end
52
+ describe '#shibboleth_session?' do
53
+ subject { strategy.shibboleth_session? }
54
+ context 'when there isn\'t a Shibboleth session' do
55
+ it { should be_false }
56
+ end
57
+ context 'when there is a Shibboleth session id' do
58
+ let(:shib_session_id) { "1234567890" }
59
+ it { should be_true }
60
+ end
61
+ context 'when there is a Shibboleth application id' do
62
+ let(:shib_application_id) { "1234567890" }
63
+ it { should be_true }
64
+ end
65
+ context 'when there is a Shibboleth session id and a Shibboleth application id' do
66
+ let(:shib_session_id) { "1234567890" }
67
+ let(:shib_application_id) { "1234567890" }
68
+ it { should be_true }
69
+ end
70
+ end
71
+ describe '#shibboleth_idp_url' do
72
+ subject { strategy.shibboleth_idp_url }
73
+ it { should eq("/Shibboleth.sso/Login?isPassive=true&target=/auth/shibboleth_passive/callback") }
74
+ end
75
+ describe '#shibboleth_idp_called?' do
76
+ subject { strategy.shibboleth_idp_called? }
77
+ context 'when the IdP hasn\'t been called back to yet' do
78
+ before { allow(strategy).to receive(:shibboleth_idp_called_param).and_return(nil) }
79
+ it { should be_false}
80
+ end
81
+ context 'when the IdP has already been called back to' do
82
+ before { allow(strategy).to receive(:shibboleth_idp_called_param).and_return(true) }
83
+ it { should be_true }
84
+ end
85
+ end
86
+ describe '#callback_phase' do
87
+ let(:shibbleth_session) { false }
88
+ let(:shibboleth_idp_called) { false }
89
+ before { allow(strategy).to receive(:shibboleth_session?).and_return(shibbleth_session) }
90
+ before { allow(strategy).to receive(:shibboleth_idp_called?).and_return(shibboleth_idp_called) }
91
+ before { allow(strategy).to receive(:set_shibboleth_idp_called_param).and_return(true) }
92
+ before { allow(strategy).to receive(:unset_shibboleth_idp_called_param).and_return(true) }
93
+ before { allow(strategy).to receive(:silent_fail).and_return(true) }
94
+ before { strategy.callback_phase }
95
+ context 'when there is a shibboleth session' do
96
+ let(:shib_session_id) { "1234567890" }
97
+ let(:shibbleth_session) { true }
98
+ it { should_not have_received(:fail!) }
99
+ it { should_not have_received(:set_shibboleth_idp_called_param) }
100
+ it { should have_received(:unset_shibboleth_idp_called_param) }
101
+ it { should_not have_received(:silent_fail) }
102
+ end
103
+ context 'when there isn\'t a shibboleth session' do
104
+ context 'when the IdP hasn\'t been called back to yet' do
105
+ it { should_not have_received(:fail!) }
106
+ it { should have_received(:set_shibboleth_idp_called_param) }
107
+ it { should_not have_received(:unset_shibboleth_idp_called_param) }
108
+ it { should_not have_received(:silent_fail) }
109
+ end
110
+ context 'when the IdP has already been called back' do
111
+ let(:shibboleth_idp_called) { true }
112
+ it { should_not have_received(:fail!) }
113
+ it { should_not have_received(:set_shibboleth_idp_called_param) }
114
+ it { should have_received(:unset_shibboleth_idp_called_param) }
115
+ it { should have_received(:silent_fail) }
116
+ end
117
+ end
118
+ end
119
+ describe '#silent_fail' do
120
+ it "should not raise an error" do
121
+ expect { strategy.silent_fail }.not_to raise_error
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,18 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+ require 'rspec'
6
+ require 'rack/test'
7
+ require 'omniauth'
8
+ require 'omniauth-shibboleth-passive'
9
+ require 'pry'
10
+ require 'active_support/core_ext/numeric/time'
11
+
12
+ RSpec.configure do |config|
13
+ config.include Rack::Test::Methods
14
+ config.extend OmniAuth::Test::StrategyMacros, type: :strategy
15
+ config.expect_with :rspec do |c|
16
+ c.syntax = :expect
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-shibboleth-passive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Scot Dalton
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth-shibboleth
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: omniauth
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.2.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.2.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 10.1.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 10.1.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.14.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.14.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: rack-test
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 0.6.2
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 0.6.2
94
+ - !ruby/object:Gem::Dependency
95
+ name: activesupport
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 4.0.2
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 4.0.2
110
+ description:
111
+ email:
112
+ - scotdalton@gmail.edu
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - .travis.yml
119
+ - Gemfile
120
+ - LICENSE
121
+ - README.md
122
+ - Rakefile
123
+ - lib/omniauth-shibboleth-passive.rb
124
+ - lib/omniauth/shibboleth-passive.rb
125
+ - lib/omniauth/shibboleth/passive/version.rb
126
+ - lib/omniauth/strategies/shibboleth_passive.rb
127
+ - omniauth-shibboleth-passive.gemspec
128
+ - spec/omniauth/strategies/shibboleth_passive_spec.rb
129
+ - spec/spec_helper.rb
130
+ homepage: https://github.com/scotdalton/omniauth-shibboleth-passive
131
+ licenses:
132
+ - MIT
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ segments:
144
+ - 0
145
+ hash: 2296265459929569504
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ segments:
153
+ - 0
154
+ hash: 2296265459929569504
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 1.8.23
158
+ signing_key:
159
+ specification_version: 3
160
+ summary: OmniAuth strategy for Shibboleth in "passive mode"
161
+ test_files:
162
+ - spec/omniauth/strategies/shibboleth_passive_spec.rb
163
+ - spec/spec_helper.rb