rack-cas 0.7.0 → 0.7.1

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: f8b3f4f0aa58877ed7a2d4c3461f29cf61627373
4
- data.tar.gz: 1957151a852757147c97e0c8bffcb2d3f9388f44
3
+ metadata.gz: b512d0ffca0a80b935d7f6aaf73c5b7ddc9fea4e
4
+ data.tar.gz: 0f0e27f8c8a5a30b1dcace4ebfb7da94312fe293
5
5
  SHA512:
6
- metadata.gz: cae156d6cad7408f836e3bdb206b287c26af315d1364d9addba79cad801f2e19347b57be115940d900cf0b572d0340c6bf100fa30175138ea474cd4b1d9bd31f
7
- data.tar.gz: f343a2ea383015d349955d4a69278065e0ed03888564bddd837de5352c6b64fe12838001033ccfe7cf5db6ab861f1c010ae77feb9757486f51e62a1d56f846c3
6
+ metadata.gz: 181b529b5eb80f72e4b47b7b501fbb56424dd344170e4fab0ea60d7850f9936f05309eaa141af10cc5ae466b5de27340a8d1bea6cd5742a7127b5290a451089c
7
+ data.tar.gz: 65c877333d00ee77ebd0356a90198d63f10582667a710fdc8e10402c1fa618283d863aee554769fa2426b445c10ff4c8a6d1abf7aaff241ceb97e93f5bc80844
@@ -1,9 +1,12 @@
1
1
  module RackCAS
2
2
  class ServiceValidationResponse
3
3
  class AuthenticationFailure < StandardError; end
4
+ class RequestInvalidError < AuthenticationFailure; end
5
+ class TicketInvalidError < AuthenticationFailure; end
6
+ class ServiceInvalidError < AuthenticationFailure; end
4
7
 
5
8
  REQUEST_HEADERS = { 'Accept' => '*/*' }
6
-
9
+
7
10
  def initialize(url)
8
11
  @url = URL.parse(url)
9
12
  end
@@ -12,7 +15,16 @@ module RackCAS
12
15
  if success?
13
16
  xml.xpath('/cas:serviceResponse/cas:authenticationSuccess/cas:user').text
14
17
  else
15
- raise AuthenticationFailure, failure_message
18
+ case failure_code
19
+ when 'INVALID_REQUEST'
20
+ raise RequestInvalidError, failure_message
21
+ when 'INVALID_TICKET'
22
+ raise TicketInvalidError, failure_message
23
+ when 'INVALID_SERVICE'
24
+ raise ServiceInvalidError, failure_message
25
+ else
26
+ raise AuthenticationFailure, failure_message
27
+ end
16
28
  end
17
29
  end
18
30
 
@@ -50,16 +62,26 @@ module RackCAS
50
62
  @success ||= !!xml.at('/cas:serviceResponse/cas:authenticationSuccess')
51
63
  end
52
64
 
65
+ def authentication_failure
66
+ @authentication_failure ||= xml.at('/cas:serviceResponse/cas:authenticationFailure')
67
+ end
68
+
53
69
  def failure_message
54
- if node = xml.at('/cas:serviceResponse/cas:authenticationFailure')
55
- node.text.strip
70
+ if authentication_failure
71
+ authentication_failure.text.strip
72
+ end
73
+ end
74
+
75
+ def failure_code
76
+ if authentication_failure
77
+ authentication_failure['code']
56
78
  end
57
79
  end
58
80
 
59
81
  def response
60
82
  require 'net/http'
61
83
  return @response unless @response.nil?
62
-
84
+
63
85
  http = Net::HTTP.new(@url.host, @url.inferred_port)
64
86
  http.use_ssl = true if @url.scheme == 'https'
65
87
 
@@ -72,8 +94,8 @@ module RackCAS
72
94
 
73
95
  def xml
74
96
  return @xml unless @xml.nil?
75
-
97
+
76
98
  @xml = Nokogiri::XML(response.body)
77
99
  end
78
100
  end
79
- end
101
+ end
@@ -1,3 +1,3 @@
1
1
  module RackCAS
2
- VERSION = '0.7.0'
2
+ VERSION = '0.7.1'
3
3
  end
data/lib/rack/cas.rb CHANGED
@@ -23,13 +23,19 @@ class Rack::CAS
23
23
  cas_request = CASRequest.new(request)
24
24
 
25
25
  if cas_request.path_matches? @config[:exclude_paths] || @config[:exclude_path]
26
- return @app.call(env)
26
+ return @app.call(env)
27
27
  end
28
28
 
29
29
  if cas_request.ticket_validation?
30
30
  log env, 'rack-cas: Intercepting ticket validation request.'
31
31
 
32
- user, extra_attrs = get_user(request.url, cas_request.ticket)
32
+ begin
33
+ user, extra_attrs = get_user(request.url, cas_request.ticket)
34
+ rescue RackCAS::ServiceValidationResponse::TicketInvalidError
35
+ log env, 'rack-cas: Invalid ticket. Redirecting to CAS login.'
36
+
37
+ return redirect_to server.login_url(cas_request.service_url).to_s
38
+ end
33
39
 
34
40
  store_session request, user, cas_request.ticket, extra_attrs
35
41
  return redirect_to cas_request.service_url
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.7.0
4
+ version: 0.7.1
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-03-22 00:00:00.000000000 Z
11
+ date: 2013-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack