rack-cas 0.7.0 → 0.7.1
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 +4 -4
- data/lib/rack-cas/service_validation_response.rb +29 -7
- data/lib/rack-cas/version.rb +1 -1
- data/lib/rack/cas.rb +8 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b512d0ffca0a80b935d7f6aaf73c5b7ddc9fea4e
|
4
|
+
data.tar.gz: 0f0e27f8c8a5a30b1dcace4ebfb7da94312fe293
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
55
|
-
|
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
|
data/lib/rack-cas/version.rb
CHANGED
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
|
-
|
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.
|
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-
|
11
|
+
date: 2013-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|