feide 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +3 -0
- data/README.md +49 -0
- data/examples/sinatra.rb +36 -0
- data/feide.gemspec +23 -0
- data/lib/feide/version.rb +3 -0
- data/lib/feide_sp.rb +80 -0
- metadata +70 -0
data/CHANGES
ADDED
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
FEIDE
|
2
|
+
=====
|
3
|
+
|
4
|
+
Library that aids in making a SAML Service Provider for the FEIDE SAML Identity Provider.
|
5
|
+
|
6
|
+
The main part of this library is a Rack middelware, making it easy to
|
7
|
+
integrate with Rails, Sinatra, or any other Rack based frameworks.
|
8
|
+
|
9
|
+
Install
|
10
|
+
-------
|
11
|
+
|
12
|
+
gem install feide
|
13
|
+
|
14
|
+
Usage
|
15
|
+
-----
|
16
|
+
|
17
|
+
See examples/sinatra.rb
|
18
|
+
|
19
|
+
Author
|
20
|
+
------
|
21
|
+
|
22
|
+
Kjell-Magne Øierud (kjellm AT oierud DOT net)
|
23
|
+
|
24
|
+
Bugs
|
25
|
+
----
|
26
|
+
|
27
|
+
Report bugs to http://github.com/kjellm/feide/issues
|
28
|
+
|
29
|
+
License
|
30
|
+
-------
|
31
|
+
|
32
|
+
(The MIT License)
|
33
|
+
|
34
|
+
Copyright © 2012 Kjell-Magne Øierud
|
35
|
+
|
36
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
37
|
+
associated documentation files (the ‘Software’), to deal in the Software without restriction, including
|
38
|
+
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
39
|
+
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to
|
40
|
+
the following conditions:
|
41
|
+
|
42
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial
|
43
|
+
portions of the Software.
|
44
|
+
|
45
|
+
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
46
|
+
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
47
|
+
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
48
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
49
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/examples/sinatra.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'saml'
|
3
|
+
require 'feide_sp'
|
4
|
+
|
5
|
+
##### CONFIGURATION
|
6
|
+
#
|
7
|
+
|
8
|
+
# This need to be set to the same port as the one feide expects to
|
9
|
+
# connect to.
|
10
|
+
#
|
11
|
+
# (If this happens to be a privileged port and you use RVM, use
|
12
|
+
# rvmsudo to start the app.)
|
13
|
+
set :port, 80
|
14
|
+
|
15
|
+
# Location of the SAML Metadata document containing an
|
16
|
+
# <EntitiesDescriptor> as the root element with both your and feides
|
17
|
+
# <EntityDescriptor>s.
|
18
|
+
metadata = 'feide.xml'
|
19
|
+
|
20
|
+
#
|
21
|
+
##### END: CONFIGURATION
|
22
|
+
|
23
|
+
meta = SAML::Metadata::Document.new(open(metadata, 'r')).root
|
24
|
+
|
25
|
+
use FeideSP, { :meta => meta }
|
26
|
+
|
27
|
+
get '/' do
|
28
|
+
<<EOT
|
29
|
+
<h1>The Sinatra Example</h1>
|
30
|
+
<ul>
|
31
|
+
<li><a href="/feide/signon">Signon</a>
|
32
|
+
<li><a href="/feide/logout">Logout</a>
|
33
|
+
EOT
|
34
|
+
end
|
35
|
+
|
36
|
+
|
data/feide.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "feide/version"
|
4
|
+
|
5
|
+
development_files = %w(Gemfile .gitignore)
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "feide"
|
9
|
+
s.version = Feide::VERSION
|
10
|
+
s.author = "Kjell-Magne Øierud"
|
11
|
+
s.email = ["kjellm@oierud.net"]
|
12
|
+
s.homepage = "https://github.com/kjellm/feide"
|
13
|
+
s.license = "MIT"
|
14
|
+
s.summary = %q{Library that aids in making a SAML Service Provider for the FEIDE SAML Identity Provider}
|
15
|
+
s.description = %q{Library that aids in making a SAML Service Provider for the FEIDE SAML Identity Provider}
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n") - development_files
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.required_ruby_version = '>= 1.8.7'
|
21
|
+
|
22
|
+
s.add_runtime_dependency "saml"
|
23
|
+
end
|
data/lib/feide_sp.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'saml'
|
2
|
+
|
3
|
+
class FeideSP
|
4
|
+
|
5
|
+
def initialize(app, opts)
|
6
|
+
@meta = SAML::Metadata::EntitiesDescriptor.from_xml(opts[:meta])
|
7
|
+
@app = app
|
8
|
+
|
9
|
+
@assertion_consumer_service = @meta.sp.sp_sso_descriptors.first.assertion_consumer_services.first
|
10
|
+
@single_logout_service = @meta.sp.sp_sso_descriptors.first.single_logout_services.first
|
11
|
+
|
12
|
+
@dispatch = {
|
13
|
+
'GET' => {
|
14
|
+
'/feide/signon' => method(:signon),
|
15
|
+
'/feide/logout' => method(:logout),
|
16
|
+
@single_logout_service.location.path => method(:consume_logout),
|
17
|
+
},
|
18
|
+
'POST' => {
|
19
|
+
@assertion_consumer_service.location.path => method(:consume),
|
20
|
+
},
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def call(env)
|
25
|
+
response = dispatch(env)
|
26
|
+
return response unless response.nil?
|
27
|
+
@app.call(env)
|
28
|
+
end
|
29
|
+
|
30
|
+
def dispatch(env)
|
31
|
+
request = Rack::Request.new(env)
|
32
|
+
return unless %w(GET POST).find(request.request_method)
|
33
|
+
handler = @dispatch[request.request_method][request.path_info]
|
34
|
+
return if handler.nil?
|
35
|
+
handler.call(request)
|
36
|
+
end
|
37
|
+
|
38
|
+
def signon(request)
|
39
|
+
response = Rack::Response.new
|
40
|
+
saml_req = SAML::Core::AuthnRequest.new
|
41
|
+
saml_req.issuer = @meta.sp.entity_id
|
42
|
+
puts saml_req.to_xml
|
43
|
+
endpoint = @meta.idp.idp_sso_descriptors.first.single_signon_services.first
|
44
|
+
SAML::Bindings.from_endpoint(endpoint).build_request(response, endpoint, saml_req)
|
45
|
+
response
|
46
|
+
end
|
47
|
+
|
48
|
+
def consume(request)
|
49
|
+
response = Rack::Response.new
|
50
|
+
saml_resp = SAML::Bindings.from_endpoint(@assertion_consumer_service).build_response(request)
|
51
|
+
saml_resp.valid?(@meta.idp.idp_sso_descriptors.first.signing_key_descriptor.x509_certificate)
|
52
|
+
str = "<pre>Status success?: #{saml_resp.success?}\n"
|
53
|
+
saml_resp.assertions.first.attribute_statement.attributes.each do |a|
|
54
|
+
str << " #{a.name} #{a.attribute_values}\n"
|
55
|
+
end
|
56
|
+
response.write(str)
|
57
|
+
response
|
58
|
+
end
|
59
|
+
|
60
|
+
def logout(request)
|
61
|
+
response = Rack::Response.new
|
62
|
+
saml_req = SAML::Core::LogoutRequest.new
|
63
|
+
saml_req.name_id = "test@feide.no"
|
64
|
+
saml_req.issuer = @meta.sp.entity_id
|
65
|
+
endpoint = @meta.idp.idp_sso_descriptors.first.single_logout_services.first
|
66
|
+
SAML::Bindings.from_endpoint(endpoint).build_request(response, endpoint, saml_req)
|
67
|
+
response
|
68
|
+
end
|
69
|
+
|
70
|
+
def consume_logout(request)
|
71
|
+
response = Rack::Response.new
|
72
|
+
saml_resp = SAML::Bindings.from_endpoint(@single_logout_service).build_response(request)
|
73
|
+
str = "<pre>Status success?: #{saml_resp.success?}\n</pre>"
|
74
|
+
response.write(str)
|
75
|
+
response
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: feide
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kjell-Magne Øierud
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: saml
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '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: '0'
|
30
|
+
description: Library that aids in making a SAML Service Provider for the FEIDE SAML
|
31
|
+
Identity Provider
|
32
|
+
email:
|
33
|
+
- kjellm@oierud.net
|
34
|
+
executables: []
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- CHANGES
|
39
|
+
- README.md
|
40
|
+
- examples/sinatra.rb
|
41
|
+
- feide.gemspec
|
42
|
+
- lib/feide/version.rb
|
43
|
+
- lib/feide_sp.rb
|
44
|
+
homepage: https://github.com/kjellm/feide
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.8.7
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.24
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Library that aids in making a SAML Service Provider for the FEIDE SAML Identity
|
69
|
+
Provider
|
70
|
+
test_files: []
|