libsaml 2.4.7 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e33af5e606a9750e235b9c6d1bac4f1eb5711aa1
4
- data.tar.gz: 7bfbf31b2a1f8d881cbcd9a588007dfc405e895c
3
+ metadata.gz: 6366380ef4896c6c119750e48f439ca0e03a5c4e
4
+ data.tar.gz: b953ecd1d5be90e167ca5a332f52cce0536d1bf1
5
5
  SHA512:
6
- metadata.gz: ea71dcaefc7622ca57bf15d28d8cbe8114a684506652eae09fd2fe345425e8a79e645d0bb6075002fab4a386af950647b0513d492efd6f52010552a27f5b8841
7
- data.tar.gz: f23c1b43226109d43ba3afcf40a20e3f38f6c44593d3b7980fa3df9cdfc4f1f013d5f664c3d686f7795fe251b17fe49b1e0b722667978de7969a56fcda12922e
6
+ metadata.gz: f36839a1dd5ee94171d0f6078a30c1379b7756e8732e33a91828e7c880ff104db1d7f3926d406a2e9f8edaaa384c8a78db0ec03f6c6704ffffdfab2c249828f8
7
+ data.tar.gz: 884e2f549a8bcdb9f9af7ba8d28f1eb80890202b4cec3aa752c3f9a0883eeb5fd1146ff8442fa3665cb7d8b6ed9e5cca829575284810a38805d97653a41506fe
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  [![Build status](https://travis-ci.org/digidentity/libsaml.png?branch=master)](https://travis-ci.org/digidentity/libsaml)
2
2
  [![Coverage status](https://coveralls.io/repos/digidentity/libsaml/badge.png)](https://coveralls.io/r/digidentity/libsaml)
3
3
  [![Code climate](https://codeclimate.com/github/digidentity/libsaml.png)](https://codeclimate.com/github/digidentity/libsaml)
4
- [![Dependency status](https://gemnasium.com/digidentity/libsaml.png)](https://coveralls.io/r/digidentity/libsaml)
4
+ [![Dependency status](https://gemnasium.com/digidentity/libsaml.png)](https://gemnasium.com/digidentity/libsaml)
5
5
 
6
6
  # libsaml
7
7
 
@@ -102,12 +102,33 @@ class SamlController < ApplicationController
102
102
 
103
103
  authn_request = Saml::AuthnRequest.new(:destination => destination)
104
104
 
105
+ session[:authn_request_id] = auth_request._id
106
+
105
107
  @saml_attributes = Saml::Bindings::HTTPPost.create_form_attributes(authn_request)
106
108
 
107
109
  render text: @saml_attributes.to_yaml
108
110
  end
109
111
 
110
112
  def receive_response
113
+ if params["SAMLart"]
114
+ # provider should be of type Saml::Provider
115
+ @response = Saml::Bindings::HTTPArtifact.resolve(request, provider.artifact_resolution_service_url)
116
+ elsif params["SAMLResponse"]
117
+ @response = Saml::Bindings::HTTPost.receive_message(request, :response)
118
+ else
119
+ # handle invalid request
120
+ end
121
+
122
+ if @response && @response.success?
123
+ if session[:authn_request_id] == @response.in_response_to
124
+ @response.assertion.fetch_attribute('any_attribute')
125
+ else
126
+ # handle unrecognized response
127
+ end
128
+ reset_session # It's good practice to reset sessions after authenticating to mitigate session fixation attacks
129
+ else
130
+ # handle failure
131
+ end
111
132
  end
112
133
  end
113
134
  ```
@@ -117,10 +138,95 @@ Don't forget to define the routes in `config/routes.rb`:
117
138
  ```ruby
118
139
  get "/saml/request_authentication" => "saml#request_authentication"
119
140
  get "/saml/receive_response" => "saml#receive_response"
141
+ post "/saml/receive_response" => "saml#receive_response"
142
+ ```
143
+
144
+ ## Using libsaml as an IDP
145
+
146
+ Writing a solid identity provider really requires a deeper knowledge of the SAML protocol, so it's recommended to read more on the SAML 2.0 Wiki http://en.wikipedia.org/wiki/SAML_2.0.
147
+ When you understand what it says, read these parts of the specification:
148
+ http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
149
+ http://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf
150
+
151
+ Below is an example of a very primitive IDP Saml Controller
152
+
153
+ ```ruby
154
+ class SamlController < ActionController::Base
155
+ extend Saml::Rails::ControllerHelper
156
+ current_provider "entity_id"
157
+
158
+ def receive_authn_request
159
+ authn_request = if request.get?
160
+ Saml::Bindings::HTTPRedirect.receive_message(request, type: :authn_request)
161
+ elsif request.post?
162
+ Saml::Bindings::HTTPPost.receive_message(request, type: :authn_request)
163
+ else
164
+ return head :not_allowed
165
+ end
166
+ request_id = authn_request._id
167
+
168
+ session[:saml_request] = {
169
+ request_id: request_id,
170
+ relay_state: params['RelayState'],
171
+ authn_request: authn_request.to_xml
172
+ }
173
+
174
+ if authn_request.invalid?
175
+ redirect_to send_response_path(request_id: request_id)
176
+ else
177
+ redirect_to sign_in_path(return_to: send_response_path(request_id: request_id))
178
+ end
179
+ end
180
+
181
+ def send_response
182
+ return head :not_found if session[:saml_request][:request_id] != params[:request_id]
183
+
184
+ authn_request = Saml::AuthnRequest.parse(session[:saml_request][:authn_request], single: true)
185
+
186
+ response = if authn_request.invalid?
187
+ build_failure(Saml::TopLevelCodes::REQUESTER, Saml::SubStatusCodes::REQUEST_DENIED)
188
+ elsif account_signed_in?
189
+ build_success_response
190
+ else
191
+ build_failure(Saml::TopLevelCodes::RESPONDER, Saml::SubStatusCodes::NO_AUTHN_CONTEXT)
192
+ end
193
+
194
+ if authn_request.protocol_binding == Saml::ProtocolBinding::HTTP_POST
195
+ # render an auto submit form with hidden fields set in the attributes hash
196
+ @attribute = Saml::Bindings::HTTPPost.create_form_attributes(response, relay_state: session[:saml_request][:relay_state])
197
+ else
198
+ # handle unsported binding
199
+ end
200
+ end
201
+
202
+ private
203
+
204
+ def build_failure(status_value, sub_status_value)
205
+ Saml::Response.new(in_response_to: session[:saml_request][:request_id], status_value: status_value, sub_status_value: sub_status_value)
206
+ end
207
+
208
+ def build_success_response(authn_request)
209
+ assertion = Saml::Assertion.new(
210
+ name_id: current_account.username, # Return anything that you can link to an account
211
+ name_id_format: 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent',
212
+ authn_context_class_ref: Saml::ClassRefs::PASSWORD_PROTECTED,
213
+ in_response_to: authn_request._id,
214
+ recipient: authn_request.assertion_url,
215
+ audience: authn_request.issuer
216
+ }
217
+
218
+ # adding custom attributes
219
+ assertion.add_attribute('name', 'value')
220
+
221
+ Saml::Response.new(in_response_to: authn_request._id,
222
+ assertion: assertion,
223
+ status_value: Saml::TopLevelCodes::SUCCESS)
224
+ end
225
+ end
120
226
  ```
121
227
 
122
228
  ## Contributing
123
229
 
124
230
  - Fork the project
125
231
  - Contribute your changes. Please make sure your changes are properly documented and covered by tests.
126
- - Send a pull request
232
+ - Send a pull request
@@ -19,10 +19,18 @@ module Saml
19
19
 
20
20
  attribute :comparison, String, :tag => "Comparison"
21
21
 
22
- element :authn_context_class_ref, String, :namespace => 'saml', :tag => "AuthnContextClassRef"
22
+ has_many :authn_context_class_refs, String, :namespace => "saml", :tag => "AuthnContextClassRef"
23
23
 
24
24
  validates :authn_context_class_ref, :presence => true, :inclusion => ALL_CLASS_REFS
25
25
  validates :comparison, :inclusion => ComparisonTypes::ALL
26
+
27
+ def authn_context_class_ref
28
+ authn_context_class_refs.first if authn_context_class_refs
29
+ end
30
+
31
+ def authn_context_class_ref=(ref)
32
+ self.authn_context_class_refs = [ref]
33
+ end
26
34
  end
27
35
  end
28
36
  end
@@ -1,3 +1,3 @@
1
1
  module Saml
2
- VERSION = "2.4.7"
2
+ VERSION = "2.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libsaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.7
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benoist Claassen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-12 00:00:00.000000000 Z
11
+ date: 2015-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -222,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
222
  version: '0'
223
223
  requirements: []
224
224
  rubyforge_project:
225
- rubygems_version: 2.2.2
225
+ rubygems_version: 2.4.6
226
226
  signing_key:
227
227
  specification_version: 4
228
228
  summary: A gem to easily create SAML 2.0 messages.