rack-cas 0.4.3 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17d582ee02fcbcc13c8b2f26387d246872857d49
4
- data.tar.gz: 7c66a26d94195e52f507071655fbe05b8af53f9b
3
+ metadata.gz: 40ea6829e44c2f3fbb046bd53f64eba0a7b0c490
4
+ data.tar.gz: 6acbdc1877f6268ef3d30d6b1c2653dd552d1250
5
5
  SHA512:
6
- metadata.gz: b1f6103cd65c29499b56b617242be29baae1c3c93b18d836d400226ea63d24bcd262fda0a588a05fe6cd67227c7c178de271e7c39a710191c1d6911fb9b5f735
7
- data.tar.gz: ac8fe7c5e196c81a5a00daee6dbda673728326cba6bb8fb262d998dcd2c4b6668753be778af5a0a60aa42dd749677a675224aa90b29dc537f210d072e4c085ca
6
+ metadata.gz: 24871eb8f49e6e7e5a1ffb74d5b3c86b8016e446d32b092f7593e91c6d6fbd5ae4022a54d620ade4167e1b7659509c36ce5d00980a1a393dc0f2a1a2d804472e
7
+ data.tar.gz: da1d0360a7bc1d17fc1367950b4d6986af11a84e610c28673af18b5bf1c647cf794cf797c530ff59686daea2e1f8b408c60ea4966b63336b8d091c2ef53a46d8
data/README.markdown CHANGED
@@ -80,6 +80,22 @@ Add the following to your `config.ru` file:
80
80
 
81
81
  Single sign out support outside of Rails is currently untested. We'll be adding instructions here soon.
82
82
 
83
+ Configuration
84
+ =============
85
+
86
+ Excluding Paths
87
+ ---------------
88
+
89
+ If you have some parts of your app that should not be CAS authenticated (such as an API namespace), just pass `exclude_path` to the middleware. You can pass in a string that matches the beginning of the path, a regular expression or an array of strings and regular expressions.
90
+
91
+ use Rack::CAS, server_url: '...', exclude_path: '/api'
92
+ use Rack::CAS, server_url: '...', exclude_path: /\.json/
93
+ use Rack::CAS, server_url: '...', exclude_paths: ['/api', /\.json/]
94
+
95
+ The same options can be passed to `FakeCAS`.
96
+
97
+ use Rack::FakeCAS, exclude_path: '/api'
98
+
83
99
  Integration
84
100
  ===========
85
101
  Your app should __return a [401 status](http://httpstatus.es/401)__ whenever a request is made that requires authentication. Rack-CAS will catch these responses and attempt to authenticate via your CAS server.
@@ -31,6 +31,16 @@ class CASRequest
31
31
  !!(@request.get? && ticket_param && ticket_param.to_s =~ /\AST\-[^\s]{29}/)
32
32
  end
33
33
 
34
+ def path_matches?(strings_or_regexps)
35
+ Array(strings_or_regexps).any? do |matcher|
36
+ if matcher.is_a? Regexp
37
+ !!(@request.path_info =~ matcher)
38
+ elsif matcher.to_s != ''
39
+ @request.path_info[0...matcher.to_s.length] == matcher.to_s
40
+ end
41
+ end
42
+ end
43
+
34
44
  private
35
45
 
36
46
  def ticket_param
@@ -5,7 +5,7 @@ module RackCAS
5
5
  initializer 'rack_cas.initialize' do |app|
6
6
  if config.rack_cas.fake || (config.rack_cas.fake.nil? && Rails.env.test?)
7
7
  require 'rack/fake_cas'
8
- app.middleware.use Rack::FakeCAS
8
+ app.middleware.use Rack::FakeCAS, config.rack_cas
9
9
  elsif !config.rack_cas.server_url.nil? # for backwards compatibility
10
10
  require 'rack/cas'
11
11
  app.middleware.use Rack::CAS, config.rack_cas
@@ -1,3 +1,3 @@
1
1
  module RackCAS
2
- VERSION = '0.4.3'
2
+ VERSION = '0.5.0'
3
3
  end
data/lib/rack/cas.rb CHANGED
@@ -10,7 +10,7 @@ class Rack::CAS
10
10
  @app = app
11
11
  @server_url = config.delete(:server_url)
12
12
  @session_store = config.delete(:session_store)
13
- @config = config
13
+ @config = config || {}
14
14
 
15
15
  raise ArgumentError, 'server_url is required' if @server_url.nil?
16
16
  if @session_store && !@session_store.respond_to?(:destroy_session_by_cas_ticket)
@@ -22,6 +22,10 @@ class Rack::CAS
22
22
  request = Rack::Request.new(env)
23
23
  cas_request = CASRequest.new(request)
24
24
 
25
+ if cas_request.path_matches? @config[:exclude_paths] || @config[:exclude_path]
26
+ return @app.call(env)
27
+ end
28
+
25
29
  if cas_request.ticket_validation?
26
30
  log env, 'rack-cas: Intercepting ticket validation request.'
27
31
 
data/lib/rack/fake_cas.rb CHANGED
@@ -1,13 +1,19 @@
1
1
  require 'rack'
2
+ require 'rack-cas/cas_request'
2
3
 
3
4
  class Rack::FakeCAS
4
5
  def initialize(app, config={})
5
6
  @app = app
6
- @config = config
7
+ @config = config || {}
7
8
  end
8
9
 
9
10
  def call(env)
10
11
  @request = Rack::Request.new(env)
12
+ cas_request = CASRequest.new(@request)
13
+
14
+ if cas_request.path_matches? @config[:exclude_paths] || @config[:exclude_path]
15
+ return @app.call(env)
16
+ end
11
17
 
12
18
  case @request.path_info
13
19
  when '/login'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-cas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.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: 2013-02-28 00:00:00.000000000 Z
11
+ date: 2013-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack