shib-rack 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 855ed5c8d4eec25c07f99b235be9b94eba1153c7
4
+ data.tar.gz: ffe393cfb960a090997ee82895f9a58f57d11c4f
5
+ SHA512:
6
+ metadata.gz: 8004fe06ab2146f4629561447145afb655c579d4654d982f10ee6adb522c413931b910d90403663987c2896da4d4aac2f1fd54d6902d03156f64e33f3b6ff7aa
7
+ data.tar.gz: f4201a06e3481fdd85e85661fa9e655def304905a9eda10ed412989fe0084a195c8842ac85f1b1696494d75c3c554285fcb7fbbdd61f0b49400c28dc377e0688
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+
10
+ tmp
11
+ log
12
+ *.sqlite3
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --format documentation
3
+ --color
@@ -0,0 +1,12 @@
1
+ ---
2
+ AllCops:
3
+ TargetRubyVersion: 2.3
4
+
5
+ Style/FileName:
6
+ Exclude:
7
+ - lib/shib-rack.rb
8
+
9
+ Style/Documentation:
10
+ Exclude:
11
+ - spec/**/*
12
+ - sample/**/*
@@ -0,0 +1,3 @@
1
+ SimpleCov.start do
2
+ add_filter('spec')
3
+ end
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ guard :bundler do
4
+ require 'guard/bundler'
5
+ require 'guard/bundler/verify'
6
+ helper = Guard::Bundler::Verify.new
7
+
8
+ files = %w(Gemfile shib-rack.gemspec)
9
+ files.each { |file| watch(helper.real_path(file)) }
10
+ end
11
+
12
+ guard :rspec, cmd: 'bundle exec rspec' do
13
+ require 'guard/rspec/dsl'
14
+ dsl = Guard::RSpec::Dsl.new(self)
15
+
16
+ rspec = dsl.rspec
17
+ watch(rspec.spec_helper) { rspec.spec_dir }
18
+ watch(rspec.spec_support) { rspec.spec_dir }
19
+ watch(rspec.spec_files)
20
+
21
+ ruby = dsl.ruby
22
+ dsl.watch_spec_files_for(ruby.lib_files)
23
+ end
24
+
25
+ guard :rubocop do
26
+ watch(/.+\.rb$/)
27
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
28
+ end
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,73 @@
1
+ # ShibRack
2
+
3
+ [![Gem Version][GV img]][Gem Version]
4
+ [![Build Status][BS img]][Build Status]
5
+ [![Dependency Status][DS img]][Dependency Status]
6
+ [![Code Climate][CC img]][Code Climate]
7
+ [![Coverage Status][CS img]][Code Climate]
8
+
9
+ [Gem Version]: https://rubygems.org/gems/shib-rack
10
+ [Build Status]: https://codeship.com/projects/145971
11
+ [Dependency Status]: https://gemnasium.com/ausaccessfed/shib-rack
12
+ [Code Climate]: https://codeclimate.com/github/ausaccessfed/shib-rack
13
+
14
+ [GV img]: https://img.shields.io/gem/v/shib-rack.svg
15
+ [BS img]: https://img.shields.io/codeship/5cdcef80-e343-0133-84a6-5a988fa7d930/develop.svg
16
+ [DS img]: https://img.shields.io/gemnasium/ausaccessfed/shib-rack.svg
17
+ [CC img]: https://img.shields.io/codeclimate/github/ausaccessfed/shib-rack.svg
18
+ [CS img]: https://img.shields.io/codeclimate/coverage/github/ausaccessfed/shib-rack.svg
19
+
20
+ [Shibboleth SP](http://shibboleth.net) authentication plugin for Rack-based web
21
+ applications. Contains Rails-specific extensions for consumption by Rails
22
+ applications.
23
+
24
+ Author: Shaun Mangelsdorf
25
+
26
+ ```
27
+ Copyright 2016, Australian Access Federation
28
+
29
+ Licensed under the Apache License, Version 2.0 (the "License");
30
+ you may not use this file except in compliance with the License.
31
+ You may obtain a copy of the License at
32
+
33
+ http://www.apache.org/licenses/LICENSE-2.0
34
+
35
+ Unless required by applicable law or agreed to in writing, software
36
+ distributed under the License is distributed on an "AS IS" BASIS,
37
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38
+ See the License for the specific language governing permissions and
39
+ limitations under the License.
40
+ ```
41
+
42
+ ## Installation
43
+
44
+ Add the `shib-rack` dependency to your application's `Gemfile`:
45
+
46
+ ```
47
+ gem 'shib-rack'
48
+ ```
49
+
50
+ Use Bundler to install the dependency:
51
+
52
+ ```
53
+ bundle install
54
+ ```
55
+
56
+ TBC
57
+
58
+ ### Integrating with a Rack application
59
+
60
+ TBD
61
+
62
+ ### Integrating with a Rails application
63
+
64
+ TBD
65
+
66
+ ### Using with Capybara-style tests
67
+
68
+ TBD
69
+
70
+ ## Contributing
71
+
72
+ Refer to [GitHub Flow](https://guides.github.com/introduction/flow/) for
73
+ help contributing to this project.
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ RuboCop::RakeTask.new
9
+
10
+ task default: [:spec, :rubocop]
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -euo pipefail
4
+ IFS=$'\n\t'
5
+ set -vx
6
+
7
+ bundle install
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ ShibRack::Engine.routes.draw do
4
+ opts = Rails.application.config.shib_rack
5
+ handler = opts.handler.constantize.new(opts)
6
+
7
+ mount handler => ''
8
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'shib_rack'
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'shib_rack/version'
4
+
5
+ # Rack middleware for Shibboleth SP authentication - top level module
6
+ module ShibRack
7
+ end
8
+
9
+ require_relative 'shib_rack/default_receiver'
10
+ require_relative 'shib_rack/handler'
11
+ require_relative 'shib_rack/test_handler'
12
+ require_relative 'shib_rack/development_handler'
13
+ require_relative 'shib_rack/attribute_mapping'
14
+
15
+ require_relative 'shib_rack/engine' if defined?(Rails)
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShibRack
4
+ # Mixin which provides helper methods for mapping attributes from Rack's `env`
5
+ module AttributeMapping
6
+ # Class methods for defining attribute mappings
7
+ module ClassMethods
8
+ attr_accessor :attribute_mappings
9
+
10
+ def map_single_value(**mappings)
11
+ mappings.each do |attr, header|
12
+ mapper = ->(env) { env[header] }
13
+ add_attribute_mapping(attr, mapper)
14
+ end
15
+ end
16
+
17
+ def map_multi_value(**mappings)
18
+ mappings.each do |attr, header|
19
+ mapper = ->(env) { env[header].split(';') }
20
+ add_attribute_mapping(attr, mapper)
21
+ end
22
+ end
23
+
24
+ def add_attribute_mapping(attr, mapper)
25
+ raise "Conflicting mapping for `#{attr}`" if attribute_mappings[attr]
26
+ attribute_mappings[attr] = mapper
27
+ end
28
+ end
29
+
30
+ def self.included(base)
31
+ base.extend(ClassMethods)
32
+ base.attribute_mappings = {}
33
+ end
34
+
35
+ def map_attributes(env)
36
+ self.class.attribute_mappings.reduce({}) do |out, (attr, mapper)|
37
+ out.merge(attr => mapper.call(env))
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShibRack
4
+ # Mixin providing the default implementation of a subject receiver
5
+ module DefaultReceiver
6
+ def receive(env)
7
+ attrs = map_attributes(env)
8
+ store_id(env, subject(env, attrs).id)
9
+ finish(env)
10
+ end
11
+
12
+ def map_attributes(_env)
13
+ {}
14
+ end
15
+
16
+ def store_id(env, id)
17
+ env['rack.session']['subject_id'] = id
18
+ end
19
+
20
+ def finish(_env)
21
+ redirect_to('/')
22
+ end
23
+
24
+ def redirect_to(url)
25
+ [302, { 'Location' => url }, []]
26
+ end
27
+
28
+ def logout(env)
29
+ env['rack.session'].clear
30
+ redirect_to('/')
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cgi'
4
+
5
+ module ShibRack
6
+ # Handler for authenticating to an application in development mode, using
7
+ # sample identities for local testing.
8
+ class DevelopmentHandler < Handler
9
+ class <<self
10
+ attr_writer :identities
11
+
12
+ def identities
13
+ @identities ||= load_identities
14
+ end
15
+
16
+ def resolve_identity(shared_token)
17
+ identities.find { |i| i['HTTP_AUEDUPERSONSHAREDTOKEN'] == shared_token }
18
+ end
19
+
20
+ def load_identities
21
+ require 'yaml'
22
+ yaml = File.read(File.expand_path('../identities.yml', __FILE__))
23
+
24
+ YAML.load(yaml)['identities'].map do |identity|
25
+ identity.reduce({}) { |a, (k, v)| a.merge("HTTP_#{k.upcase}" => v) }
26
+ end
27
+ end
28
+ end
29
+
30
+ def call(env)
31
+ case env['PATH_INFO']
32
+ when '/login'
33
+ login(env)
34
+ when '/development'
35
+ development
36
+ else
37
+ super
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def login(env)
44
+ params = CGI.parse(env['QUERY_STRING'])
45
+ st, = params['identity']
46
+ identity = st && DevelopmentHandler.resolve_identity(st)
47
+
48
+ return super(env.merge(identity)) if identity
49
+
50
+ [302, { 'Location' => "#{env['SCRIPT_NAME']}/development" }, []]
51
+ end
52
+
53
+ def development
54
+ [
55
+ 200,
56
+ { 'Content-Type' => 'text/html; charset=utf-8' },
57
+ [development_html]
58
+ ]
59
+ end
60
+
61
+ def development_html
62
+ <<~EOF
63
+ <!doctype html>
64
+ <html>
65
+ <head><title>Development Login</title></head>
66
+ <body>
67
+ <h1>Please select an identity</h1>
68
+ #{identities_html}
69
+ </body>
70
+ </html>
71
+ EOF
72
+ end
73
+
74
+ def identities_html
75
+ DevelopmentHandler.identities.map { |i| identity_html(i) }.join
76
+ end
77
+
78
+ def identity_html(identity)
79
+ <<~EOF
80
+ <form method="get" action="login">
81
+ <hr/>
82
+ <pre>#{JSON.pretty_generate(identity)}</pre>
83
+ <input type="hidden" name="identity"
84
+ value="#{identity['HTTP_AUEDUPERSONSHAREDTOKEN']}"/>
85
+ <button type="submit">Log In</button>
86
+ </form>
87
+ EOF
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShibRack
4
+ # Provides integration of shib-rack into Rails applications
5
+ class Engine < Rails::Engine
6
+ isolate_namespace ShibRack
7
+
8
+ configure do
9
+ config.shib_rack = OpenStruct.new
10
+ end
11
+
12
+ initializer('shib_rack.configure_handler') do
13
+ configuration.handler = handler
14
+ end
15
+
16
+ def configuration
17
+ config.shib_rack
18
+ end
19
+
20
+ def handler
21
+ return 'ShibRack::DevelopmentHandler' if configuration[:development_mode]
22
+ return 'ShibRack::TestHandler' if configuration[:test_mode]
23
+ 'ShibRack::Handler'
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShibRack
4
+ # Rack application which handles incoming sessions authenticated by
5
+ # Shibboleth SP.
6
+ class Handler
7
+ attr_reader :error_handler
8
+ private :error_handler
9
+
10
+ def initialize(opts)
11
+ @receiver = constantize(opts[:receiver])
12
+ @error_handler = constantize(opts[:error_handler])&.new || self
13
+ end
14
+
15
+ def call(env)
16
+ return login(env) if env['PATH_INFO'] == '/login'
17
+ return logout(env) if env['PATH_INFO'] == '/logout'
18
+ [404, {}, ["Not found: #{env['PATH_INFO']}"]]
19
+ end
20
+
21
+ def handle(_env, _exception)
22
+ [
23
+ 400, { 'Content-Type' => 'text/plain' }, [
24
+ 'Sorry, your attempt to log in to this service was not successful. ',
25
+ 'Please contact the service owner for assistance, and include the ',
26
+ 'link you used to access this service.'
27
+ ]
28
+ ]
29
+ end
30
+
31
+ private
32
+
33
+ def login(env)
34
+ receiver.receive(env)
35
+ rescue => e
36
+ error_handler.handle(env, e)
37
+ end
38
+
39
+ def logout(env)
40
+ receiver.logout(env)
41
+ end
42
+
43
+ def constantize(klass_name)
44
+ return nil if klass_name.nil?
45
+ klass_name.split('::').reduce(Kernel) { |a, e| a.const_get(e) }
46
+ end
47
+
48
+ def receiver
49
+ @receiver.new
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,64 @@
1
+ ---
2
+ # Sample data generated by Faker 1.6.3 and Ruby's SecureRandom and then manually
3
+ # edited to our format. All data is fictional and any similarity to real
4
+ # identities is purely coincidental.
5
+ identities:
6
+ - targeted_id: https://idp.ernser.example.edu/idp/shibboleth!https://sp.example.edu/shibboleth!17865674-60c1-4202-aef9-21d4e66338d6
7
+ auedupersonsharedtoken: CZa_1pvgsbWD_IzNsAR7d7jaGcs
8
+ displayname: Jefferey Kohler
9
+ cn: Jefferey Kohler
10
+ principalname: kohlerj@ernser.example.edu
11
+ mail: jefferey.kohler@ernser.example.edu
12
+ o: Southern Ernser University
13
+ homeorganization: ernser.example.edu
14
+ homeorganizationtype: urn:mace:terena.org:schac:homeOrganizationType:au:university
15
+ edupersonaffiliation: staff;member
16
+ edupersonscopedaffiliation: staff@ernser.example.edu;member@ernser.example.edu
17
+
18
+ - targeted_id: https://login.schneidermoen.example.edu/idp/shibboleth!https://sp.example.edu/shibboleth!a4ee2cb2-d764-4e1c-90f2-c6756b83d538
19
+ auedupersonsharedtoken: iNrgu8iDNLu2V_WT7OxnwKs1EBs
20
+ displayname: Winifred Cummings IV
21
+ cn: Winifred Cummings
22
+ principalname: w.cummings@schneidermoen.example.org
23
+ mail: w.cummings+fed@schneidermoen.example.org
24
+ o: Schneider-Moen
25
+ homeorganization: schneidermoen.example.org
26
+ homeorganizationtype: urn:mace:terena.org:schac:homeOrganizationType:au:other
27
+ edupersonaffiliation: member
28
+ edupersonscopedaffiliation: member@schneidermoen.example.edu
29
+
30
+ - targeted_id: https://idp.fritsch.example.edu/idp/shibboleth!https://sp.example.edu/shibboleth!R+kfUJVoLH+xfDX/0rPwCTTRfoHaS5QofNPlXmYU
31
+ auedupersonsharedtoken: 07fhxNyDIEa4DNYBTK2Bi0_D1Bc
32
+ displayname: Keeley A. Romaguera
33
+ cn: Keeley Romaguera
34
+ principalname: romagk@fritsch.example.edu
35
+ mail: keeley.r@student.fritsch.example.edu
36
+ o: Fritsch University
37
+ homeorganization: fritsch.example.edu
38
+ homeorganizationtype: urn:mace:terena.org:schac:homeOrganizationType:au:university
39
+ edupersonaffiliation: student;member
40
+ edupersonscopedaffiliation: student@fritsch.example.edu;member@fritsch.example.edu
41
+
42
+ - targeted_id: https://idp.westmarks.example.edu/idp/shibboleth!https://sp.example.edu/shibboleth!d2949a7a-0920-427f-a98e-846c4261c737
43
+ auedupersonsharedtoken: GBxa6l23yK5m6-jmPcoBJLWzg5w
44
+ displayname: Lüra Vån Ernser V
45
+ cn: Lüra VånErnser
46
+ principalname: velura@westmarks.example.edu
47
+ mail: ve.lura@westmarks.example.edu
48
+ o: West Marks Academy
49
+ homeorganization: westmarks.example.edu
50
+ homeorganizationtype: urn:mace:terena.org:schac:homeOrganizationType:au:university
51
+ edupersonaffiliation: staff;member
52
+ edupersonscopedaffiliation: staff@westmarks.example.edu;member@westmarks.example.edu
53
+
54
+ - targeted_id: https://idp.stroa.example.ac.ru/idp/shibboleth!https://sp.example.edu/shibboleth!JnNdHrBp8qYrHYM8dnXrPdV52whAHcc6bpmlsvw=
55
+ auedupersonsharedtoken: weR_sI_2huUSq_2bGOkd1sMNZ9I
56
+ displayname: Константинова Арина Данииловна
57
+ cn: Константинова АринаДанииловна
58
+ principalname: daniika@stroa.example.ac.ru
59
+ mail: ka.daniilovna@stroa.example.ac.ru
60
+ o: Южная Тромп академия
61
+ homeorganization: stroa.example.ac.ru
62
+ homeorganizationtype: urn:mace:terena.org:schac:homeOrganizationType:ru:university
63
+ edupersonaffiliation: staff;member
64
+ edupersonscopedaffiliation: staff@stroa.example.ac.ru;member@stroa.example.ac.ru
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShibRack
4
+ # Handler for headless browser testing, which injects configured attributes
5
+ # into the Rack env before invoking ShibRack::Handler.
6
+ class TestHandler < Handler
7
+ class <<self
8
+ attr_accessor :attributes
9
+ end
10
+
11
+ def call(env)
12
+ attrs = TestHandler.attributes || raise('No user attributes were set')
13
+ super(env.merge(attrs))
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShibRack
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path('../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'shib_rack/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'shib-rack'
10
+ spec.version = ShibRack::VERSION
11
+ spec.authors = ['Shaun Mangelsdorf']
12
+ spec.email = ['s.mangelsdorf@gmail.com']
13
+
14
+ spec.summary = 'Rack middleware for Shibboleth SP authentication'
15
+ spec.homepage = 'https://github.com/ausaccessfed/shib-rack.git'
16
+
17
+ spec.files =
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(sample|spec)/}) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'rack'
22
+
23
+ spec.add_development_dependency 'rack-test'
24
+ spec.add_development_dependency 'faker'
25
+ spec.add_development_dependency 'rails', '~> 4.2'
26
+ spec.add_development_dependency 'sqlite3'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.11'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.0'
31
+
32
+ spec.add_development_dependency 'guard'
33
+ spec.add_development_dependency 'guard-bundler'
34
+ spec.add_development_dependency 'guard-rubocop'
35
+ spec.add_development_dependency 'guard-rspec'
36
+ spec.add_development_dependency 'simplecov'
37
+ end
metadata ADDED
@@ -0,0 +1,247 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shib-rack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shaun Mangelsdorf
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack-test
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faker
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.11'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.11'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard-bundler
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: guard-rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: guard-rspec
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: simplecov
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ description:
196
+ email:
197
+ - s.mangelsdorf@gmail.com
198
+ executables: []
199
+ extensions: []
200
+ extra_rdoc_files: []
201
+ files:
202
+ - ".gitignore"
203
+ - ".rspec"
204
+ - ".rubocop.yml"
205
+ - ".simplecov"
206
+ - Gemfile
207
+ - Guardfile
208
+ - LICENSE
209
+ - README.md
210
+ - Rakefile
211
+ - bin/setup
212
+ - config/routes.rb
213
+ - lib/shib-rack.rb
214
+ - lib/shib_rack.rb
215
+ - lib/shib_rack/attribute_mapping.rb
216
+ - lib/shib_rack/default_receiver.rb
217
+ - lib/shib_rack/development_handler.rb
218
+ - lib/shib_rack/engine.rb
219
+ - lib/shib_rack/handler.rb
220
+ - lib/shib_rack/identities.yml
221
+ - lib/shib_rack/test_handler.rb
222
+ - lib/shib_rack/version.rb
223
+ - shib-rack.gemspec
224
+ homepage: https://github.com/ausaccessfed/shib-rack.git
225
+ licenses: []
226
+ metadata: {}
227
+ post_install_message:
228
+ rdoc_options: []
229
+ require_paths:
230
+ - lib
231
+ required_ruby_version: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - ">="
234
+ - !ruby/object:Gem::Version
235
+ version: '0'
236
+ required_rubygems_version: !ruby/object:Gem::Requirement
237
+ requirements:
238
+ - - ">="
239
+ - !ruby/object:Gem::Version
240
+ version: '0'
241
+ requirements: []
242
+ rubyforge_project:
243
+ rubygems_version: 2.5.1
244
+ signing_key:
245
+ specification_version: 4
246
+ summary: Rack middleware for Shibboleth SP authentication
247
+ test_files: []