rack-cas 0.2.0 → 0.3.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.
- data/README.markdown +48 -22
- data/lib/generators/cas_session_store_migration_generator.rb +26 -0
- data/lib/generators/templates/migration.rb +18 -0
- data/lib/rack-cas/cas_request.rb +2 -4
- data/lib/rack-cas/session_store/active_record.rb +49 -0
- data/lib/rack-cas/session_store/rack/mongo.rb +1 -1
- data/lib/rack-cas/session_store/rack/mongoid.rb +1 -1
- data/lib/rack-cas/session_store/rails/active_record.rb +10 -0
- data/lib/rack-cas/session_store/rails/mongo.rb +1 -1
- data/lib/rack-cas/session_store/rails/mongoid.rb +1 -1
- data/lib/rack-cas/version.rb +1 -1
- metadata +6 -2
data/README.markdown
CHANGED
@@ -6,7 +6,7 @@ Features
|
|
6
6
|
========
|
7
7
|
* __Rack based__
|
8
8
|
* __Framework independent__
|
9
|
-
Works with but doesn't depend on Rails, Sinatra, etc.
|
9
|
+
Works with, but doesn't depend on Rails, Sinatra, etc.
|
10
10
|
* __Minimal dependencies__
|
11
11
|
Current gem dependencies are [rack](http://rubygems.org/gems/rack), [addressable](http://rubygems.org/gems/addressable) and [nokogiri](http://rubygems.org/gems/nokogiri).
|
12
12
|
* __Supports CAS extra attributes__
|
@@ -14,10 +14,6 @@ Extra attributes are a mess though. So let me know if your brand of CAS server i
|
|
14
14
|
* __Single sign out__
|
15
15
|
One of the included session stores must be used.
|
16
16
|
|
17
|
-
Coming Soon
|
18
|
-
===========
|
19
|
-
* __Single sign out compatible session store for Active Record__
|
20
|
-
|
21
17
|
Requirements
|
22
18
|
============
|
23
19
|
* Ruby >= 1.9.2
|
@@ -26,38 +22,68 @@ Requirements
|
|
26
22
|
Installation
|
27
23
|
============
|
28
24
|
|
29
|
-
|
25
|
+
Rails
|
26
|
+
-----
|
27
|
+
|
28
|
+
Add `gem 'rack-cas'` to your [`Gemfile`](http://gembundler.com/gemfile.html) and run `bundle install`
|
29
|
+
|
30
|
+
Create `config/initializers/rack-cas.rb` with the following:
|
31
|
+
|
32
|
+
require 'rack/cas'
|
33
|
+
YourApp::Application.config.middleware.use Rack::CAS, server_url: 'https://login.example.com/cas'
|
34
|
+
|
35
|
+
### Single Sign Out ###
|
30
36
|
|
31
|
-
|
37
|
+
If you wish to enable [single sign out](https://wiki.jasig.org/display/CASUM/Single+Sign+Out) you'll need to modify your configuration as below.
|
32
38
|
|
33
|
-
|
39
|
+
#### Active Record ####
|
34
40
|
|
35
|
-
|
41
|
+
Set the `session_store` in `config/initialiers/rack-cas.rb`
|
36
42
|
|
37
43
|
require 'rack/cas'
|
38
|
-
|
44
|
+
require 'rack-cas/session_store/active_record'
|
45
|
+
YourApp::Application.config.middleware.use Rack::CAS,
|
46
|
+
server_url: 'https://login.example.com/cas',
|
47
|
+
session_store: RackCAS::ActiveRecordStore
|
48
|
+
|
49
|
+
Edit your `config/initializers/session_store.rb` file with the following:
|
50
|
+
|
51
|
+
require 'rack-cas/session_store/rails/active_record'
|
52
|
+
YourApp::Application.config.session_store :rack_cas_active_record_store
|
39
53
|
|
40
|
-
|
41
|
-
---------------
|
42
|
-
Support for [single sign out](https://wiki.jasig.org/display/CASUM/Single+Sign+Out) requires the use of one of the included session stores listed below.
|
54
|
+
Run:
|
43
55
|
|
44
|
-
|
56
|
+
rails generate cas_session_store_migration
|
57
|
+
rake db:migrate
|
45
58
|
|
46
|
-
|
59
|
+
#### Mongoid ####
|
60
|
+
|
61
|
+
Set the `session_store` in `config/initialiers/rack-cas.rb`
|
62
|
+
|
63
|
+
require 'rack/cas'
|
64
|
+
require 'rack-cas/session_store/mongoid'
|
65
|
+
YourApp::Application.config.middleware.use Rack::CAS,
|
66
|
+
server_url: 'https://login.example.com/cas',
|
67
|
+
session_store: RackCAS::MongoidStore
|
68
|
+
|
69
|
+
Edit your `config/initializers/session_store.rb` file with the following:
|
47
70
|
|
48
71
|
require 'rack-cas/session_store/rails/mongoid'
|
49
|
-
YourApp::Application.config.session_store :
|
72
|
+
YourApp::Application.config.session_store :rack_cas_mongoid_store
|
50
73
|
|
51
|
-
|
74
|
+
Sinatra and Other Rack-Compatible Frameworks
|
75
|
+
--------------------------------------------
|
52
76
|
|
53
|
-
|
54
|
-
use Rack::Session::MongoidStore
|
77
|
+
Add `gem 'rack-cas'` to your [`Gemfile`](http://gembundler.com/gemfile.html) and run `bundle install`
|
55
78
|
|
56
|
-
|
79
|
+
Add the following to your `config.ru` file:
|
57
80
|
|
58
81
|
require 'rack/cas'
|
59
|
-
|
60
|
-
|
82
|
+
use Rack::CAS, server_url: 'https://login.example.com/cas'
|
83
|
+
|
84
|
+
### Single Sign Out ###
|
85
|
+
|
86
|
+
Single sign out support outside of Rails is currently untested. We'll be adding instructions here soon.
|
61
87
|
|
62
88
|
Integration
|
63
89
|
===========
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
class CasSessionStoreMigrationGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
|
7
|
+
desc 'Creates a new CAS session store migration file'
|
8
|
+
|
9
|
+
def self.source_root
|
10
|
+
File.expand_path('../templates', __FILE__)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.next_migration_number(dirname)
|
14
|
+
if ActiveRecord::Base.timestamped_migrations
|
15
|
+
migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
16
|
+
migration_number += 1
|
17
|
+
migration_number.to_s
|
18
|
+
else
|
19
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_migration_file
|
24
|
+
migration_template 'migration.rb', 'db/migrate/create_rack_cas_sessions'
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateRackCasSessions < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :sessions do |t|
|
4
|
+
t.string :session_id, :null => false
|
5
|
+
t.string :cas_ticket
|
6
|
+
t.text :data
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index :sessions, :session_id
|
11
|
+
add_index :sessions, :cas_ticket
|
12
|
+
add_index :sessions, :updated_at
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.down
|
16
|
+
drop_table :sessions
|
17
|
+
end
|
18
|
+
end
|
data/lib/rack-cas/cas_request.rb
CHANGED
@@ -7,10 +7,8 @@ class CASRequest
|
|
7
7
|
|
8
8
|
def ticket
|
9
9
|
@ticket ||= if single_sign_out?
|
10
|
-
xml = Nokogiri::XML(@request.params['logoutRequest'])
|
11
|
-
|
12
|
-
end
|
13
|
-
node = xml.at('/LogoutRequest/SessionIndex')
|
10
|
+
xml = Nokogiri::XML(@request.params['logoutRequest'])
|
11
|
+
node = xml.root.children.find { |c| c.name =~ /SessionIndex/i }
|
14
12
|
node.text unless node.nil?
|
15
13
|
else
|
16
14
|
@request.params['ticket']
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module RackCAS
|
2
|
+
module ActiveRecordStore
|
3
|
+
class Session < ActiveRecord::Base
|
4
|
+
attr_accessible :id, :data, :cas_ticket
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.destroy_session_by_cas_ticket(cas_ticket)
|
8
|
+
affected = Session.delete_all(cas_ticket: cas_ticket)
|
9
|
+
affected == 1
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def get_session(env, sid)
|
15
|
+
if sid.nil?
|
16
|
+
sid = generate_sid
|
17
|
+
data = nil
|
18
|
+
else
|
19
|
+
session = Session.where(session_id: sid).first || {}
|
20
|
+
data = unpack(session['data'])
|
21
|
+
end
|
22
|
+
|
23
|
+
[sid, data]
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_session(env, sid, session_data, options)
|
27
|
+
cas_ticket = (session_data['cas']['ticket'] unless session_data['cas'].nil?)
|
28
|
+
|
29
|
+
session = Session.find_or_initialize_by_session_id(sid)
|
30
|
+
success = session.update_attributes(data: pack(session_data), cas_ticket: cas_ticket)
|
31
|
+
|
32
|
+
success ? session.session_id : false
|
33
|
+
end
|
34
|
+
|
35
|
+
def destroy_session(env, sid, options)
|
36
|
+
session = Session.where(session_id: sid).delete
|
37
|
+
|
38
|
+
options[:drop] ? nil : generate_sid
|
39
|
+
end
|
40
|
+
|
41
|
+
def pack(data)
|
42
|
+
::Base64.encode64(Marshal.dump(data)) if data
|
43
|
+
end
|
44
|
+
|
45
|
+
def unpack(data)
|
46
|
+
Marshal.load(::Base64.decode64(data)) if data
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/rack-cas/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-cas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -67,12 +67,16 @@ extra_rdoc_files: []
|
|
67
67
|
files:
|
68
68
|
- README.markdown
|
69
69
|
- MIT-LICENSE
|
70
|
+
- lib/generators/templates/migration.rb
|
71
|
+
- lib/generators/cas_session_store_migration_generator.rb
|
70
72
|
- lib/rack-cas.rb
|
71
73
|
- lib/rack-cas/url.rb
|
72
74
|
- lib/rack-cas/version.rb
|
73
75
|
- lib/rack-cas/session_store/rails/mongo.rb
|
76
|
+
- lib/rack-cas/session_store/rails/active_record.rb
|
74
77
|
- lib/rack-cas/session_store/rails/mongoid.rb
|
75
78
|
- lib/rack-cas/session_store/mongo.rb
|
79
|
+
- lib/rack-cas/session_store/active_record.rb
|
76
80
|
- lib/rack-cas/session_store/rack/mongo.rb
|
77
81
|
- lib/rack-cas/session_store/rack/mongoid.rb
|
78
82
|
- lib/rack-cas/session_store/mongoid.rb
|