cas-client 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -6
- data/lib/cas-client.rb +9 -0
- data/lib/cas/client/configuration.rb +12 -0
- data/lib/cas/client/middleware.rb +21 -17
- data/lib/cas/client/response.rb +16 -13
- data/lib/cas/client/server.rb +11 -3
- data/lib/cas/client/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd0f12781655ef893c92fb9b5275ccc32e42b1304d82eb8f13cab07b4a458fb8
|
4
|
+
data.tar.gz: 92277075f6dc6fc4a1507a36baf5ea0a8e1d3380ce940fdaad3abc14dc138a85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e003ef0e3ccdcf50de97fbf30abdc0aba1a2d267fac0ab393191b0faa4a680313920eb304a5dd6d3fb7700ae6f787e3e906368d6e0345113952228480d5bb97
|
7
|
+
data.tar.gz: d6d0a79b004c54ad886660efa7618f89e576802b0a79ccc201cc2ed77f19f58a7a05016c81bf702c4e320e6e01bf84f652b9e4bc6930c34a5d2206a57a8c5911
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ TODO: Delete this and the text above, and describe your gem
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem '
|
12
|
+
gem 'cas-client'
|
13
13
|
```
|
14
14
|
|
15
15
|
And then execute:
|
@@ -18,17 +18,25 @@ And then execute:
|
|
18
18
|
|
19
19
|
Or install it yourself as:
|
20
20
|
|
21
|
-
$ gem install
|
21
|
+
$ gem install cas-client
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
25
|
Configure middleware from the specific environment file
|
26
26
|
|
27
27
|
```ruby
|
28
|
-
config.middleware.insert_after ActionDispatch::Session::CookieStore, Cas::Client::Middleware
|
29
|
-
server_url
|
30
|
-
extra_attributes
|
31
|
-
|
28
|
+
config.middleware.insert_after ActionDispatch::Session::CookieStore, Cas::Client::Middleware do |config|
|
29
|
+
config.server_url = "https://staging.cas-server"
|
30
|
+
config.extra_attributes = [:first_name, :last_name, :email]
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
Configure global/non-environment specific options
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
Cas::Client.configure do |config|
|
38
|
+
config.extra_attributes = [:first_name, :last_name, :email]
|
39
|
+
end
|
32
40
|
```
|
33
41
|
|
34
42
|
## Development
|
data/lib/cas-client.rb
CHANGED
@@ -4,8 +4,17 @@ require 'cas/client/response'
|
|
4
4
|
require 'cas/client/server'
|
5
5
|
require 'cas/client/url'
|
6
6
|
require 'cas/client/version'
|
7
|
+
require 'cas/client/configuration'
|
7
8
|
|
8
9
|
module Cas
|
9
10
|
module Client
|
11
|
+
class << self
|
12
|
+
attr_accessor :configuration
|
13
|
+
|
14
|
+
def configure
|
15
|
+
self.configuration ||= Configuration.new
|
16
|
+
yield configuration
|
17
|
+
end
|
18
|
+
end
|
10
19
|
end
|
11
20
|
end
|
@@ -3,25 +3,25 @@ require 'net/http'
|
|
3
3
|
module Cas
|
4
4
|
module Client
|
5
5
|
class Middleware
|
6
|
-
def initialize(app,
|
6
|
+
def initialize(app, &block)
|
7
7
|
@app = app
|
8
|
-
|
9
|
-
|
10
|
-
@request = nil
|
8
|
+
|
9
|
+
Cas::Client.configure(&block) if block_given?
|
11
10
|
end
|
12
11
|
|
13
12
|
def call(env)
|
14
13
|
@request = Rack::Request.new(env)
|
15
|
-
server = Cas::Client::Server.new(@config[:server_url])
|
16
14
|
status, headers, rack_body = @app.call(env)
|
17
|
-
log(env, "Middleware called. Status: #{status}, Headers: #{headers}")
|
18
15
|
|
19
16
|
if ticket_validation?
|
20
|
-
attributes = server.validate_service(self_url
|
21
|
-
set_session(
|
22
|
-
|
17
|
+
attributes = server.validate_service(self_url, ticket_param)
|
18
|
+
set_session(attributes)
|
19
|
+
|
20
|
+
return redirect_to(self_url)
|
23
21
|
elsif status == 401
|
24
|
-
|
22
|
+
log(env, "Cas::Client::Middleware detected 401, Status: #{status}, Headers: #{headers}\n")
|
23
|
+
|
24
|
+
return redirect_to(server.login_url({ service_url: self_url }))
|
25
25
|
else
|
26
26
|
return [status, headers, rack_body]
|
27
27
|
end
|
@@ -29,28 +29,32 @@ module Cas
|
|
29
29
|
|
30
30
|
private
|
31
31
|
|
32
|
-
def
|
33
|
-
|
32
|
+
def server
|
33
|
+
@_server ||= Cas::Client::Server.new
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_session(attributes)
|
37
|
+
@request.session['cas'] = attributes
|
34
38
|
end
|
35
39
|
|
36
40
|
def redirect_to(url, status=302)
|
37
41
|
[ status, { 'Location' => url, 'Content-Type' => 'text/plain' }, ["Redirecting you to #{url}"] ]
|
38
42
|
end
|
39
43
|
|
40
|
-
def self_url
|
41
|
-
|
44
|
+
def self_url
|
45
|
+
@request.url.split('?')[0]
|
42
46
|
end
|
43
47
|
|
44
48
|
def ticket_validation?
|
45
|
-
|
49
|
+
@request.get? && param_service_ticket?
|
46
50
|
end
|
47
51
|
|
48
52
|
def ticket_param
|
49
53
|
@request.params['ticket']
|
50
54
|
end
|
51
55
|
|
52
|
-
def
|
53
|
-
|
56
|
+
def param_service_ticket?
|
57
|
+
ticket_param.to_s =~ /\AST\-[^\s]{1,253}\Z/
|
54
58
|
end
|
55
59
|
|
56
60
|
def log(env, message, level = :info)
|
data/lib/cas/client/response.rb
CHANGED
@@ -11,21 +11,21 @@ module Cas
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def success?
|
14
|
-
@response.to_s.match(
|
14
|
+
@response.to_s.match(/<#{xml_namespace}:authenticationSuccess>/)
|
15
15
|
end
|
16
16
|
|
17
|
-
def all_attributes
|
18
|
-
|
17
|
+
def all_attributes
|
18
|
+
get_user.merge!(get_extra_attributes)
|
19
19
|
end
|
20
20
|
|
21
21
|
protected
|
22
22
|
|
23
23
|
def xml_namespace
|
24
|
-
|
24
|
+
Cas::Client.configuration.cas_namespace
|
25
25
|
end
|
26
26
|
|
27
|
-
def get_user
|
28
|
-
match =
|
27
|
+
def get_user
|
28
|
+
match = @response.match(/<#{xml_namespace}:user>(.*)<\/#{xml_namespace}:user>/)
|
29
29
|
if match
|
30
30
|
{ user: match.captures.first }
|
31
31
|
else # Failed login
|
@@ -33,15 +33,18 @@ module Cas
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def get_extra_attributes
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
def get_extra_attributes
|
37
|
+
{}.tap do |attributes|
|
38
|
+
Cas::Client.configuration.extra_attributes.each do |ea|
|
39
|
+
match = @response.match(/<#{xml_namespace}:#{ea}>(.*)<\/#{xml_namespace}:#{ea}>/)
|
40
|
+
|
41
|
+
if match
|
42
|
+
attributes[ea] = match.captures.first
|
43
|
+
else
|
44
|
+
attributes
|
45
|
+
end
|
42
46
|
end
|
43
47
|
end
|
44
|
-
attributes
|
45
48
|
end
|
46
49
|
end
|
47
50
|
end
|
data/lib/cas/client/server.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Cas
|
2
2
|
module Client
|
3
3
|
class Server
|
4
|
-
def initialize
|
4
|
+
def initialize
|
5
5
|
@url = Cas::Client::URL.new(server_url)
|
6
6
|
end
|
7
7
|
|
@@ -21,15 +21,23 @@ module Cas
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
24
|
+
def self.logout_url(options={})
|
25
|
+
new.logout_url(options).to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
def validate_service(service_url, ticket)
|
25
29
|
uri = Cas::Client::URL.new(validate_service_url(service_url, ticket)).to_uri
|
26
30
|
res = Cas::Client::Response.new(uri)
|
27
31
|
res.validate_service_response
|
28
|
-
res.all_attributes
|
32
|
+
res.all_attributes
|
29
33
|
end
|
30
34
|
|
31
35
|
protected
|
32
36
|
|
37
|
+
def server_url
|
38
|
+
Cas::Client.configuration.server_url
|
39
|
+
end
|
40
|
+
|
33
41
|
def validate_service_url(service_url, ticket)
|
34
42
|
protocol_path = "p3"
|
35
43
|
server_url = @url
|
data/lib/cas/client/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cas-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Donavan White
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- bin/setup
|
87
87
|
- cas-client.gemspec
|
88
88
|
- lib/cas-client.rb
|
89
|
+
- lib/cas/client/configuration.rb
|
89
90
|
- lib/cas/client/middleware.rb
|
90
91
|
- lib/cas/client/response.rb
|
91
92
|
- lib/cas/client/server.rb
|