devise_bushido_authenticatable 1.0.0.alpha10

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.
Files changed (47) hide show
  1. data/.project +12 -0
  2. data/Gemfile +22 -0
  3. data/Gemfile.lock +169 -0
  4. data/README.md +114 -0
  5. data/Rakefile +46 -0
  6. data/VERSION +1 -0
  7. data/app/controllers/devise/cas_sessions_controller.rb +52 -0
  8. data/app/views/devise/cas_sessions/new.html.erb +1 -0
  9. data/app/views/devise/cas_sessions/unregistered.html.erb +2 -0
  10. data/devise_cas_authenticatable.gemspec +118 -0
  11. data/lib/devise_cas_authenticatable/exceptions.rb +10 -0
  12. data/lib/devise_cas_authenticatable/model.rb +56 -0
  13. data/lib/devise_cas_authenticatable/routes.rb +35 -0
  14. data/lib/devise_cas_authenticatable/schema.rb +15 -0
  15. data/lib/devise_cas_authenticatable/strategy.rb +49 -0
  16. data/lib/devise_cas_authenticatable.rb +93 -0
  17. data/rails/init.rb +1 -0
  18. data/spec/routes_spec.rb +20 -0
  19. data/spec/scenario/.gitignore +4 -0
  20. data/spec/scenario/app/controllers/application_controller.rb +3 -0
  21. data/spec/scenario/app/controllers/home_controller.rb +7 -0
  22. data/spec/scenario/app/models/user.rb +3 -0
  23. data/spec/scenario/app/views/layouts/application.html.erb +17 -0
  24. data/spec/scenario/config/application.rb +38 -0
  25. data/spec/scenario/config/boot.rb +13 -0
  26. data/spec/scenario/config/castronaut.yml +32 -0
  27. data/spec/scenario/config/database.yml +22 -0
  28. data/spec/scenario/config/environment.rb +5 -0
  29. data/spec/scenario/config/environments/development.rb +26 -0
  30. data/spec/scenario/config/environments/production.rb +49 -0
  31. data/spec/scenario/config/environments/test.rb +35 -0
  32. data/spec/scenario/config/initializers/backtrace_silencers.rb +7 -0
  33. data/spec/scenario/config/initializers/devise.rb +3 -0
  34. data/spec/scenario/config/initializers/inflections.rb +10 -0
  35. data/spec/scenario/config/initializers/mime_types.rb +5 -0
  36. data/spec/scenario/config/initializers/secret_token.rb +7 -0
  37. data/spec/scenario/config/initializers/session_store.rb +8 -0
  38. data/spec/scenario/config/locales/en.yml +5 -0
  39. data/spec/scenario/config/routes.rb +8 -0
  40. data/spec/scenario/config/rubycas-server.yml +13 -0
  41. data/spec/scenario/config.ru +4 -0
  42. data/spec/scenario/db/migrate/20100401102949_create_tables.rb +14 -0
  43. data/spec/scenario/public/.gitkeep +0 -0
  44. data/spec/spec_helper.rb +22 -0
  45. data/spec/strategy_spec.rb +96 -0
  46. data/spec/support/migrations.rb +4 -0
  47. metadata +202 -0
data/.project ADDED
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>devise_cas_authenticatable</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ </buildSpec>
9
+ <natures>
10
+ <nature>org.radrails.rails.core.railsnature</nature>
11
+ </natures>
12
+ </projectDescription>
data/Gemfile ADDED
@@ -0,0 +1,22 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'devise'
4
+
5
+ group :development do
6
+ gem 'linecache', '0.43', :platforms => :mri_18
7
+ gem 'ruby-debug', :platforms => :mri_18
8
+ gem 'ruby-debug19', :platforms => :mri_19
9
+ gem "jeweler"
10
+ end
11
+
12
+ group :test do
13
+ gem "rails", ">= 3.0.7"
14
+ gem "rspec-rails", ">= 2.5.0"
15
+ gem "mocha"
16
+ gem "shoulda"
17
+ gem "sqlite3-ruby"
18
+ gem "sham_rack"
19
+ gem "capybara"
20
+ gem 'crypt-isaac'
21
+ gem 'launchy'
22
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,169 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.7)
6
+ actionpack (= 3.0.7)
7
+ mail (~> 2.2.15)
8
+ actionpack (3.0.7)
9
+ activemodel (= 3.0.7)
10
+ activesupport (= 3.0.7)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.5.0)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.14)
16
+ rack-test (~> 0.5.7)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.7)
19
+ activesupport (= 3.0.7)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.5.0)
22
+ activerecord (3.0.7)
23
+ activemodel (= 3.0.7)
24
+ activesupport (= 3.0.7)
25
+ arel (~> 2.0.2)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.7)
28
+ activemodel (= 3.0.7)
29
+ activesupport (= 3.0.7)
30
+ activesupport (3.0.7)
31
+ archive-tar-minitar (0.5.2)
32
+ arel (2.0.9)
33
+ bcrypt-ruby (2.1.4)
34
+ builder (2.1.2)
35
+ capybara (0.4.1.1)
36
+ celerity (>= 0.7.9)
37
+ culerity (>= 0.2.4)
38
+ mime-types (>= 1.16)
39
+ nokogiri (>= 1.3.3)
40
+ rack (>= 1.0.0)
41
+ rack-test (>= 0.5.4)
42
+ selenium-webdriver (>= 0.0.27)
43
+ xpath (~> 0.1.3)
44
+ celerity (0.8.7)
45
+ childprocess (0.1.6)
46
+ ffi (~> 0.6.3)
47
+ columnize (0.3.1)
48
+ configuration (1.2.0)
49
+ crypt-isaac (0.9.1)
50
+ culerity (0.2.15)
51
+ devise (1.3.4)
52
+ bcrypt-ruby (~> 2.1.2)
53
+ orm_adapter (~> 0.0.3)
54
+ warden (~> 1.0.3)
55
+ diff-lcs (1.1.2)
56
+ erubis (2.6.6)
57
+ abstract (>= 1.0.0)
58
+ ffi (0.6.3)
59
+ rake (>= 0.8.7)
60
+ git (1.2.5)
61
+ i18n (0.5.0)
62
+ jeweler (1.5.2)
63
+ bundler (~> 1.0.0)
64
+ git (>= 1.2.5)
65
+ rake
66
+ json_pure (1.5.0)
67
+ launchy (0.3.7)
68
+ configuration (>= 0.0.5)
69
+ rake (>= 0.8.1)
70
+ linecache (0.43)
71
+ linecache19 (0.5.12)
72
+ ruby_core_source (>= 0.1.4)
73
+ mail (2.2.19)
74
+ activesupport (>= 2.3.6)
75
+ i18n (>= 0.4.0)
76
+ mime-types (~> 1.16)
77
+ treetop (~> 1.4.8)
78
+ mime-types (1.16)
79
+ mocha (0.9.10)
80
+ rake
81
+ nokogiri (1.4.4)
82
+ orm_adapter (0.0.5)
83
+ polyglot (0.3.1)
84
+ rack (1.2.2)
85
+ rack-mount (0.6.14)
86
+ rack (>= 1.0.0)
87
+ rack-test (0.5.7)
88
+ rack (>= 1.0)
89
+ rails (3.0.7)
90
+ actionmailer (= 3.0.7)
91
+ actionpack (= 3.0.7)
92
+ activerecord (= 3.0.7)
93
+ activeresource (= 3.0.7)
94
+ activesupport (= 3.0.7)
95
+ bundler (~> 1.0)
96
+ railties (= 3.0.7)
97
+ railties (3.0.7)
98
+ actionpack (= 3.0.7)
99
+ activesupport (= 3.0.7)
100
+ rake (>= 0.8.7)
101
+ thor (~> 0.14.4)
102
+ rake (0.8.7)
103
+ rspec (2.5.0)
104
+ rspec-core (~> 2.5.0)
105
+ rspec-expectations (~> 2.5.0)
106
+ rspec-mocks (~> 2.5.0)
107
+ rspec-core (2.5.2)
108
+ rspec-expectations (2.5.0)
109
+ diff-lcs (~> 1.1.2)
110
+ rspec-mocks (2.5.0)
111
+ rspec-rails (2.5.0)
112
+ actionpack (~> 3.0)
113
+ activesupport (~> 3.0)
114
+ railties (~> 3.0)
115
+ rspec (~> 2.5.0)
116
+ ruby-debug (0.10.4)
117
+ columnize (>= 0.1)
118
+ ruby-debug-base (~> 0.10.4.0)
119
+ ruby-debug-base (0.10.4)
120
+ linecache (>= 0.3)
121
+ ruby-debug-base19 (0.11.25)
122
+ columnize (>= 0.3.1)
123
+ linecache19 (>= 0.5.11)
124
+ ruby_core_source (>= 0.1.4)
125
+ ruby-debug19 (0.11.6)
126
+ columnize (>= 0.3.1)
127
+ linecache19 (>= 0.5.11)
128
+ ruby-debug-base19 (>= 0.11.19)
129
+ ruby_core_source (0.1.5)
130
+ archive-tar-minitar (>= 0.5.2)
131
+ rubyzip (0.9.4)
132
+ selenium-webdriver (0.1.2)
133
+ childprocess (~> 0.1.5)
134
+ ffi (~> 0.6.3)
135
+ json_pure
136
+ rubyzip
137
+ sham_rack (1.3.3)
138
+ rack
139
+ shoulda (2.11.3)
140
+ sqlite3 (1.3.3)
141
+ sqlite3-ruby (1.3.3)
142
+ sqlite3 (>= 1.3.3)
143
+ thor (0.14.6)
144
+ treetop (1.4.9)
145
+ polyglot (>= 0.3.1)
146
+ tzinfo (0.3.27)
147
+ warden (1.0.4)
148
+ rack (>= 1.0)
149
+ xpath (0.1.3)
150
+ nokogiri (~> 1.3)
151
+
152
+ PLATFORMS
153
+ ruby
154
+
155
+ DEPENDENCIES
156
+ capybara
157
+ crypt-isaac
158
+ devise
159
+ jeweler
160
+ launchy
161
+ linecache (= 0.43)
162
+ mocha
163
+ rails (>= 3.0.7)
164
+ rspec-rails (>= 2.5.0)
165
+ ruby-debug
166
+ ruby-debug19
167
+ sham_rack
168
+ shoulda
169
+ sqlite3-ruby
data/README.md ADDED
@@ -0,0 +1,114 @@
1
+ devise_cas_authenticatable
2
+ ==========================
3
+
4
+ Written by Nat Budin, tweaked by others.<br/>
5
+ Taking a lot of inspiration from [devise_ldap_authenticatable](http://github.com/cschiewek/devise_ldap_authenticatable)
6
+
7
+ devise_cas_authenticatable is [CAS](http://www.jasig.org/cas) single sign-on support for
8
+ [Devise](http://github.com/plataformatec/devise) applications. It acts as a replacement for
9
+ database_authenticatable. It builds on [rubycas-client](http://github.com/gunark/rubycas-client)
10
+ and should support just about any conformant CAS server (although I have personally tested it
11
+ using [rubycas-server](http://github.com/gunark/rubycas-server)).
12
+
13
+ Requirements
14
+ ------------
15
+
16
+ - Rails 2.3 or 3.0
17
+ - Devise 1.0 or greater
18
+ - rubycas-client
19
+
20
+ Installation
21
+ ------------
22
+
23
+ gem install --pre devise_cas_authenticatable
24
+
25
+ and in your config/environment.rb (on Rails 2.3):
26
+
27
+ config.gem 'devise', :version => '~> 1.0.6'
28
+ config.gem 'devise_cas_authenticatable'
29
+
30
+ or Gemfile (Rails 3.0):
31
+
32
+ gem 'devise'
33
+ gem 'devise_cas_authenticatable'
34
+
35
+ Example
36
+ -------
37
+
38
+ I've modified the devise_example application to work with this gem. You can find the results
39
+ [here](http://github.com/nbudin/devise_cas_example).
40
+
41
+ Setup
42
+ -----
43
+
44
+ Once devise\_cas\_authenticatable is installed, add the following to your user model:
45
+
46
+ devise :cas_authenticatable
47
+
48
+ You can also add other modules such as token_authenticatable, trackable, etc. Please do not
49
+ add database_authenticatable as this module is intended to replace it.
50
+
51
+ You'll also need to set up the database schema for this:
52
+
53
+ create_table :users do |t|
54
+ t.cas_authenticatable
55
+ end
56
+
57
+ and, optionally, indexes:
58
+
59
+ add_index :users, :username, :unique => true
60
+
61
+ Finally, you'll need to add some configuration to your config/initializers/devise.rb in order
62
+ to tell your app how to talk to your CAS server:
63
+
64
+ Devise.setup do |config|
65
+ ...
66
+ config.cas_base_url = "https://cas.myorganization.com"
67
+
68
+ # you can override these if you need to, but cas_base_url is usually enough
69
+ # config.cas_login_url = "https://cas.myorganization.com/login"
70
+ # config.cas_logout_url = "https://cas.myorganization.com/logout"
71
+ # config.cas_validate_url = "https://cas.myorganization.com/serviceValidate"
72
+
73
+ # By default, devise_cas_authenticatable will create users. If you would rather
74
+ # require user records to already exist locally before they can authenticate via
75
+ # CAS, uncomment the following line.
76
+ # config.cas_create_user = false
77
+ end
78
+
79
+ Extra attributes
80
+ ----------------
81
+
82
+ If your CAS server passes along extra attributes you'd like to save in your user records,
83
+ using the CAS extra_attributes parameter, you can define a method in your user model called
84
+ cas_extra_attributes= to accept these. For example:
85
+
86
+ class User < ActiveRecord::Base
87
+ devise :cas_authenticatable
88
+
89
+ def cas_extra_attributes=(extra_attributes)
90
+ extra_attributes.each do |name, value|
91
+ case name.to_sym
92
+ when :fullname
93
+ self.fullname = value
94
+ when :email
95
+ self.email = value
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ See also
102
+ --------
103
+
104
+ * [CAS](http://www.jasig.org/cas)
105
+ * [rubycas-server](http://github.com/gunark/rubycas-server)
106
+ * [rubycas-client](http://github.com/gunark/rubycas-client)
107
+ * [Devise](http://github.com/plataformatec/devise)
108
+ * [Warden](http://github.com/hassox/warden)
109
+
110
+ TODO
111
+ ----
112
+
113
+ * Implement CAS single sign-off support (maybe via a Rack middleware?)
114
+ * Test on non-ActiveRecord ORMs
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'bundler'
2
+
3
+ Bundler.setup
4
+
5
+ require 'rake'
6
+ require 'rake/rdoctask'
7
+ require 'rspec/mocks/version'
8
+ require 'rspec/core/rake_task'
9
+
10
+ RSpec::Core::RakeTask.new(:spec)
11
+
12
+ desc 'Default: run specs.'
13
+ task :default => :spec
14
+
15
+ desc 'Generate documentation for the devise_bushido_authenticatable plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'devise_bushido_authenticatable'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
23
+
24
+
25
+ begin
26
+ require 'jeweler'
27
+ Jeweler::Tasks.new do |gemspec|
28
+ gemspec.name = "devise_bushido_authenticatable"
29
+ gemspec.summary = "Bushido SSO authentication module for Devise"
30
+ gemspec.description = "Bushido SSO authentication module for Devise. A slight variant of the excellent work from Nat Budlin on devise_cas_authenticatable."
31
+ gemspec.email = "s@bushi.do"
32
+ gemspec.homepage = "http://github.com/bushido/bushido_cas_authenticatable"
33
+ gemspec.authors = ["Akash Manohar J", "Sean Grove", "Didier Lafforgue"]
34
+ gemspec.add_runtime_dependency "devise", ">= 1.0.6"
35
+ gemspec.add_runtime_dependency "rubycas-client", ">= 2.2.1"
36
+ end
37
+ Jeweler::RubygemsDotOrgTasks.new
38
+ rescue LoadError
39
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
40
+ end
41
+
42
+ # namespace :scenario do
43
+ # require File.expand_path('../spec/scenario/config/application', __FILE__)
44
+ #
45
+ # Scenario::Application.load_tasks
46
+ # end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0.alpha10
@@ -0,0 +1,52 @@
1
+ class Devise::CasSessionsController < Devise::SessionsController
2
+ unloadable
3
+
4
+ def new
5
+ unless returning_from_cas?
6
+ redirect_to(cas_login_url)
7
+ end
8
+ end
9
+
10
+ def service
11
+ warden.authenticate!(:scope => resource_name)
12
+
13
+ if params[:redirect]
14
+ return redirect_to params[:redirect]
15
+ end
16
+
17
+ return redirect_to after_sign_in_path_for(resource_name)
18
+ end
19
+
20
+ def unregistered
21
+ end
22
+
23
+ def destroy
24
+ # if :cas_create_user is false a CAS session might be open but not signed_in
25
+ # in such case we destroy the session here
26
+ if signed_in?(resource_name)
27
+ sign_out(resource_name)
28
+ else
29
+ reset_session
30
+ end
31
+ redirect_to(::Devise.cas_client.logout_url)
32
+ end
33
+
34
+ private
35
+ def returning_from_cas?
36
+ params[:ticket] || request.referer =~ /^#{::Devise.cas_client.cas_base_url}/
37
+ end
38
+
39
+ def cas_return_to_url
40
+ resource_or_scope = ::Devise.mappings.keys.first rescue 'user'
41
+ session["#{resource_or_scope}_return_to"].nil? ? '/' : session["#{resource_or_scope}_return_to"].to_s
42
+ end
43
+
44
+ def cas_login_url
45
+ login_url = ::Devise.cas_client.add_service_to_login_url(::Devise.cas_service_url(request.url, devise_mapping))
46
+
47
+ redirect_url = "&redirect=#{cas_return_to_url}"
48
+
49
+ return "#{login_url}#{redirect_url}"
50
+ end
51
+ helper_method :cas_login_url
52
+ end
@@ -0,0 +1 @@
1
+ <p>Click <%= link_to "here", cas_login_url %> to sign in.</p>
@@ -0,0 +1,2 @@
1
+ <p>The user <%=h params[:username] %> is not registered with this site.
2
+ Please <%= link_to "sign in using a different account", Devise.cas_client.logout_url(new_session_url(resource_name)) %>.</p>
@@ -0,0 +1,118 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{devise_cas_authenticatable}
8
+ s.version = "1.0.0.alpha10"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Nat Budin"]
12
+ s.date = %q{2011-06-08}
13
+ s.description = %q{CAS authentication module for Devise}
14
+ s.email = %q{natbudin@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".project",
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "README.md",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "app/controllers/devise/cas_sessions_controller.rb",
26
+ "app/views/devise/cas_sessions/new.html.erb",
27
+ "app/views/devise/cas_sessions/unregistered.html.erb",
28
+ "devise_cas_authenticatable.gemspec",
29
+ "lib/devise_cas_authenticatable.rb",
30
+ "lib/devise_cas_authenticatable/exceptions.rb",
31
+ "lib/devise_cas_authenticatable/model.rb",
32
+ "lib/devise_cas_authenticatable/routes.rb",
33
+ "lib/devise_cas_authenticatable/schema.rb",
34
+ "lib/devise_cas_authenticatable/strategy.rb",
35
+ "rails/init.rb",
36
+ "spec/routes_spec.rb",
37
+ "spec/scenario/.gitignore",
38
+ "spec/scenario/app/controllers/application_controller.rb",
39
+ "spec/scenario/app/controllers/home_controller.rb",
40
+ "spec/scenario/app/models/user.rb",
41
+ "spec/scenario/app/views/layouts/application.html.erb",
42
+ "spec/scenario/config.ru",
43
+ "spec/scenario/config/application.rb",
44
+ "spec/scenario/config/boot.rb",
45
+ "spec/scenario/config/castronaut.yml",
46
+ "spec/scenario/config/database.yml",
47
+ "spec/scenario/config/environment.rb",
48
+ "spec/scenario/config/environments/development.rb",
49
+ "spec/scenario/config/environments/production.rb",
50
+ "spec/scenario/config/environments/test.rb",
51
+ "spec/scenario/config/initializers/backtrace_silencers.rb",
52
+ "spec/scenario/config/initializers/devise.rb",
53
+ "spec/scenario/config/initializers/inflections.rb",
54
+ "spec/scenario/config/initializers/mime_types.rb",
55
+ "spec/scenario/config/initializers/secret_token.rb",
56
+ "spec/scenario/config/initializers/session_store.rb",
57
+ "spec/scenario/config/locales/en.yml",
58
+ "spec/scenario/config/routes.rb",
59
+ "spec/scenario/config/rubycas-server.yml",
60
+ "spec/scenario/db/migrate/20100401102949_create_tables.rb",
61
+ "spec/scenario/public/.gitkeep",
62
+ "spec/spec_helper.rb",
63
+ "spec/strategy_spec.rb",
64
+ "spec/support/migrations.rb"
65
+ ]
66
+ s.homepage = %q{http://github.com/nbudin/devise_cas_authenticatable}
67
+ s.require_paths = ["lib"]
68
+ s.rubygems_version = %q{1.5.0}
69
+ s.summary = %q{CAS authentication module for Devise}
70
+ s.test_files = [
71
+ "spec/routes_spec.rb",
72
+ "spec/scenario/app/controllers/application_controller.rb",
73
+ "spec/scenario/app/controllers/home_controller.rb",
74
+ "spec/scenario/app/models/user.rb",
75
+ "spec/scenario/config/application.rb",
76
+ "spec/scenario/config/boot.rb",
77
+ "spec/scenario/config/environment.rb",
78
+ "spec/scenario/config/environments/development.rb",
79
+ "spec/scenario/config/environments/production.rb",
80
+ "spec/scenario/config/environments/test.rb",
81
+ "spec/scenario/config/initializers/backtrace_silencers.rb",
82
+ "spec/scenario/config/initializers/devise.rb",
83
+ "spec/scenario/config/initializers/inflections.rb",
84
+ "spec/scenario/config/initializers/mime_types.rb",
85
+ "spec/scenario/config/initializers/secret_token.rb",
86
+ "spec/scenario/config/initializers/session_store.rb",
87
+ "spec/scenario/config/routes.rb",
88
+ "spec/scenario/db/migrate/20100401102949_create_tables.rb",
89
+ "spec/spec_helper.rb",
90
+ "spec/strategy_spec.rb",
91
+ "spec/support/migrations.rb"
92
+ ]
93
+
94
+ if s.respond_to? :specification_version then
95
+ s.specification_version = 3
96
+
97
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
98
+ s.add_runtime_dependency(%q<devise>, [">= 0"])
99
+ s.add_development_dependency(%q<ruby-debug>, [">= 0"])
100
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
101
+ s.add_runtime_dependency(%q<devise>, [">= 1.0.6"])
102
+ s.add_runtime_dependency(%q<rubycas-client>, [">= 2.2.1"])
103
+ else
104
+ s.add_dependency(%q<devise>, [">= 0"])
105
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
106
+ s.add_dependency(%q<jeweler>, [">= 0"])
107
+ s.add_dependency(%q<devise>, [">= 1.0.6"])
108
+ s.add_dependency(%q<rubycas-client>, [">= 2.2.1"])
109
+ end
110
+ else
111
+ s.add_dependency(%q<devise>, [">= 0"])
112
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
113
+ s.add_dependency(%q<jeweler>, [">= 0"])
114
+ s.add_dependency(%q<devise>, [">= 1.0.6"])
115
+ s.add_dependency(%q<rubycas-client>, [">= 2.2.1"])
116
+ end
117
+ end
118
+
@@ -0,0 +1,10 @@
1
+ # Thrown when a user attempts to pass a CAS ticket that the server
2
+ # says is invalid.
3
+ class InvalidCasTicketException < Exception
4
+ attr_reader :ticket
5
+
6
+ def initialize(ticket, msg=nil)
7
+ super(msg)
8
+ @ticket = ticket
9
+ end
10
+ end
@@ -0,0 +1,56 @@
1
+ module Devise
2
+ module Models
3
+ # Extends your User class with support for CAS ticket authentication.
4
+ module CasAuthenticatable
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+
8
+ if defined?(Mongoid)
9
+ base.class_eval do
10
+ field :username
11
+ end
12
+ end
13
+ end
14
+
15
+ module ClassMethods
16
+ # Authenticate a CAS ticket and return the resulting user object. Behavior is as follows:
17
+ #
18
+ # * Check ticket validity using RubyCAS::Client. Return nil if the ticket is invalid.
19
+ # * Find a matching user by username (will use find_for_authentication if available).
20
+ # * If the user does not exist, but Devise.cas_create_user is set, attempt to create the
21
+ # user object in the database. If cas_extra_attributes= is defined, this will also
22
+ # pass in the ticket's extra_attributes hash.
23
+ # * Return the resulting user object.
24
+ def authenticate_with_cas_ticket(ticket)
25
+ ::Devise.cas_client.validate_service_ticket(ticket) unless ticket.has_been_validated?
26
+
27
+ puts "ticket = #{ticket.inspect}"
28
+
29
+ if ticket.is_valid?
30
+ conditions = {::Devise.cas_username_column => ticket.response.user}
31
+
32
+ # We don't want to override Devise 1.1's find_for_authentication
33
+ resource = if respond_to?(:find_for_authentication)
34
+ find_for_authentication(conditions)
35
+ else
36
+ find(:first, :conditions => conditions)
37
+ end
38
+
39
+ resource = new(conditions) if (resource.nil? and ::Devise.cas_create_user?)
40
+
41
+ puts "found #{resource.inspect}"
42
+
43
+ return nil unless resource
44
+
45
+ resource.cas_extra_attributes = ticket.response.extra_attributes if resource.respond_to? :cas_extra_attributes=
46
+
47
+ # puts "resource.cas_extra_attributes = #{resource.cas_extra_attributes.inspect}"
48
+
49
+ resource.save
50
+ resource
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,35 @@
1
+ if ActionController::Routing.name =~ /ActionDispatch/
2
+ # Rails 3
3
+
4
+ ActionDispatch::Routing::Mapper.class_eval do
5
+ protected
6
+
7
+ def devise_cas_authenticatable(mapping, controllers)
8
+ # service endpoint for CAS server
9
+ get "service", :to => "#{controllers[:cas_sessions]}#service", :as => "service"
10
+
11
+ resource :session, :only => [], :controller => controllers[:cas_sessions], :path => "" do
12
+ get :new, :path => mapping.path_names[:sign_in], :as => "new"
13
+ get :unregistered
14
+ post :create, :path => mapping.path_names[:sign_in]
15
+ match :destroy, :path => mapping.path_names[:sign_out], :as => "destroy"
16
+ end
17
+ end
18
+ end
19
+ else
20
+ # Rails 2
21
+
22
+ ActionController::Routing::RouteSet::Mapper.class_eval do
23
+ protected
24
+
25
+ def cas_authenticatable(routes, mapping)
26
+ routes.with_options(:controller => 'devise/cas_sessions', :name_prefix => nil) do |session|
27
+ session.send(:"#{mapping.name}_service", '/', :action => 'service', :conditions => {:method => :get})
28
+ session.send(:"unregistered_#{mapping.name}_session", '/unregistered', :action => "unregistered", :conditions => {:method => :get})
29
+ session.send(:"new_#{mapping.name}_session", mapping.path_names[:sign_in], :action => 'new', :conditions => {:method => :get})
30
+ session.send(:"#{mapping.name}_session", mapping.path_names[:sign_in], :action => 'create', :conditions => {:method => :post})
31
+ session.send(:"destroy_#{mapping.name}_session", mapping.path_names[:sign_out], :action => 'destroy', :conditions => { :method => :get })
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ require 'devise/schema'
2
+
3
+ module Devise
4
+ module Schema
5
+ # Adds the required fields for cas_authenticatable to the schema. Currently
6
+ # this is just username (String).
7
+ def cas_authenticatable
8
+ if respond_to? :apply_devise_schema
9
+ apply_devise_schema :username, String
10
+ else
11
+ apply_schema :username, String
12
+ end
13
+ end
14
+ end
15
+ end