rack-cas 0.13.0 → 0.14.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: cc8336d0e3209b2a97a12f4edf8c75ab4eba5394
4
- data.tar.gz: 75d90457796e73f01d1a68e94c17fc833823306c
3
+ metadata.gz: daf9d3dbf75e0d6a514a5385e4eac0d3d9c892b7
4
+ data.tar.gz: 53e90cefe8b5aeaa46f417cb989fbc8a41452af4
5
5
  SHA512:
6
- metadata.gz: 9e3411f27cb4033cdc3a9f908680fa456d9b0b36ea61e49abe55411d1e299fb44fa97eef5451aabf5b71bc18e1ea896dd830e4109466f322111e2fe24686ee05
7
- data.tar.gz: e4fa2a3b97670d12d5ab8967c8e7413eeff4405d15e062e0b58d908983dcbd71ec0958c0c764b51ea7461111657f33ab974cb62d1333faf9789582ca05ad55c0
6
+ metadata.gz: a8869d32aef929055c0ce13d90c064a794512f52aaae28512357c875e50940df1e94f9f7ae5f2e2289e306ca9ebc6ab56e0044ea6583b2e2cd0c68919609eeb6
7
+ data.tar.gz: c73417fcef8ab4db3912b9fad3d9c090418c4ee47fffb5f3a88fa40e7615ab99e9aa704d49acfdc42c012872de97516965128f0c67eb09fe6b6bea5fc80ce328
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Rack-CAS [![Build Status](https://travis-ci.org/biola/rack-cas.png?branch=master)](https://travis-ci.org/biola/rack-cas)
1
+ Rack-CAS [![Build Status](https://travis-ci.org/biola/rack-cas.svg?branch=master)](https://travis-ci.org/biola/rack-cas) [![Gem Version](https://badge.fury.io/rb/rack-cas.svg)](https://badge.fury.io/rb/rack-cas)
2
2
  ========
3
3
  Rack-CAS is simple [Rack](http://rack.github.com/) middleware to perform [CAS](http://en.wikipedia.org/wiki/Central_Authentication_Service) client authentication.
4
4
 
@@ -20,7 +20,7 @@ Requirements
20
20
  ============
21
21
  * Ruby >= 1.9.2
22
22
  * A working [CAS server](http://casino.rbcas.com)
23
- * An app that [returns a `401 Unauthorized`](#integration) status when authentication is requried
23
+ * An app that [returns a `401 Unauthorized`](#integration) status when authentication is required
24
24
 
25
25
  Installation
26
26
  ============
@@ -38,7 +38,7 @@ If the the server URL depends on your environment, you can define it in the acco
38
38
 
39
39
  ### Single Logout ###
40
40
 
41
- If you wish to enable [single logout](http://jasig.github.io/cas/4.0.x/installation/Logout-Single-Signout.html) you'll need to modify your configuration as below.
41
+ If you wish to enable [single logout](http://apereo.github.io/cas/4.0.x/installation/Logout-Single-Signout.html) you'll need to modify your configuration as below.
42
42
 
43
43
  #### Active Record ####
44
44
 
@@ -83,7 +83,27 @@ See the [example Sinatra app](https://gist.github.com/adamcrown/a7e7577594690335
83
83
 
84
84
  ### Single Sign Out ###
85
85
 
86
- Single sign out support outside of Rails is currently untested. We'll be adding instructions here soon.
86
+ You will need to store sessions in session store supported by Rack CAS.
87
+
88
+ #### Active Record ####
89
+ Add a migration that looks roughly like
90
+
91
+ class AddSessionStore < ActiveRecord::Migration
92
+ def change
93
+ create_table :sessions do |t|
94
+ t.string :cas_ticket
95
+ t.string :session_id
96
+ t.text :data
97
+ t.datetime :created_at
98
+ t.datetime :updated_at
99
+ end
100
+ end
101
+ end
102
+
103
+ Then use the middleware with
104
+
105
+ require 'rack-cas/session-store/rack/active_record'
106
+ use Rack::Session::RackCASActiveRecordStore
87
107
 
88
108
  Configuration
89
109
  =============
@@ -111,6 +131,29 @@ The same options can be passed to `FakeCAS`.
111
131
  use Rack::FakeCAS, exclude_path: '/api'
112
132
  ```
113
133
 
134
+ Excluding Requests
135
+ ------------------
136
+
137
+ If the path exclusion is not suitable to ignore the CAS authentication in some parts of your app, you can pass
138
+ `exclude_request_validator` to the middleware with a custom validator. You need to pass a `Proc` object that will accept
139
+ a `Rack::Request` object as a parameter.
140
+
141
+ ```ruby
142
+ use Rack::CAS, server_url: '...', exclude_request_validator: Proc.new { |req| req.env['HTTP_CONTENT_TYPE'] == 'application/json' }
143
+ ```
144
+
145
+ Ignore 401 Intercept
146
+ --------------------
147
+
148
+ For some requests you might want to ignore the 401 intercept made by the middleware. For example when we want CAS to
149
+ authenticate API requests but leave the redirect handling to the client. For this you can use the
150
+ `ignore_intercept_validator`. You need to pass a `Proc` object that will accept a `Rack::Request` object as a parameter.
151
+
152
+ ```ruby
153
+ use Rack::CAS, server_url: '...', ignore_intercept_validator: Proc.new { |req| req.env['HTTP_CONTENT_TYPE'] == 'application/json' }
154
+ use Rack::CAS, server_url: '...', ignore_intercept_validator: Proc.new { |req| req.env['PATH_INFO'] =~ 'api' }
155
+ ```
156
+
114
157
  SSL Cert Verification
115
158
  ---------------------
116
159
 
@@ -1,6 +1,8 @@
1
1
  require 'nokogiri'
2
2
 
3
3
  class CASRequest
4
+ attr_reader :request
5
+
4
6
  def initialize(request)
5
7
  @request = request
6
8
  end
@@ -1,12 +1,13 @@
1
1
  module RackCAS
2
2
  class Configuration
3
- SETTINGS = [:fake, :server_url, :session_store, :exclude_path, :exclude_paths, :extra_attributes_filter, :verify_ssl_cert, :renew, :use_saml_validation]
3
+ SETTINGS = [:fake, :server_url, :session_store, :exclude_path, :exclude_paths, :extra_attributes_filter,
4
+ :verify_ssl_cert, :renew, :use_saml_validation, :ignore_intercept_validator, :exclude_request_validator]
4
5
 
5
6
  SETTINGS.each do |setting|
6
7
  attr_accessor setting
7
8
 
8
9
  define_method "#{setting}?" do
9
- !(send(setting).nil? || send(setting) == [])
10
+ ![nil, false, []].include? send(setting)
10
11
  end
11
12
  end
12
13
 
@@ -24,7 +25,7 @@ module RackCAS
24
25
  raise ArgumentError, "invalid setting: #{setting}"
25
26
  end
26
27
 
27
- self.public_send "#{setting}=", value
28
+ public_send "#{setting}=", value
28
29
  end
29
30
 
30
31
  raise ArgumentError, 'server_url is required' unless server_url?
@@ -15,7 +15,8 @@ module RackCAS
15
15
 
16
16
  private
17
17
 
18
- def get_session(env, sid)
18
+ # Rack 2.0 method
19
+ def find_session(env, sid)
19
20
  if sid.nil?
20
21
  sid = generate_sid
21
22
  data = nil
@@ -31,7 +32,8 @@ module RackCAS
31
32
  [sid, data]
32
33
  end
33
34
 
34
- def set_session(env, sid, session_data, options)
35
+ # Rack 2.0 method
36
+ def write_session(req, sid, session_data, options)
35
37
  cas_ticket = (session_data['cas']['ticket'] unless session_data['cas'].nil?)
36
38
 
37
39
  session = if ActiveRecord.respond_to?(:version) && ActiveRecord.version >= Gem::Version.new('4.0.0')
@@ -46,12 +48,26 @@ module RackCAS
46
48
  success ? session.session_id : false
47
49
  end
48
50
 
49
- def destroy_session(env, sid, options)
51
+ # Rack 2.0 method
52
+ def delete_session(req, sid, options)
50
53
  Session.where(session_id: sid).delete_all
51
54
 
52
55
  options[:drop] ? nil : generate_sid
53
56
  end
54
57
 
58
+ # Rack 1.* method
59
+ alias get_session find_session
60
+
61
+ # Rack 1.* method
62
+ def set_session(env, sid, session_data, options) # rack 1.x compatibilty
63
+ write_session(Rack::Request.new(env), sid, session_data, options)
64
+ end
65
+
66
+ # Rack 1.* method
67
+ def destroy_session(env, sid, options) # rack 1.x compatibilty
68
+ delete_session(Rack::Request.new(env), sid, options)
69
+ end
70
+
55
71
  def pack(data)
56
72
  ::Base64.encode64(Marshal.dump(data)) if data
57
73
  end
@@ -27,7 +27,8 @@ module RackCAS
27
27
 
28
28
  private
29
29
 
30
- def get_session(env, sid)
30
+ # Rack 2.0 method
31
+ def find_session(env, sid)
31
32
  if sid.nil?
32
33
  sid = generate_sid
33
34
  data = nil
@@ -43,7 +44,8 @@ module RackCAS
43
44
  [sid, data]
44
45
  end
45
46
 
46
- def set_session(env, sid, session_data, options)
47
+ # Rack 2.0 method
48
+ def write_session(env, sid, session_data, options)
47
49
  cas_ticket = (session_data['cas']['ticket'] unless session_data['cas'].nil?)
48
50
 
49
51
  session = Session.find_or_initialize_by(_id: sid)
@@ -52,12 +54,26 @@ module RackCAS
52
54
  success ? session.id : false
53
55
  end
54
56
 
55
- def destroy_session(env, sid, options)
57
+ # Rack 2.0 method
58
+ def delete_session(env, sid, options)
56
59
  Session.where(_id: sid).delete
57
60
 
58
61
  options[:drop] ? nil : generate_sid
59
62
  end
60
63
 
64
+ # Rack 1.* method
65
+ alias get_session find_session
66
+
67
+ # Rack 1.* method
68
+ def set_session(env, sid, session_data, options) # rack 1.x compatibilty
69
+ write_session(Rack::Request.new(env), sid, session_data, options)
70
+ end
71
+
72
+ # Rack 1.* method
73
+ def destroy_session(env, sid, options) # rack 1.x compatibilty
74
+ delete_session(Rack::Request.new(env), sid, options)
75
+ end
76
+
61
77
  def pack(data)
62
78
  if defined? Moped::BSON
63
79
  Moped::BSON::Binary.new(:generic, Marshal.dump(data))
@@ -0,0 +1,10 @@
1
+ require 'rack/session/abstract/id'
2
+ require 'rack-cas/session_store/active_record'
3
+
4
+ module Rack
5
+ module Session
6
+ class RackCASActiveRecordStore < Rack::Session::Abstract::ID
7
+ include RackCAS::ActiveRecordStore
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module RackCAS
2
- VERSION = '0.13.0'
2
+ VERSION = '0.14.0'
3
3
  end
@@ -16,9 +16,7 @@ class Rack::CAS
16
16
  request = Rack::Request.new(env)
17
17
  cas_request = CASRequest.new(request)
18
18
 
19
- if cas_request.path_matches? RackCAS.config.exclude_path || RackCAS.config.exclude_paths
20
- return @app.call(env)
21
- end
19
+ return @app.call(env) if exclude_request?(cas_request)
22
20
 
23
21
  if cas_request.ticket_validation?
24
22
  log env, 'rack-cas: Intercepting ticket validation request.'
@@ -51,7 +49,7 @@ class Rack::CAS
51
49
 
52
50
  response = @app.call(env)
53
51
 
54
- if response[0] == 401 # access denied
52
+ if response[0] == 401 && !ignore_intercept?(request) # access denied
55
53
  log env, 'rack-cas: Intercepting 401 access denied response. Redirecting to CAS login.'
56
54
 
57
55
  redirect_to server.login_url(request.url).to_s
@@ -66,6 +64,19 @@ class Rack::CAS
66
64
  @server ||= RackCAS::Server.new(RackCAS.config.server_url)
67
65
  end
68
66
 
67
+ def ignore_intercept?(request)
68
+ return false if (validator = RackCAS.config.ignore_intercept_validator).nil?
69
+ validator.call(request)
70
+ end
71
+
72
+ def exclude_request?(cas_request)
73
+ if (validator = RackCAS.config.exclude_request_validator)
74
+ validator.call(cas_request.request)
75
+ else
76
+ cas_request.path_matches? RackCAS.config.exclude_path || RackCAS.config.exclude_paths
77
+ end
78
+ end
79
+
69
80
  def get_user(service_url, ticket)
70
81
  server.validate_service(service_url, ticket)
71
82
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-cas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Crownoble
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-01 00:00:00.000000000 Z
11
+ date: 2016-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
@@ -84,14 +84,14 @@ dependencies:
84
84
  name: rack-test
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0.6'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0.6'
97
97
  - !ruby/object:Gem::Dependency
@@ -127,6 +127,7 @@ files:
127
127
  - lib/rack-cas/service_validation_response.rb
128
128
  - lib/rack-cas/session_store/active_record.rb
129
129
  - lib/rack-cas/session_store/mongoid.rb
130
+ - lib/rack-cas/session_store/rack/active_record.rb
130
131
  - lib/rack-cas/session_store/rack/mongoid.rb
131
132
  - lib/rack-cas/session_store/rails/active_record.rb
132
133
  - lib/rack-cas/session_store/rails/mongoid.rb
@@ -160,3 +161,4 @@ signing_key:
160
161
  specification_version: 4
161
162
  summary: Rack-based CAS client
162
163
  test_files: []
164
+ has_rdoc: