devise_cas_authenticatable 1.0.0.alpha2 → 1.0.0.alpha3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +14 -5
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/app/controllers/devise/cas_sessions_controller.rb +18 -0
- data/devise_cas_authenticatable.gemspec +8 -8
- data/lib/devise_cas_authenticatable.rb +13 -1
- data/lib/devise_cas_authenticatable/model.rb +8 -14
- data/lib/devise_cas_authenticatable/routes.rb +30 -8
- data/lib/devise_cas_authenticatable/schema.rb +12 -4
- data/lib/devise_cas_authenticatable/strategy.rb +13 -10
- metadata +15 -6
- data/app/controllers/cas_sessions_controller.rb +0 -23
data/README.md
CHANGED
@@ -13,18 +13,28 @@ using [rubycas-server](http://github.com/gunark/rubycas-server)).
|
|
13
13
|
Requirements
|
14
14
|
------------
|
15
15
|
|
16
|
-
- Rails 2.3
|
17
|
-
- Devise 1.0 (
|
18
|
-
- rubycas-client
|
16
|
+
- Rails 2.3 or 3.0
|
17
|
+
- Devise 1.0 (for Rails 2.3) or 1.1 (for Rails 3.0)
|
18
|
+
- rubycas-client
|
19
19
|
|
20
20
|
Installation
|
21
21
|
------------
|
22
22
|
|
23
23
|
gem install --pre devise_cas_authenticatable
|
24
24
|
|
25
|
-
and in your config/environment.rb:
|
25
|
+
and in your config/environment.rb (on Rails 2.3):
|
26
26
|
|
27
27
|
config.gem 'devise_cas_authenticatable'
|
28
|
+
|
29
|
+
or Gemfile (Rails 3.0):
|
30
|
+
|
31
|
+
gem 'devise_cas_authenticatable'
|
32
|
+
|
33
|
+
Example
|
34
|
+
-------
|
35
|
+
|
36
|
+
I've modified the devise_example application to work with this gem. You can find the results
|
37
|
+
[here](http://github.com/nbudin/devise_cas_example).
|
28
38
|
|
29
39
|
Setup
|
30
40
|
-----
|
@@ -101,4 +111,3 @@ TODO
|
|
101
111
|
* Implement CAS single sign-off support (maybe via a Rack middleware?)
|
102
112
|
* Write test suite
|
103
113
|
* Test on non-ActiveRecord ORMs
|
104
|
-
* Test on Rails 3/Devise 1.1
|
data/Rakefile
CHANGED
@@ -32,10 +32,10 @@ begin
|
|
32
32
|
gemspec.email = "natbudin@gmail.com"
|
33
33
|
gemspec.homepage = "http://github.com/nbudin/devise_cas_authenticatable"
|
34
34
|
gemspec.authors = ["Nat Budin"]
|
35
|
-
gemspec.add_runtime_dependency "devise", "
|
35
|
+
gemspec.add_runtime_dependency "devise", ">= 1.0.6"
|
36
36
|
gemspec.add_runtime_dependency "rubycas-client", "~> 2.1.0"
|
37
37
|
end
|
38
38
|
Jeweler::GemcutterTasks.new
|
39
39
|
rescue LoadError
|
40
40
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
41
|
-
end
|
41
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.0.
|
1
|
+
1.0.0.alpha3
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Devise::CasSessionsController < Devise::SessionsController
|
2
|
+
def service
|
3
|
+
if signed_in?(resource_name)
|
4
|
+
redirect_to after_sign_in_path_for(resource_name)
|
5
|
+
else
|
6
|
+
redirect_to root_url
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def destroy
|
11
|
+
sign_out(resource_name)
|
12
|
+
destination = request.protocol
|
13
|
+
destination << request.host
|
14
|
+
destination << ":#{request.port.to_s}" unless request.port == 80
|
15
|
+
destination << after_sign_out_path_for(resource_name)
|
16
|
+
redirect_to(::Devise.cas_client.logout_url(destination))
|
17
|
+
end
|
18
|
+
end
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{devise_cas_authenticatable}
|
8
|
-
s.version = "1.0.0.
|
8
|
+
s.version = "1.0.0.alpha3"
|
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{2010-
|
12
|
+
s.date = %q{2010-08-27}
|
13
13
|
s.description = %q{CAS authentication module for Devise}
|
14
14
|
s.email = %q{natbudin@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
"README.md",
|
21
21
|
"Rakefile",
|
22
22
|
"VERSION",
|
23
|
-
"app/controllers/cas_sessions_controller.rb",
|
23
|
+
"app/controllers/devise/cas_sessions_controller.rb",
|
24
24
|
"devise_cas_authenticatable.gemspec",
|
25
25
|
"lib/devise_cas_authenticatable.rb",
|
26
26
|
"lib/devise_cas_authenticatable/exceptions.rb",
|
@@ -33,22 +33,22 @@ Gem::Specification.new do |s|
|
|
33
33
|
s.homepage = %q{http://github.com/nbudin/devise_cas_authenticatable}
|
34
34
|
s.rdoc_options = ["--charset=UTF-8"]
|
35
35
|
s.require_paths = ["lib"]
|
36
|
-
s.rubygems_version = %q{1.3.
|
36
|
+
s.rubygems_version = %q{1.3.7}
|
37
37
|
s.summary = %q{CAS authentication module for Devise}
|
38
38
|
|
39
39
|
if s.respond_to? :specification_version then
|
40
40
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
41
41
|
s.specification_version = 3
|
42
42
|
|
43
|
-
if Gem::Version.new(Gem::
|
44
|
-
s.add_runtime_dependency(%q<devise>, ["
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_runtime_dependency(%q<devise>, [">= 1.0.6"])
|
45
45
|
s.add_runtime_dependency(%q<rubycas-client>, ["~> 2.1.0"])
|
46
46
|
else
|
47
|
-
s.add_dependency(%q<devise>, ["
|
47
|
+
s.add_dependency(%q<devise>, [">= 1.0.6"])
|
48
48
|
s.add_dependency(%q<rubycas-client>, ["~> 2.1.0"])
|
49
49
|
end
|
50
50
|
else
|
51
|
-
s.add_dependency(%q<devise>, ["
|
51
|
+
s.add_dependency(%q<devise>, [">= 1.0.6"])
|
52
52
|
s.add_dependency(%q<rubycas-client>, ["~> 2.1.0"])
|
53
53
|
end
|
54
54
|
end
|
@@ -7,7 +7,18 @@ require 'devise_cas_authenticatable/exceptions'
|
|
7
7
|
|
8
8
|
require 'rubycas-client'
|
9
9
|
|
10
|
-
|
10
|
+
# Register as a Rails engine if Rails::Engine exists
|
11
|
+
begin
|
12
|
+
Rails::Engine
|
13
|
+
rescue
|
14
|
+
else
|
15
|
+
module DeviseCasAuthenticatable
|
16
|
+
class Engine < Rails::Engine
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module Devise
|
11
22
|
mattr_accessor :cas_base_url
|
12
23
|
@@cas_base_url = nil
|
13
24
|
|
@@ -36,4 +47,5 @@ end
|
|
36
47
|
Devise.add_module(:cas_authenticatable,
|
37
48
|
:strategy => true,
|
38
49
|
:controller => :cas_sessions,
|
50
|
+
:route => :cas_authenticatable,
|
39
51
|
:model => 'devise_cas_authenticatable/model')
|
@@ -4,22 +4,25 @@ module Devise
|
|
4
4
|
def self.included(base)
|
5
5
|
base.extend ClassMethods
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
module ClassMethods
|
9
9
|
def authenticate_with_cas_ticket(ticket)
|
10
10
|
::Devise.cas_client.validate_service_ticket(ticket) unless ticket.has_been_validated?
|
11
11
|
|
12
12
|
if ticket.is_valid?
|
13
|
-
logger.debug "Ticket is valid and is for user #{ticket.response.user}"
|
14
13
|
conditions = {:username => ticket.response.user}
|
15
|
-
puts conditions.inspect
|
16
14
|
|
17
|
-
|
15
|
+
# We don't want to override Devise 1.1's find_for_authentication
|
16
|
+
resource = if respond_to?(:find_for_authentication)
|
17
|
+
find_for_authentication(conditions)
|
18
|
+
else
|
19
|
+
find(:first, :conditions => conditions)
|
20
|
+
end
|
21
|
+
|
18
22
|
resource = new(conditions) if (resource.nil? and ::Devise.cas_create_user)
|
19
23
|
return nil unless resource
|
20
24
|
|
21
25
|
if resource.new_record?
|
22
|
-
logger.debug "Creating new user record"
|
23
26
|
if resource.respond_to? :cas_extra_attributes=
|
24
27
|
resource.cas_extra_attributes = ticket.response.extra_attributes
|
25
28
|
end
|
@@ -27,23 +30,14 @@ module Devise
|
|
27
30
|
create(conditions)
|
28
31
|
else
|
29
32
|
if resource.respond_to? :cas_extra_attributes=
|
30
|
-
logger.debug "Updating existing user record"
|
31
33
|
resource.cas_extra_attributes = ticket.response.extra_attributes
|
32
34
|
resource.save
|
33
35
|
end
|
34
36
|
|
35
37
|
resource
|
36
38
|
end
|
37
|
-
else
|
38
|
-
logger.debug "Ticket is invalid"
|
39
|
-
return nil
|
40
39
|
end
|
41
40
|
end
|
42
|
-
|
43
|
-
protected
|
44
|
-
def find_for_cas_authentication(conditions)
|
45
|
-
self.find(:first, :conditions => conditions)
|
46
|
-
end
|
47
41
|
end
|
48
42
|
end
|
49
43
|
end
|
@@ -1,11 +1,33 @@
|
|
1
|
-
ActionController::Routing
|
2
|
-
|
1
|
+
if ActionController::Routing.name =~ /ActionDispatch/
|
2
|
+
# Rails 3
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
ActionDispatch::Routing::Mapper.class_eval do
|
5
|
+
protected
|
6
|
+
|
7
|
+
def devise_cas_authenticatable(mapping, controllers)
|
8
|
+
scope :controller => controllers[:cas_sessions], :as => :session do
|
9
|
+
# service endpoint for CAS server
|
10
|
+
get "/", :to => "#{controllers[:cas_sessions]}#service"
|
11
|
+
|
12
|
+
get :new, :path => mapping.path_names[:sign_in], :to => "#{controllers[:cas_sessions]}#create"
|
13
|
+
get :create, :path => mapping.path_names[:sign_in], :as => ""
|
14
|
+
get :destroy, :path => mapping.path_names[:sign_out]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
else
|
19
|
+
# Rails 2
|
20
|
+
|
21
|
+
ActionController::Routing::RouteSet::Mapper.class_eval do
|
22
|
+
protected
|
23
|
+
|
24
|
+
def cas_authenticatable(routes, mapping)
|
25
|
+
routes.with_options(:controller => 'devise/cas_sessions', :name_prefix => nil) do |session|
|
26
|
+
session.connect('/', :action => 'service', :conditions => {:method => :get})
|
27
|
+
session.send(:"new_#{mapping.name}_session", mapping.path_names[:sign_in], :action => 'create', :conditions => {:method => :get})
|
28
|
+
session.send(:"#{mapping.name}_session", mapping.path_names[:sign_in], :action => 'create', :conditions => {:method => :post})
|
29
|
+
session.send(:"destroy_#{mapping.name}_session", mapping.path_names[:sign_out], :action => 'destroy', :conditions => { :method => :get })
|
30
|
+
end
|
9
31
|
end
|
10
32
|
end
|
11
|
-
end
|
33
|
+
end
|
@@ -1,5 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require 'devise/schema'
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Schema
|
5
|
+
def cas_authenticatable
|
6
|
+
if respond_to? :apply_devise_schema
|
7
|
+
apply_devise_schema :username, String
|
8
|
+
else
|
9
|
+
apply_schema :username, String
|
10
|
+
end
|
11
|
+
end
|
4
12
|
end
|
5
|
-
end
|
13
|
+
end
|
@@ -9,7 +9,6 @@ module Devise
|
|
9
9
|
|
10
10
|
def authenticate!
|
11
11
|
ticket = read_ticket(params)
|
12
|
-
RAILS_DEFAULT_LOGGER.debug "Received CAS ticket: #{ticket.inspect}"
|
13
12
|
if ticket
|
14
13
|
if resource = mapping.to.authenticate_with_cas_ticket(ticket)
|
15
14
|
success!(resource)
|
@@ -27,22 +26,26 @@ module Devise
|
|
27
26
|
def returning_from_cas?
|
28
27
|
request.referer =~ /^#{::Devise.cas_client.cas_base_url}/
|
29
28
|
end
|
30
|
-
|
31
|
-
def service_url
|
32
|
-
url = URI.parse(request.url)
|
33
|
-
url.path = "#{mapping.parsed_path}/#{mapping.path_names[:sign_in]}"
|
34
|
-
url.query = nil
|
35
|
-
url.to_s
|
36
|
-
end
|
37
|
-
|
29
|
+
|
38
30
|
def login_url
|
39
31
|
::Devise.cas_client.add_service_to_login_url(service_url)
|
40
32
|
end
|
33
|
+
|
34
|
+
def service_url
|
35
|
+
u = URI.parse(request.url)
|
36
|
+
u.query = nil
|
37
|
+
u.path = if mapping.respond_to?(:fullpath)
|
38
|
+
mapping.fullpath
|
39
|
+
else
|
40
|
+
mapping.raw_path
|
41
|
+
end
|
42
|
+
u.to_s
|
43
|
+
end
|
41
44
|
|
42
45
|
def read_ticket(params)
|
43
46
|
ticket = params[:ticket]
|
44
47
|
return nil unless ticket
|
45
|
-
|
48
|
+
|
46
49
|
if ticket =~ /^PT-/
|
47
50
|
::CASClient::ProxyTicket.new(ticket, service_url, params[:renew])
|
48
51
|
else
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_cas_authenticatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: -1710980575
|
4
5
|
prerelease: true
|
5
6
|
segments:
|
6
7
|
- 1
|
7
8
|
- 0
|
8
9
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.0.
|
10
|
+
- alpha3
|
11
|
+
version: 1.0.0.alpha3
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Nat Budin
|
@@ -15,16 +16,18 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2010-
|
19
|
+
date: 2010-08-27 00:00:00 -04:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
22
23
|
name: devise
|
23
24
|
prerelease: false
|
24
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
25
27
|
requirements:
|
26
|
-
- -
|
28
|
+
- - ">="
|
27
29
|
- !ruby/object:Gem::Version
|
30
|
+
hash: 27
|
28
31
|
segments:
|
29
32
|
- 1
|
30
33
|
- 0
|
@@ -36,9 +39,11 @@ dependencies:
|
|
36
39
|
name: rubycas-client
|
37
40
|
prerelease: false
|
38
41
|
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
39
43
|
requirements:
|
40
44
|
- - ~>
|
41
45
|
- !ruby/object:Gem::Version
|
46
|
+
hash: 11
|
42
47
|
segments:
|
43
48
|
- 2
|
44
49
|
- 1
|
@@ -59,7 +64,7 @@ files:
|
|
59
64
|
- README.md
|
60
65
|
- Rakefile
|
61
66
|
- VERSION
|
62
|
-
- app/controllers/cas_sessions_controller.rb
|
67
|
+
- app/controllers/devise/cas_sessions_controller.rb
|
63
68
|
- devise_cas_authenticatable.gemspec
|
64
69
|
- lib/devise_cas_authenticatable.rb
|
65
70
|
- lib/devise_cas_authenticatable/exceptions.rb
|
@@ -78,16 +83,20 @@ rdoc_options:
|
|
78
83
|
require_paths:
|
79
84
|
- lib
|
80
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
81
87
|
requirements:
|
82
88
|
- - ">="
|
83
89
|
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
84
91
|
segments:
|
85
92
|
- 0
|
86
93
|
version: "0"
|
87
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
88
96
|
requirements:
|
89
97
|
- - ">"
|
90
98
|
- !ruby/object:Gem::Version
|
99
|
+
hash: 25
|
91
100
|
segments:
|
92
101
|
- 1
|
93
102
|
- 3
|
@@ -96,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
105
|
requirements: []
|
97
106
|
|
98
107
|
rubyforge_project:
|
99
|
-
rubygems_version: 1.3.
|
108
|
+
rubygems_version: 1.3.7
|
100
109
|
signing_key:
|
101
110
|
specification_version: 3
|
102
111
|
summary: CAS authentication module for Devise
|
@@ -1,23 +0,0 @@
|
|
1
|
-
class CasSessionsController < ApplicationController
|
2
|
-
include Devise::Controllers::InternalHelpers
|
3
|
-
|
4
|
-
def create
|
5
|
-
resource = authenticate(resource_name)
|
6
|
-
if resource
|
7
|
-
sign_in_and_redirect(resource)
|
8
|
-
elsif warden.result == :redirect
|
9
|
-
throw :warden, :scope => resource_name
|
10
|
-
else
|
11
|
-
throw InvalidCasTicketException.new(params[:ticket])
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def destroy
|
16
|
-
sign_out(resource_name)
|
17
|
-
destination = request.protocol
|
18
|
-
destination << request.host
|
19
|
-
destination << ":#{request.port.to_s}" unless request.port == 80
|
20
|
-
destination << after_sign_out_path_for(resource_name)
|
21
|
-
redirect_to(::Devise.cas_client.logout_url(destination))
|
22
|
-
end
|
23
|
-
end
|