devise_cas_authenticatable 1.0.0.alpha5 → 1.0.0.alpha6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,13 +2,23 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rails', '3.0.0'
6
- gem "rspec", ">= 2.0.0.beta.17"
7
- gem "rspec-rails", ">= 2.0.0.beta.17"
8
- gem "mocha"
9
- gem "shoulda"
10
- gem "sqlite3-ruby"
11
- gem "sham_rack"
12
- gem "webrat"
13
- gem "ruby-debug"
14
- gem "jeweler"
5
+ gem 'devise'
6
+
7
+ group :development do
8
+ gem "ruby-debug"
9
+ gem "jeweler"
10
+ end
11
+
12
+ group :test do
13
+ gem "rails", ">= 3.0.0"
14
+ gem "rspec", ">= 2.0.0.beta.17"
15
+ gem "rspec-rails", ">= 2.0.0.beta.17"
16
+ gem "mocha"
17
+ gem "shoulda"
18
+ gem "sqlite3-ruby"
19
+ gem "sham_rack"
20
+ gem "capybara"
21
+ gem 'rubycas-server', :git => 'https://github.com/gunark/rubycas-server.git', :branch => 'sinatra'
22
+ gem 'crypt-isaac'
23
+ gem 'launchy'
24
+ end
data/Gemfile.lock CHANGED
@@ -1,8 +1,21 @@
1
+ GIT
2
+ remote: https://github.com/gunark/rubycas-server.git
3
+ revision: c6ce0068bcaffe847f7b12804401c493b1179f47
4
+ branch: sinatra
5
+ specs:
6
+ rubycas-server (0.9.999999)
7
+ activerecord (~> 3.0.0)
8
+ activesupport (~> 3.0.0)
9
+ gettext (~> 2.1.0)
10
+ sinatra (~> 1.0)
11
+
1
12
  PATH
2
13
  remote: .
3
14
  specs:
4
- devise_cas_authenticatable (1.0.0.alpha5)
15
+ devise_cas_authenticatable (1.0.0.alpha6)
5
16
  devise (>= 1.0.6)
17
+ devise
18
+ devise_cas_authenticatable
6
19
  rubycas-client (>= 2.2.1)
7
20
 
8
21
  GEM
@@ -39,35 +52,60 @@ GEM
39
52
  activesupport (~> 3.0.0)
40
53
  bcrypt-ruby (2.1.4)
41
54
  builder (2.1.2)
55
+ capybara (0.4.1.1)
56
+ celerity (>= 0.7.9)
57
+ culerity (>= 0.2.4)
58
+ mime-types (>= 1.16)
59
+ nokogiri (>= 1.3.3)
60
+ rack (>= 1.0.0)
61
+ rack-test (>= 0.5.4)
62
+ selenium-webdriver (>= 0.0.27)
63
+ xpath (~> 0.1.3)
64
+ celerity (0.8.7)
65
+ childprocess (0.1.6)
66
+ ffi (~> 0.6.3)
42
67
  columnize (0.3.1)
43
- devise (1.1.5)
68
+ configuration (1.2.0)
69
+ crypt-isaac (0.9.1)
70
+ culerity (0.2.15)
71
+ devise (1.2.1)
44
72
  bcrypt-ruby (~> 2.1.2)
45
- warden (~> 1.0.2)
73
+ orm_adapter (~> 0.0.3)
74
+ warden (~> 1.0.3)
46
75
  diff-lcs (1.1.2)
47
76
  erubis (2.6.6)
48
77
  abstract (>= 1.0.0)
49
- gemcutter (0.6.1)
78
+ ffi (0.6.3)
79
+ rake (>= 0.8.7)
80
+ gettext (2.1.0)
81
+ locale (>= 2.0.5)
50
82
  git (1.2.5)
51
- i18n (0.4.1)
52
- jeweler (1.4.0)
53
- gemcutter (>= 0.1.0)
83
+ i18n (0.4.2)
84
+ jeweler (1.5.2)
85
+ bundler (~> 1.0.0)
54
86
  git (>= 1.2.5)
55
- rubyforge (>= 2.0.0)
56
- json_pure (1.4.6)
87
+ rake
88
+ json_pure (1.5.0)
89
+ launchy (0.3.7)
90
+ configuration (>= 0.0.5)
91
+ rake (>= 0.8.1)
57
92
  linecache (0.43)
58
- mail (2.2.6.1)
93
+ locale (2.0.5)
94
+ mail (2.2.14)
59
95
  activesupport (>= 2.3.6)
60
- mime-types
61
- treetop (>= 1.4.5)
96
+ i18n (>= 0.4.0)
97
+ mime-types (~> 1.16)
98
+ treetop (~> 1.4.8)
62
99
  mime-types (1.16)
63
- mocha (0.9.8)
100
+ mocha (0.9.10)
64
101
  rake
65
- nokogiri (1.4.3.1)
102
+ nokogiri (1.4.4)
103
+ orm_adapter (0.0.4)
66
104
  polyglot (0.3.1)
67
105
  rack (1.2.1)
68
106
  rack-mount (0.6.13)
69
107
  rack (>= 1.0.0)
70
- rack-test (0.5.4)
108
+ rack-test (0.5.7)
71
109
  rack (>= 1.0)
72
110
  rails (3.0.0)
73
111
  actionmailer (= 3.0.0)
@@ -83,53 +121,67 @@ GEM
83
121
  rake (>= 0.8.4)
84
122
  thor (~> 0.14.0)
85
123
  rake (0.8.7)
86
- rspec (2.0.0.beta.22)
87
- rspec-core (= 2.0.0.beta.22)
88
- rspec-expectations (= 2.0.0.beta.22)
89
- rspec-mocks (= 2.0.0.beta.22)
90
- rspec-core (2.0.0.beta.22)
91
- rspec-expectations (2.0.0.beta.22)
92
- diff-lcs (>= 1.1.2)
93
- rspec-mocks (2.0.0.beta.22)
94
- rspec-core (= 2.0.0.beta.22)
95
- rspec-expectations (= 2.0.0.beta.22)
96
- rspec-rails (2.0.0.beta.22)
97
- rspec (= 2.0.0.beta.22)
98
- ruby-debug (0.10.3)
124
+ rspec (2.4.0)
125
+ rspec-core (~> 2.4.0)
126
+ rspec-expectations (~> 2.4.0)
127
+ rspec-mocks (~> 2.4.0)
128
+ rspec-core (2.4.0)
129
+ rspec-expectations (2.4.0)
130
+ diff-lcs (~> 1.1.2)
131
+ rspec-mocks (2.4.0)
132
+ rspec-rails (2.4.1)
133
+ actionpack (~> 3.0)
134
+ activesupport (~> 3.0)
135
+ railties (~> 3.0)
136
+ rspec (~> 2.4.0)
137
+ ruby-debug (0.10.4)
99
138
  columnize (>= 0.1)
100
- ruby-debug-base (~> 0.10.3.0)
101
- ruby-debug-base (0.10.3)
139
+ ruby-debug-base (~> 0.10.4.0)
140
+ ruby-debug-base (0.10.4)
102
141
  linecache (>= 0.3)
103
142
  rubycas-client (2.2.1)
104
143
  activesupport
105
- rubyforge (2.0.4)
106
- json_pure (>= 1.1.7)
107
- sham_rack (1.3.2)
144
+ rubyzip (0.9.4)
145
+ selenium-webdriver (0.1.2)
146
+ childprocess (~> 0.1.5)
147
+ ffi (~> 0.6.3)
148
+ json_pure
149
+ rubyzip
150
+ sham_rack (1.3.3)
151
+ rack
108
152
  shoulda (2.11.3)
109
- sqlite3-ruby (1.3.1)
110
- thor (0.14.1)
111
- treetop (1.4.8)
153
+ sinatra (1.1.2)
154
+ rack (~> 1.1)
155
+ tilt (~> 1.2)
156
+ sqlite3 (1.3.3)
157
+ sqlite3-ruby (1.3.3)
158
+ sqlite3 (>= 1.3.3)
159
+ thor (0.14.6)
160
+ tilt (1.2.2)
161
+ treetop (1.4.9)
112
162
  polyglot (>= 0.3.1)
113
- tzinfo (0.3.23)
163
+ tzinfo (0.3.24)
114
164
  warden (1.0.3)
115
165
  rack (>= 1.0.0)
116
- webrat (0.7.1)
117
- nokogiri (>= 1.2.0)
118
- rack (>= 1.0)
119
- rack-test (>= 0.5.3)
166
+ xpath (0.1.3)
167
+ nokogiri (~> 1.3)
120
168
 
121
169
  PLATFORMS
122
170
  ruby
123
171
 
124
172
  DEPENDENCIES
173
+ capybara
174
+ crypt-isaac
175
+ devise
125
176
  devise_cas_authenticatable!
126
177
  jeweler
178
+ launchy
127
179
  mocha
128
- rails (= 3.0.0)
180
+ rails (>= 3.0.0)
129
181
  rspec (>= 2.0.0.beta.17)
130
182
  rspec-rails (>= 2.0.0.beta.17)
131
183
  ruby-debug
184
+ rubycas-server!
132
185
  sham_rack
133
186
  shoulda
134
187
  sqlite3-ruby
135
- webrat
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0.alpha5
1
+ 1.0.0.alpha6
@@ -1,100 +1,120 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{devise_cas_authenticatable}
8
- s.version = "1.0.0.alpha5"
8
+ s.version = "1.0.0.alpha6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nat Budin"]
12
- s.date = %q{2011-03-31}
12
+ s.date = %q{2011-04-11}
13
13
  s.description = %q{CAS authentication module for Devise}
14
14
  s.email = %q{natbudin@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "README.md"
17
17
  ]
18
18
  s.files = [
19
- ".gitignore",
20
- ".project",
21
- "Gemfile",
22
- "Gemfile.lock",
23
- "README.md",
24
- "Rakefile",
25
- "VERSION",
26
- "app/controllers/devise/cas_sessions_controller.rb",
27
- "devise_cas_authenticatable.gemspec",
28
- "lib/devise_cas_authenticatable.rb",
29
- "lib/devise_cas_authenticatable/exceptions.rb",
30
- "lib/devise_cas_authenticatable/model.rb",
31
- "lib/devise_cas_authenticatable/routes.rb",
32
- "lib/devise_cas_authenticatable/schema.rb",
33
- "lib/devise_cas_authenticatable/strategy.rb",
34
- "rails/init.rb",
35
- "spec/routes_spec.rb",
36
- "spec/scenario/.gitignore",
37
- "spec/scenario/app/controllers/application_controller.rb",
38
- "spec/scenario/app/controllers/home_controller.rb",
39
- "spec/scenario/app/models/user.rb",
40
- "spec/scenario/app/views/layouts/application.html.erb",
41
- "spec/scenario/config.ru",
42
- "spec/scenario/config/application.rb",
43
- "spec/scenario/config/boot.rb",
44
- "spec/scenario/config/database.yml",
45
- "spec/scenario/config/environment.rb",
46
- "spec/scenario/config/environments/development.rb",
47
- "spec/scenario/config/environments/production.rb",
48
- "spec/scenario/config/environments/test.rb",
49
- "spec/scenario/config/initializers/backtrace_silencers.rb",
50
- "spec/scenario/config/initializers/inflections.rb",
51
- "spec/scenario/config/initializers/mime_types.rb",
52
- "spec/scenario/config/initializers/secret_token.rb",
53
- "spec/scenario/config/initializers/session_store.rb",
54
- "spec/scenario/config/locales/en.yml",
55
- "spec/scenario/config/routes.rb",
56
- "spec/scenario/db/migrate/20100401102949_create_tables.rb",
57
- "spec/spec_helper.rb",
58
- "spec/support/migrations.rb"
19
+ ".project",
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "README.md",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "app/controllers/devise/cas_sessions_controller.rb",
26
+ "devise_cas_authenticatable.gemspec",
27
+ "lib/devise_cas_authenticatable.rb",
28
+ "lib/devise_cas_authenticatable/exceptions.rb",
29
+ "lib/devise_cas_authenticatable/model.rb",
30
+ "lib/devise_cas_authenticatable/routes.rb",
31
+ "lib/devise_cas_authenticatable/schema.rb",
32
+ "lib/devise_cas_authenticatable/strategy.rb",
33
+ "rails/init.rb",
34
+ "spec/routes_spec.rb",
35
+ "spec/scenario/.gitignore",
36
+ "spec/scenario/app/controllers/application_controller.rb",
37
+ "spec/scenario/app/controllers/home_controller.rb",
38
+ "spec/scenario/app/models/user.rb",
39
+ "spec/scenario/app/views/layouts/application.html.erb",
40
+ "spec/scenario/config.ru",
41
+ "spec/scenario/config/application.rb",
42
+ "spec/scenario/config/boot.rb",
43
+ "spec/scenario/config/database.yml",
44
+ "spec/scenario/config/environment.rb",
45
+ "spec/scenario/config/environments/development.rb",
46
+ "spec/scenario/config/environments/production.rb",
47
+ "spec/scenario/config/environments/test.rb",
48
+ "spec/scenario/config/initializers/backtrace_silencers.rb",
49
+ "spec/scenario/config/initializers/inflections.rb",
50
+ "spec/scenario/config/initializers/mime_types.rb",
51
+ "spec/scenario/config/initializers/secret_token.rb",
52
+ "spec/scenario/config/initializers/session_store.rb",
53
+ "spec/scenario/config/locales/en.yml",
54
+ "spec/scenario/config/routes.rb",
55
+ "spec/scenario/config/rubycas-server.yml",
56
+ "spec/scenario/db/migrate/20100401102949_create_tables.rb",
57
+ "spec/scenario/public/.gitkeep",
58
+ "spec/spec_helper.rb",
59
+ "spec/strategy_spec.rb",
60
+ "spec/support/migrations.rb"
59
61
  ]
60
62
  s.homepage = %q{http://github.com/nbudin/devise_cas_authenticatable}
61
- s.rdoc_options = ["--charset=UTF-8"]
62
63
  s.require_paths = ["lib"]
63
64
  s.rubygems_version = %q{1.5.0}
64
65
  s.summary = %q{CAS authentication module for Devise}
65
66
  s.test_files = [
66
67
  "spec/routes_spec.rb",
67
- "spec/scenario/app/controllers/application_controller.rb",
68
- "spec/scenario/app/controllers/home_controller.rb",
69
- "spec/scenario/app/models/user.rb",
70
- "spec/scenario/config/application.rb",
71
- "spec/scenario/config/boot.rb",
72
- "spec/scenario/config/environment.rb",
73
- "spec/scenario/config/environments/development.rb",
74
- "spec/scenario/config/environments/production.rb",
75
- "spec/scenario/config/environments/test.rb",
76
- "spec/scenario/config/initializers/backtrace_silencers.rb",
77
- "spec/scenario/config/initializers/inflections.rb",
78
- "spec/scenario/config/initializers/mime_types.rb",
79
- "spec/scenario/config/initializers/secret_token.rb",
80
- "spec/scenario/config/initializers/session_store.rb",
81
- "spec/scenario/config/routes.rb",
82
- "spec/scenario/db/migrate/20100401102949_create_tables.rb",
83
- "spec/spec_helper.rb",
84
- "spec/support/migrations.rb"
68
+ "spec/scenario/app/controllers/application_controller.rb",
69
+ "spec/scenario/app/controllers/home_controller.rb",
70
+ "spec/scenario/app/models/user.rb",
71
+ "spec/scenario/config/application.rb",
72
+ "spec/scenario/config/boot.rb",
73
+ "spec/scenario/config/environment.rb",
74
+ "spec/scenario/config/environments/development.rb",
75
+ "spec/scenario/config/environments/production.rb",
76
+ "spec/scenario/config/environments/test.rb",
77
+ "spec/scenario/config/initializers/backtrace_silencers.rb",
78
+ "spec/scenario/config/initializers/inflections.rb",
79
+ "spec/scenario/config/initializers/mime_types.rb",
80
+ "spec/scenario/config/initializers/secret_token.rb",
81
+ "spec/scenario/config/initializers/session_store.rb",
82
+ "spec/scenario/config/routes.rb",
83
+ "spec/scenario/db/migrate/20100401102949_create_tables.rb",
84
+ "spec/spec_helper.rb",
85
+ "spec/strategy_spec.rb",
86
+ "spec/support/migrations.rb"
85
87
  ]
86
88
 
87
89
  if s.respond_to? :specification_version then
88
90
  s.specification_version = 3
89
91
 
90
92
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
93
+ s.add_runtime_dependency(%q<devise_cas_authenticatable>, [">= 0"])
94
+ s.add_runtime_dependency(%q<devise>, [">= 0"])
95
+ s.add_development_dependency(%q<ruby-debug>, [">= 0"])
96
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
97
+ s.add_development_dependency(%q<ruby-debug>, [">= 0"])
98
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
91
99
  s.add_runtime_dependency(%q<devise>, [">= 1.0.6"])
92
100
  s.add_runtime_dependency(%q<rubycas-client>, [">= 2.2.1"])
93
101
  else
102
+ s.add_dependency(%q<devise_cas_authenticatable>, [">= 0"])
103
+ s.add_dependency(%q<devise>, [">= 0"])
104
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
105
+ s.add_dependency(%q<jeweler>, [">= 0"])
106
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
107
+ s.add_dependency(%q<jeweler>, [">= 0"])
94
108
  s.add_dependency(%q<devise>, [">= 1.0.6"])
95
109
  s.add_dependency(%q<rubycas-client>, [">= 2.2.1"])
96
110
  end
97
111
  else
112
+ s.add_dependency(%q<devise_cas_authenticatable>, [">= 0"])
113
+ s.add_dependency(%q<devise>, [">= 0"])
114
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
115
+ s.add_dependency(%q<jeweler>, [">= 0"])
116
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
117
+ s.add_dependency(%q<jeweler>, [">= 0"])
98
118
  s.add_dependency(%q<devise>, [">= 1.0.6"])
99
119
  s.add_dependency(%q<rubycas-client>, [">= 2.2.1"])
100
120
  end
@@ -1,3 +1,5 @@
1
+ # Thrown when a user attempts to pass a CAS ticket that the server
2
+ # says is invalid.
1
3
  class InvalidCasTicketException < Exception
2
4
  attr_reader :ticket
3
5
 
@@ -1,11 +1,20 @@
1
1
  module Devise
2
2
  module Models
3
+ # Extends your User class with support for CAS ticket authentication.
3
4
  module CasAuthenticatable
4
5
  def self.included(base)
5
6
  base.extend ClassMethods
6
7
  end
7
8
 
8
9
  module ClassMethods
10
+ # Authenticate a CAS ticket and return the resulting user object. Behavior is as follows:
11
+ #
12
+ # * Check ticket validity using RubyCAS::Client. Return nil if the ticket is invalid.
13
+ # * Find a matching user by username (will use find_for_authentication if available).
14
+ # * If the user does not exist, but Devise.cas_create_user is set, attempt to create the
15
+ # user object in the database. If cas_extra_attributes= is defined, this will also
16
+ # pass in the ticket's extra_attributes hash.
17
+ # * Return the resulting user object.
9
18
  def authenticate_with_cas_ticket(ticket)
10
19
  ::Devise.cas_client.validate_service_ticket(ticket) unless ticket.has_been_validated?
11
20
 
@@ -19,23 +28,12 @@ module Devise
19
28
  find(:first, :conditions => conditions)
20
29
  end
21
30
 
22
- resource = new(conditions) if (resource.nil? and ::Devise.cas_create_user)
31
+ resource = new(conditions) if (resource.nil? and ::Devise.cas_create_user?)
23
32
  return nil unless resource
24
33
 
25
- if resource.new_record?
26
- if resource.respond_to? :cas_extra_attributes=
27
- resource.cas_extra_attributes = ticket.response.extra_attributes
28
- end
29
-
30
- create(conditions)
31
- else
32
- if resource.respond_to? :cas_extra_attributes=
33
- resource.cas_extra_attributes = ticket.response.extra_attributes
34
- resource.save
35
- end
36
-
37
- resource
38
- end
34
+ resource.cas_extra_attributes = ticket.response.extra_attributes if resource.respond_to? :cas_extra_attributes=
35
+ resource.save
36
+ resource
39
37
  end
40
38
  end
41
39
  end
@@ -5,10 +5,10 @@ if ActionController::Routing.name =~ /ActionDispatch/
5
5
  protected
6
6
 
7
7
  def devise_cas_authenticatable(mapping, controllers)
8
- resource :session, :only => [], :controller => controllers[:cas_sessions], :path => "" do
9
- # service endpoint for CAS server
10
- get "/", :to => "#{controllers[:cas_sessions]}#service"
8
+ # service endpoint for CAS server
9
+ get "/", :to => "#{controllers[:cas_sessions]}#service", :as => ""
11
10
 
11
+ resource :session, :only => [], :controller => controllers[:cas_sessions], :path => "" do
12
12
  get :new, :path => mapping.path_names[:sign_in], :to => "#{controllers[:cas_sessions]}#create", :as => "new"
13
13
  post :create, :path => mapping.path_names[:sign_in]
14
14
  match :destroy, :path => mapping.path_names[:sign_out], :as => "destroy"
@@ -23,7 +23,7 @@ else
23
23
 
24
24
  def cas_authenticatable(routes, mapping)
25
25
  routes.with_options(:controller => 'devise/cas_sessions', :name_prefix => nil) do |session|
26
- session.connect('/', :action => 'service', :conditions => {:method => :get})
26
+ session.send(:"#{mapping.name}", '/', :action => 'service', :conditions => {:method => :get})
27
27
  session.send(:"new_#{mapping.name}_session", mapping.path_names[:sign_in], :action => 'create', :conditions => {:method => :get})
28
28
  session.send(:"#{mapping.name}_session", mapping.path_names[:sign_in], :action => 'create', :conditions => {:method => :post})
29
29
  session.send(:"destroy_#{mapping.name}_session", mapping.path_names[:sign_out], :action => 'destroy', :conditions => { :method => :get })
@@ -2,6 +2,8 @@ require 'devise/schema'
2
2
 
3
3
  module Devise
4
4
  module Schema
5
+ # Adds the required fields for cas_authenticatable to the schema. Currently
6
+ # this is just username (String).
5
7
  def cas_authenticatable
6
8
  if respond_to? :apply_devise_schema
7
9
  apply_devise_schema :username, String
@@ -3,10 +3,16 @@ require 'devise/strategies/base'
3
3
  module Devise
4
4
  module Strategies
5
5
  class CasAuthenticatable < Base
6
+ # True if the mapping supports authenticate_with_cas_ticket.
6
7
  def valid?
7
8
  mapping.to.respond_to?(:authenticate_with_cas_ticket)
8
9
  end
9
10
 
11
+ # Try to authenticate a user using the CAS ticket passed in params.
12
+ # If the ticket is valid and the model's authenticate_with_cas_ticket method
13
+ # returns a user, then return success. If the ticket is invalid, then either
14
+ # fail (if we're just returning from the CAS server, based on the referrer)
15
+ # or attempt to redirect to the CAS server's login URL.
10
16
  def authenticate!
11
17
  ticket = read_ticket(params)
12
18
  if ticket
@@ -18,22 +18,31 @@ else
18
18
  end
19
19
  end
20
20
 
21
- module Devise
22
- mattr_accessor :cas_base_url
21
+ module Devise
22
+ # The base URL of the CAS server. For example, http://cas.example.com. Specifying this
23
+ # is mandatory.
23
24
  @@cas_base_url = nil
24
25
 
25
- mattr_accessor :cas_login_url
26
+ # The login URL of the CAS server. If undefined, will default based on cas_base_url.
26
27
  @@cas_login_url = nil
27
28
 
28
- mattr_accessor :cas_logout_url
29
+ # The login URL of the CAS server. If undefined, will default based on cas_base_url.
29
30
  @@cas_logout_url = nil
30
31
 
31
- mattr_accessor :cas_validate_url
32
+ # The login URL of the CAS server. If undefined, will default based on cas_base_url.
32
33
  @@cas_validate_url = nil
33
34
 
34
- mattr_accessor :cas_create_user
35
+ # Should devise_cas_authenticatable attempt to create new user records for
36
+ # unknown usernames? True by default.
35
37
  @@cas_create_user = true
36
38
 
39
+ mattr_accessor :cas_base_url, :cas_login_url, :cas_logout_url, :cas_validate_url, :cas_create_user
40
+
41
+ def self.cas_create_user?
42
+ cas_create_user
43
+ end
44
+
45
+ # Return a CASClient::Client instance based on configuration parameters.
37
46
  def self.cas_client
38
47
  @@cas_client ||= CASClient::Client.new(
39
48
  :cas_base_url => @@cas_base_url,
data/spec/routes_spec.rb CHANGED
@@ -9,7 +9,8 @@ describe Devise::CasSessionsController do
9
9
  it { should route(:get, "/users/sign_out").to(:action => "destroy") }
10
10
 
11
11
  it "should have the right route names" do
12
- controller.should respond_to("new_user_session_path", "user_session_path", "destroy_user_session_path")
12
+ controller.should respond_to("user_path", "new_user_session_path", "user_session_path", "destroy_user_session_path")
13
+ controller.user_path.should == "/users"
13
14
  controller.new_user_session_path.should == "/users/sign_in"
14
15
  controller.user_session_path.should == "/users/sign_in"
15
16
  controller.destroy_user_session_path.should == "/users/sign_out"
@@ -1,4 +1,3 @@
1
1
  class ApplicationController < ActionController::Base
2
2
  protect_from_forgery
3
- before_filter :authenticate_user!
4
3
  end
@@ -1,4 +1,6 @@
1
1
  class HomeController < ApplicationController
2
+ before_filter :authenticate_user!
3
+
2
4
  def index
3
5
  head(:ok)
4
6
  end
@@ -11,6 +11,24 @@ Devise.setup do |config|
11
11
  require "devise/orm/active_record"
12
12
  end
13
13
 
14
+ require 'casserver/authenticators/base'
15
+ class TestAuthenticator < CASServer::Authenticators::Base
16
+ def self.reset_valid_users!
17
+ @@valid_users = {
18
+ "joeuser" => "joepassword"
19
+ }
20
+ end
21
+ reset_valid_users!
22
+
23
+ def self.register_valid_user(username, password)
24
+ @@valid_users[username] = password
25
+ end
26
+
27
+ def validate(credentials)
28
+ @@valid_users[credentials[:username]] == credentials[:password]
29
+ end
30
+ end
31
+
14
32
  module Scenario
15
33
  class Application < Rails::Application
16
34
  config.active_support.deprecation = :stderr
@@ -1,4 +1,8 @@
1
+ ENV['CONFIG_FILE'] = File.expand_path('../rubycas-server.yml', __FILE__)
2
+ require 'casserver'
3
+
1
4
  Scenario::Application.routes.draw do
2
5
  devise_for :users
6
+ match "/cas_server/*args" => CASServer::Server, :as => "cas_server"
3
7
  root :to => "home#index"
4
8
  end
@@ -0,0 +1,13 @@
1
+ url_path: /cas_server
2
+
3
+ log:
4
+ level: DEBUG
5
+
6
+ database:
7
+ adapter: sqlite3
8
+ database: db/cas.sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ authenticator:
13
+ class: TestAuthenticator
File without changes
data/spec/spec_helper.rb CHANGED
@@ -6,11 +6,7 @@ require "scenario/config/environment"
6
6
  require "rails/test_help"
7
7
  require 'rspec/rails'
8
8
  require 'sham_rack'
9
-
10
- Webrat.configure do |config|
11
- config.mode = :rails
12
- config.open_error_files = false
13
- end
9
+ require 'capybara/rspec'
14
10
 
15
11
  RSpec.configure do |config|
16
12
  config.mock_with :mocha
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Devise::Strategies::CasAuthenticatable, :type => "acceptance" do
4
+ include Rspec::Rails::RequestExampleGroup
5
+
6
+ before do
7
+ Devise.cas_base_url = "http://www.example.com/cas_server"
8
+ TestAuthenticator.reset_valid_users!
9
+ User.create! do |u|
10
+ u.username = "joeuser"
11
+ end
12
+ end
13
+
14
+ after do
15
+ User.delete_all
16
+ end
17
+
18
+ def cas_login_url
19
+ @cas_login_url ||= begin
20
+ uri = URI.parse(Devise.cas_base_url + "/login")
21
+ uri.query = Rack::Utils.build_nested_query(:service => user_url)
22
+ uri.to_s
23
+ end
24
+ end
25
+
26
+ describe "GET /protected/resource" do
27
+ before { get '/' }
28
+
29
+ it 'should redirect to sign-in' do
30
+ response.should be_redirect
31
+ response.should redirect_to(cas_login_url)
32
+ end
33
+ end
34
+
35
+ describe "Sign in with valid user" do
36
+ it 'should log in ok' do
37
+ puts cas_login_url
38
+ visit cas_login_url
39
+ puts Capybara.current_session.current_url
40
+ save_and_open_page
41
+ end
42
+ end
43
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_cas_authenticatable
3
3
  version: !ruby/object:Gem::Version
4
- hash: -3702664330
4
+ hash: -3702664336
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
9
  - 0
10
10
  - alpha
11
- - 5
12
- version: 1.0.0.alpha5
11
+ - 6
12
+ version: 1.0.0.alpha6
13
13
  platform: ruby
14
14
  authors:
15
15
  - Nat Budin
@@ -17,13 +17,96 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-03-31 00:00:00 -04:00
20
+ date: 2011-04-11 00:00:00 -04:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
24
- prerelease: false
25
24
  type: :runtime
26
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ name: devise_cas_authenticatable
35
+ version_requirements: *id001
36
+ prerelease: false
37
+ - !ruby/object:Gem::Dependency
38
+ type: :runtime
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ name: devise
49
+ version_requirements: *id002
50
+ prerelease: false
51
+ - !ruby/object:Gem::Dependency
52
+ type: :development
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ name: ruby-debug
63
+ version_requirements: *id003
64
+ prerelease: false
65
+ - !ruby/object:Gem::Dependency
66
+ type: :development
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ name: jeweler
77
+ version_requirements: *id004
78
+ prerelease: false
79
+ - !ruby/object:Gem::Dependency
80
+ type: :development
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ name: ruby-debug
91
+ version_requirements: *id005
92
+ prerelease: false
93
+ - !ruby/object:Gem::Dependency
94
+ type: :development
95
+ requirement: &id006 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ name: jeweler
105
+ version_requirements: *id006
106
+ prerelease: false
107
+ - !ruby/object:Gem::Dependency
108
+ type: :runtime
109
+ requirement: &id007 !ruby/object:Gem::Requirement
27
110
  none: false
28
111
  requirements:
29
112
  - - ">="
@@ -35,11 +118,11 @@ dependencies:
35
118
  - 6
36
119
  version: 1.0.6
37
120
  name: devise
38
- version_requirements: *id001
39
- - !ruby/object:Gem::Dependency
121
+ version_requirements: *id007
40
122
  prerelease: false
123
+ - !ruby/object:Gem::Dependency
41
124
  type: :runtime
42
- requirement: &id002 !ruby/object:Gem::Requirement
125
+ requirement: &id008 !ruby/object:Gem::Requirement
43
126
  none: false
44
127
  requirements:
45
128
  - - ">="
@@ -51,7 +134,8 @@ dependencies:
51
134
  - 1
52
135
  version: 2.2.1
53
136
  name: rubycas-client
54
- version_requirements: *id002
137
+ version_requirements: *id008
138
+ prerelease: false
55
139
  description: CAS authentication module for Devise
56
140
  email: natbudin@gmail.com
57
141
  executables: []
@@ -61,7 +145,6 @@ extensions: []
61
145
  extra_rdoc_files:
62
146
  - README.md
63
147
  files:
64
- - .gitignore
65
148
  - .project
66
149
  - Gemfile
67
150
  - Gemfile.lock
@@ -98,16 +181,19 @@ files:
98
181
  - spec/scenario/config/initializers/session_store.rb
99
182
  - spec/scenario/config/locales/en.yml
100
183
  - spec/scenario/config/routes.rb
184
+ - spec/scenario/config/rubycas-server.yml
101
185
  - spec/scenario/db/migrate/20100401102949_create_tables.rb
186
+ - spec/scenario/public/.gitkeep
102
187
  - spec/spec_helper.rb
188
+ - spec/strategy_spec.rb
103
189
  - spec/support/migrations.rb
104
190
  has_rdoc: true
105
191
  homepage: http://github.com/nbudin/devise_cas_authenticatable
106
192
  licenses: []
107
193
 
108
194
  post_install_message:
109
- rdoc_options:
110
- - --charset=UTF-8
195
+ rdoc_options: []
196
+
111
197
  require_paths:
112
198
  - lib
113
199
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -156,4 +242,5 @@ test_files:
156
242
  - spec/scenario/config/routes.rb
157
243
  - spec/scenario/db/migrate/20100401102949_create_tables.rb
158
244
  - spec/spec_helper.rb
245
+ - spec/strategy_spec.rb
159
246
  - spec/support/migrations.rb
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- .bundle/*
2
- .yardoc/*
3
- pkg/*
4
- spec/scenario/db/*.sqlite3
5
- spec/scenario/tmp/*