casablanca 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,17 @@
1
+ === 0.1.0 / 2009-02-18
2
+
3
+ * 1 major enhancement
4
+
5
+ * Implemented gatewaying for rails filter
6
+
1
7
  === 0.0.2 / 2009-01-07
2
8
 
3
9
  * 1 major enhancement
4
10
 
5
- * Implmented renew
11
+ * Implemented renew
6
12
  * Added logger
7
13
 
8
- === 0.0.2 / 2009-01-07
14
+ === 0.0.1 / 2009-01-07
9
15
 
10
16
  * 1 major enhancement
11
17
 
@@ -2,15 +2,18 @@ History.txt
2
2
  Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
- init.rb
6
5
  bin/casablanca
6
+ init.rb
7
7
  lib/casablanca.rb
8
8
  lib/casablanca/cli.rb
9
9
  lib/casablanca/client.rb
10
- lib/casablanca/filters/rails.rb
10
+ lib/casablanca/rails/cas_proxy_callback_controller.rb
11
+ lib/casablanca/rails/filter.rb
11
12
  lib/casablanca/response_parsers.rb
13
+ test/mocks.rb
12
14
  test/test_client.rb
13
15
  test/test_helper.rb
14
16
  test/test_parser.rb
17
+ test/test_rails_cas_proxy_callback_controller.rb
15
18
  test/test_rails_filter.rb
16
- test/test_ticket.rb
19
+ test/test_ticket.rb
data/README.txt CHANGED
@@ -4,20 +4,20 @@
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
- Casablanca is a single sign-on client for the CAS 2.0 protocol.
7
+ Casablanca is a ruby single sign-on client for the CAS 2.0 protocol.
8
8
 
9
9
  == FEATURES:
10
10
 
11
11
  * Includes a commandline Client to test getting service tickets from a CAS server
12
12
  * It can be run as a Rails plugin.
13
- * Gatewaying (permitting the user to continue without authentication).
13
+ * Gatewaying (permitting the user to continue without authentication) is not implemented.
14
+ Just skip the filter for those actions.
14
15
 
15
16
  == TODO:
16
17
 
17
18
  * Add extra attributes returned from the server
18
- * Implement proxing
19
+ * Implement proxying
19
20
  * Check for single signout
20
- * Check for endless redirects
21
21
 
22
22
  == SYNOPSIS:
23
23
 
@@ -39,16 +39,15 @@ In IRB:
39
39
  In a Rails project:
40
40
  - environment.rb:
41
41
 
42
- Casablanca::RailsFilter.config do |config|
42
+ Casablanca::Rails::Config.config do |config|
43
43
  config[:cas_server_url] = "http://localhost:4567"
44
- config[:service_url] = "http://localhost:3000"
45
44
  # Always require new credentials for authentication
46
45
  config[:renew] = true
47
46
  end
48
47
 
49
48
  - Add the following to application.rb:
50
49
 
51
- before_filter Casablanca::RailsFilter
50
+ before_filter Casablanca::Rails::Filter
52
51
 
53
52
  def current_person
54
53
  @current_person ||= login_from_cas unless @current_person == false
@@ -64,7 +63,7 @@ In a Rails project:
64
63
 
65
64
  - Add the following to you logout action
66
65
 
67
- Casablanca::RailsFilter.logout(self)
66
+ Casablanca::Rails::Filter.logout(self)
68
67
 
69
68
  == REQUIREMENTS:
70
69
 
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'hoe'
5
5
  require 'lib/casablanca.rb'
6
6
 
7
7
  Hoe.new('casablanca', Casablanca::VERSION) do |p|
8
- p.developer('FIX', 'FIX@example.com')
8
+ p.developer('Petrik de Heus', 'FIX@example.com')
9
9
  p.remote_rdoc_dir = '' # Release to root
10
10
  end
11
11
 
data/init.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  $: << File.expand_path(File.dirname(__FILE__))+'/lib'
2
2
  require 'casablanca'
3
- require 'casablanca/filters/rails'
3
+ require 'casablanca/rails/filter'
@@ -1,5 +1,5 @@
1
1
  module Casablanca
2
- VERSION = '0.0.3'
2
+ VERSION = '0.1.0'
3
3
  end
4
4
  require 'casablanca/client'
5
5
  require 'casablanca/response_parsers'
@@ -28,7 +28,9 @@ module Casablanca
28
28
  def login_url(params={})
29
29
  uri = URI.parse("#{@cas_server_url}/login")
30
30
  query = {:service => @service_url}
31
+ # TODO Check that only one of these can be set
31
32
  query[:renew] = 'true' if params[:renew]
33
+ query[:gateway] = 'true' if params[:gateway]
32
34
  uri.merge_query(query)
33
35
  uri.to_s
34
36
  end
@@ -0,0 +1,2 @@
1
+ class CasProxyCallbackController < ActionController::Base
2
+ end
@@ -0,0 +1,157 @@
1
+ module Casablanca::Rails
2
+
3
+ class Config
4
+
5
+ class << self
6
+
7
+ ##
8
+ # Configure the client
9
+ #
10
+ # Casablanca::Rails::Config.config do |config|
11
+ # config[:cas_server_url] = "http://localhost:4567"
12
+ # # Always require new credentials for authentication
13
+ # config[:renew] = true
14
+ # end
15
+ def config
16
+ config = {}
17
+ yield config
18
+ @cas_server_url = config[:cas_server_url]
19
+ @renew = config[:renew] # always renew the session
20
+ # set logger to rails logger
21
+ Casablanca::Client.logger = ::ActionController::Base.logger
22
+ end
23
+
24
+ def renew
25
+ @renew
26
+ end
27
+
28
+ def cas_server_url
29
+ @cas_server_url
30
+ end
31
+
32
+ end
33
+ end
34
+
35
+ class Filter
36
+
37
+ class << self
38
+
39
+ ##
40
+ # Require a authenticated user to the CAS server otherwise redirect to
41
+ # the CAS server login url.
42
+ # Set session[:cas_user] to the authenticated CAS user if authenticated
43
+ def filter(controller)
44
+ if authentication_required?(controller)
45
+ return get_credentials(controller)
46
+ elsif controller.params[:ticket]
47
+ return authenticate_ticket(controller)
48
+ else
49
+ return true
50
+ end
51
+ end
52
+
53
+ ##
54
+ # The login url of the Cas server. This page has the login form.
55
+ def login_url(controller, params={})
56
+ client = Casablanca::Client.new(:cas_server_url => Config.cas_server_url, :service_url => service_url(controller))
57
+ client.login_url(params)
58
+ end
59
+
60
+ ##
61
+ # The logout url of the Cas server.
62
+ def logout_url(controller, params={})
63
+ client = Casablanca::Client.new(:cas_server_url => Config.cas_server_url, :service_url => service_url(controller))
64
+ client.logout_url(params)
65
+ end
66
+
67
+ ##
68
+ # Logs out of the Cas server.
69
+ def logout(controller)
70
+ controller.session[:cas_user] = nil
71
+ end
72
+
73
+ def logger
74
+ Casablanca::Client.logger
75
+ end
76
+
77
+ # Always require new credentials for authentication?
78
+ def renew?
79
+ Config.renew
80
+ end
81
+
82
+ # Has the user already talked to the Cas server?
83
+ def authentication_required?(controller)
84
+ (controller.session[:cas_user].nil? || renew?) && controller.params[:ticket].nil?
85
+ end
86
+
87
+ def redirect_to_cas_login(controller, renew)
88
+ controller.session[:cas_renew] = renew
89
+ controller.send(:redirect_to, login_url(controller, :renew => renew))
90
+ end
91
+
92
+ def get_credentials(controller)
93
+ if renew?
94
+ logger.debug "Always require credentials for authentication"
95
+ else
96
+ logger.debug "Not authenticated yet. Ticket parameter required"
97
+ end
98
+ redirect_to_cas_login(controller, renew?)
99
+ return false
100
+ end
101
+
102
+ def authenticate_ticket(controller)
103
+ client = Casablanca::Client.new(:cas_server_url => Config.cas_server_url, :service_url => service_url(controller))
104
+ ticket = Casablanca::Ticket.new(controller.params[:ticket], client.service_url, controller.session[:cas_renew])
105
+ if client.authenticate_ticket(ticket)
106
+ logger.debug "Ticket authenticated"
107
+ controller.session[:cas_user] = ticket.user
108
+ controller.session[:cas_renew] = nil
109
+ return true
110
+ else
111
+ logger.debug "Ticket authentication failed: #{ticket.failure_message}"
112
+ logout(controller)
113
+ logger.debug "Renew login credentials"
114
+ redirect_to_cas_login(controller, renew?)
115
+ return false
116
+ end
117
+ end
118
+
119
+ private
120
+
121
+ def service_url(controller)
122
+ params = controller.params.merge(:only_path => false).dup
123
+ params.delete(:ticket)
124
+ controller.url_for(params)
125
+ end
126
+
127
+ end
128
+ end
129
+
130
+
131
+ class GatewayFilter < Filter
132
+
133
+ class << self
134
+
135
+ # # Has the user already talked to the Cas server?
136
+ # def authentication_required?(controller)
137
+ # super(controller)
138
+ # end
139
+
140
+ def get_credentials(controller)
141
+ if controller.session[:cas_gatewayed]
142
+ logger.debug "Allow user without credentials because gateway is set"
143
+ return true
144
+ end
145
+ return super(controller)
146
+ end
147
+
148
+ def redirect_to_cas_login(controller, renew)
149
+ controller.session[:cas_gatewayed] = true
150
+ logger.debug "Redirecting to #{login_url(controller, :gateway => true)}"
151
+ controller.send(:redirect_to, login_url(controller, :gateway => true))
152
+ end
153
+
154
+ end
155
+ end
156
+
157
+ end
@@ -0,0 +1,66 @@
1
+
2
+ class MockResponse < Net::HTTPResponse
3
+ attr_accessor :body, :code
4
+ def initialize(body, code=200, header={})
5
+ @body, @code, @header = body, code, header
6
+ end
7
+
8
+ def []= key, value
9
+ @header[key.to_sym] = value
10
+ end
11
+
12
+ def [] key
13
+ @header[key.to_sym]
14
+ end
15
+
16
+ def kind_of?(klass)
17
+ if klass == Net::HTTPSuccess
18
+ code.to_i == 200
19
+ end
20
+ end
21
+ end
22
+
23
+ module ActionController
24
+ class Base
25
+ def self.logger
26
+ @logger = ::Logger.new($stderr)
27
+ @logger.level = LOGGER_LEVEL
28
+ @logger
29
+ end
30
+ end
31
+ end
32
+
33
+ class Controller < ActionController::Base
34
+ attr_accessor :params, :session
35
+ def initialize
36
+ @session = {}
37
+ end
38
+
39
+ def request
40
+ Request.new
41
+ end
42
+
43
+ def url_for(url)
44
+ if url.is_a? Hash
45
+ return "http://localhost:3000" if url[:only_path] == false
46
+ end
47
+ url
48
+ end
49
+
50
+ def redirect_to(url)
51
+ end
52
+
53
+ private
54
+
55
+ def reset_session
56
+ @session = {}
57
+ end
58
+ end
59
+
60
+ class Request
61
+ def headers
62
+ {}
63
+ end
64
+ def post?
65
+ end
66
+ end
@@ -92,9 +92,9 @@ class TestCommandLineClient < Test::Unit::TestCase
92
92
  mock_get_service_ticket(@client)
93
93
  service_ticket = @client.login('admin', 'admin')
94
94
  assert_equal 37, @client.ticket_granting_ticket.size
95
- # if MOCK_REQUESTS
96
- # @client.expects(:get).returns(MockResponse.new(body, '200', :location => 'http://localhost:3000?ticket=ST-1231341579r871C5757B79767C21E'))
97
- # end
95
+ if MOCK_REQUESTS
96
+ @client.expects(:get).returns(MockResponse.new('<html></html>', '200', :location => 'http://localhost:3000?ticket=ST-1231341579r871C5757B79767C21E'))
97
+ end
98
98
  service_ticket = @client.logout
99
99
  assert_equal nil, @client.ticket_granting_ticket
100
100
  end
@@ -103,9 +103,9 @@ class TestCommandLineClient < Test::Unit::TestCase
103
103
  mock_get_service_ticket(@client)
104
104
  service_ticket = @client.login('admin', 'admin')
105
105
  assert_equal 37, @client.ticket_granting_ticket.size
106
- # if MOCK_REQUESTS
107
- # @client.expects(:get).returns(MockResponse.new(body, '200', :location => 'http://localhost:3000?ticket=ST-1231341579r871C5757B79767C21E'))
108
- # end
106
+ if MOCK_REQUESTS
107
+ @client.expects(:get).returns(MockResponse.new('<html></html>', '200', :location => 'http://localhost:3000?ticket=ST-1231341579r871C5757B79767C21E'))
108
+ end
109
109
  service_ticket = @client.logout('follow_url')
110
110
  assert_equal nil, @client.ticket_granting_ticket
111
111
  # TODO check for follow_url
@@ -1,11 +1,16 @@
1
- require(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'casablanca.rb')))
2
- require(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'casablanca', 'filters', 'rails.rb')))
3
1
  require 'test/unit'
4
2
  require 'rubygems'
5
3
  require 'mocha'
4
+ # require 'logger'
5
+ require(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'casablanca.rb')))
6
+ require(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'casablanca', 'client.rb')))
7
+ require(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'casablanca', 'rails', 'filter.rb')))
8
+ require(File.expand_path(File.join(File.dirname(__FILE__), 'mocks.rb')))
9
+ require(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'casablanca', 'rails', 'cas_proxy_callback_controller.rb')))
6
10
 
7
11
  # set to false if you're integration testing against a real server
8
- MOCK_REQUESTS = true
12
+ MOCK_REQUESTS = true unless defined? MOCK_REQUESTS
13
+ LOGGER_LEVEL = Logger::WARN unless defined? LOGGER_LEVEL
9
14
 
10
15
  class Test::Unit::TestCase
11
16
  include Casablanca
@@ -31,27 +36,7 @@ class Test::Unit::TestCase
31
36
  end
32
37
  end
33
38
 
34
- class MockResponse < Net::HTTPResponse
35
- attr_accessor :body, :code
36
- def initialize(body, code=200, header={})
37
- @body, @code, @header = body, code, header
38
- end
39
-
40
- def []= key, value
41
- @header[key.to_sym] = value
42
- end
43
-
44
- def [] key
45
- @header[key.to_sym]
46
- end
47
-
48
- def kind_of?(klass)
49
- if klass == Net::HTTPSuccess
50
- code.to_i == 200
51
- end
52
- end
53
- end
54
-
39
+ unless defined? VALID_REQUEST
55
40
  VALID_REQUEST = %(
56
41
  <cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
57
42
  <cas:authenticationSuccess>
@@ -74,4 +59,5 @@ INVALID_TICKET = %(
74
59
  Ticket ST-1231242314r72465638160B31E8D1 not recognized.
75
60
  </cas:authenticationFailure>
76
61
  </cas:serviceResponse>
77
- )
62
+ )
63
+ end
@@ -0,0 +1,6 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper.rb')
2
+
3
+ class TestRailsCasProxyCallbackController < Test::Unit::TestCase
4
+ def test_default
5
+ end
6
+ end
@@ -1,51 +1,59 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper.rb')
1
+ require File.join(File.dirname(__FILE__), 'test_helper.rb')
2
+
3
+ class TestRailsConfig < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @controller = Controller.new
7
+ @controller.params = {}
8
+ end
9
+
10
+ def test_config
11
+ Rails::Config.config do |config|
12
+ config[:cas_server_url] = "http://example.com/cas_server"
13
+ config[:renew] = true
14
+ end
15
+ assert_equal 'http://example.com/cas_server/login?service=http%3A%2F%2Flocalhost%3A3000', Rails::Filter.login_url(@controller)
16
+ assert_equal true, Rails::Filter.renew?
17
+ end
18
+
19
+ end
2
20
 
3
21
  class TestRailsFilter < Test::Unit::TestCase
22
+ include Casablanca::Rails
4
23
  def setup
5
- Casablanca::RailsFilter.config do |config|
24
+ Config.config do |config|
6
25
  config[:cas_server_url] = "http://localhost:4567"
7
- config[:service_url] = "http://localhost:3000"
8
26
  end
9
27
  @controller = Controller.new
10
- @controller.params = {}
28
+ @controller.params = {}
11
29
  end
12
30
 
13
31
  def test_login_url
14
- assert_equal 'http://localhost:4567/login?service=http%3A%2F%2Flocalhost%3A3000', RailsFilter.login_url
32
+ assert_equal 'http://localhost:4567/login?service=http%3A%2F%2Flocalhost%3A3000', Filter.login_url(@controller)
15
33
  end
16
34
 
17
35
  def test_login_url_with_params
18
- url = RailsFilter.login_url(:renew => true)
36
+ url = Filter.login_url(@controller, :renew => true)
19
37
  assert_equal true, (url =~ /service\=http%3A%2F%2Flocalhost%3A3000/) > 0
20
38
  assert_equal true, (url =~ /renew\=true/) > 0
21
39
  end
22
40
 
23
41
  def test_logout_url
24
- assert_equal 'http://localhost:4567/logout?', RailsFilter.logout_url
42
+ assert_equal 'http://localhost:4567/logout?', Filter.logout_url(@controller)
25
43
  end
26
44
 
27
45
  def test_logout
28
46
  @controller.session = { :cas_user => 'admin' }
29
- RailsFilter.logout(@controller)
47
+ Filter.logout(@controller)
30
48
  assert_equal({:cas_user=>nil }, @controller.session)
31
49
  end
32
-
33
- def test_config
34
- Casablanca::RailsFilter.config do |config|
35
- config[:cas_server_url] = "http://example.com/cas_server"
36
- config[:service_url] = "http://example.com/application"
37
- end
38
- # assert_equal "http://example.com/cas_server", RailsFilter.client.cas_server_url
39
- # assert_equal "http://example.com/application", RailsFilter.client.service_url
40
- assert_equal 'http://example.com/cas_server/login?service=http%3A%2F%2Fexample.com%2Fapplication', RailsFilter.login_url
41
- end
42
50
 
43
51
  def test_filter_invalid_attempt
44
52
  service_ticket = get_service_ticket
45
53
  params = {:ticket => 'service_ticket.ticket'}
46
54
  mock_authenticate_ticket(INVALID_REQUEST)
47
55
  @controller.params = params
48
- assert_equal false, RailsFilter.filter(@controller)
56
+ assert_equal false, Filter.filter(@controller)
49
57
  end
50
58
 
51
59
  def test_filter_authenticated_with_valid_ticket_from_request
@@ -53,58 +61,60 @@ class TestRailsFilter < Test::Unit::TestCase
53
61
  params = {:ticket => service_ticket.ticket}
54
62
  mock_authenticate_ticket(VALID_REQUEST)
55
63
  @controller.params = params
56
- assert_equal true, RailsFilter.filter(@controller)
64
+ assert_equal true, Filter.filter(@controller)
57
65
  assert_equal 'admin', @controller.session[:cas_user]
58
66
  end
59
67
 
60
68
  def test_filter_already_authenticated_with_valid_ticket_from_session
61
69
  service_ticket = get_service_ticket
62
70
  @controller.session = {:cas_user => 'admin'}
63
- mock_authenticate_ticket(VALID_REQUEST)
64
- assert_equal true, RailsFilter.filter(@controller)
71
+ assert_equal true, Filter.filter(@controller)
65
72
  assert_equal 'admin', @controller.session[:cas_user]
66
73
  end
74
+
75
+ def test_filter_already_authenticated_with_valid_ticket_from_session_but_renew_required
76
+ Config.config do |config|
77
+ config[:cas_server_url] = "http://localhost:4567"
78
+ config[:renew] = true
79
+ end
80
+ service_ticket = get_service_ticket
81
+ @controller.session = {:cas_user => 'admin'}
82
+ assert_equal false, Filter.filter(@controller)
83
+ assert_equal 'admin', @controller.session[:cas_user]
84
+ end
67
85
 
68
- end
69
-
70
- module ActionController
71
- module Base
72
- def self.logger
73
- @logger = ::Logger.new($stderr)
74
- @logger.level = ::Logger::ERROR
75
- @logger
76
- end
86
+ def test_filter_not_authenticated
87
+ assert_equal false, Filter.filter(@controller)
77
88
  end
78
- end
79
89
 
80
- class Controller # < ActionController::Base
81
- attr_accessor :params, :session
82
- def initialize
83
- @session = {}
84
- end
85
-
86
- def request
87
- Request.new
88
- end
89
-
90
- def url_for(url)
91
- url
92
- end
93
-
94
- def redirect_to(url)
95
- end
96
-
97
- private
98
-
99
- def reset_session
100
- @session = {}
90
+ def test_filter_not_authenticated
91
+ assert_equal false, Filter.filter(@controller)
101
92
  end
93
+
102
94
  end
103
95
 
104
- class Request
105
- def headers
106
- {}
96
+ class TestRailsGatewayFilter < TestRailsFilter
97
+ def setup
98
+ Config.config do |config|
99
+ config[:cas_server_url] = "http://localhost:4567"
100
+ end
101
+ @controller = Controller.new
102
+ @controller.params = {}
103
+ end
104
+
105
+ def test_filter_not_authenticated_sets_cas_gatewayed
106
+ # service_ticket = get_service_ticket
107
+ #mock_authenticate_ticket(VALID_REQUEST)
108
+ assert_equal false, GatewayFilter.filter(@controller)
109
+ assert_equal true, @controller.session[:cas_gatewayed]
107
110
  end
108
- def post?
111
+
112
+ def test_filter_not_authenticated_already_tried
113
+ # service_ticket = get_service_ticket
114
+ @controller.session = {:cas_gatewayed => true}
115
+ #mock_authenticate_ticket(VALID_REQUEST)
116
+ assert_equal true, GatewayFilter.filter(@controller)
117
+ assert_equal nil, @controller.session[:cas_user]
109
118
  end
119
+
110
120
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casablanca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - FIX
7
+ - Petrik de Heus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-24 00:00:00 +01:00
12
+ date: 2009-02-18 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,7 +22,7 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 1.8.3
24
24
  version:
25
- description: Casablanca is a single sign-on client for the CAS 2.0 protocol.
25
+ description: Casablanca is a ruby single sign-on client for the CAS 2.0 protocol.
26
26
  email:
27
27
  - FIX@example.com
28
28
  executables:
@@ -38,16 +38,19 @@ files:
38
38
  - Manifest.txt
39
39
  - README.txt
40
40
  - Rakefile
41
- - init.rb
42
41
  - bin/casablanca
42
+ - init.rb
43
43
  - lib/casablanca.rb
44
44
  - lib/casablanca/cli.rb
45
45
  - lib/casablanca/client.rb
46
- - lib/casablanca/filters/rails.rb
46
+ - lib/casablanca/rails/cas_proxy_callback_controller.rb
47
+ - lib/casablanca/rails/filter.rb
47
48
  - lib/casablanca/response_parsers.rb
49
+ - test/mocks.rb
48
50
  - test/test_client.rb
49
51
  - test/test_helper.rb
50
52
  - test/test_parser.rb
53
+ - test/test_rails_cas_proxy_callback_controller.rb
51
54
  - test/test_rails_filter.rb
52
55
  - test/test_ticket.rb
53
56
  has_rdoc: true
@@ -73,13 +76,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
76
  requirements: []
74
77
 
75
78
  rubyforge_project: casablanca
76
- rubygems_version: 1.2.0
79
+ rubygems_version: 1.3.1
77
80
  signing_key:
78
81
  specification_version: 2
79
- summary: Casablanca is a single sign-on client for the CAS 2.0 protocol.
82
+ summary: Casablanca is a ruby single sign-on client for the CAS 2.0 protocol.
80
83
  test_files:
81
84
  - test/test_client.rb
82
85
  - test/test_helper.rb
83
86
  - test/test_parser.rb
87
+ - test/test_rails_cas_proxy_callback_controller.rb
84
88
  - test/test_rails_filter.rb
85
89
  - test/test_ticket.rb
@@ -1,88 +0,0 @@
1
- module Casablanca
2
- class RailsFilter
3
-
4
- class << self
5
-
6
- ##
7
- # Configure the client
8
- #
9
- # Casablanca::RailsFilter.config do |config|
10
- # config[:cas_server_url] = "http://localhost:4567"
11
- # config[:service_url] = "http://localhost:3000"
12
- # end
13
- def config
14
- config = {}
15
- yield config
16
- @cas_server_url = config[:cas_server_url]
17
- @service_url = config[:service_url]
18
- @renew = config[:renew] # always renew the session
19
- # set logger to rails logger
20
- Client.logger = ::ActionController::Base.logger
21
- end
22
-
23
- def filter(controller)
24
-
25
- client = Client.new(:cas_server_url => @cas_server_url, :service_url => @service_url)
26
- if !controller.session[:cas_user] && !controller.params[:ticket]
27
- if renew?
28
- logger.debug "Always require credentials for authentication"
29
- else
30
- logger.debug "Not authenticated yet. Ticket parameter required"
31
- end
32
- redirect_to_cas_login(controller, renew?)
33
- return false
34
- end
35
- ticket = Ticket.new(controller.params[:ticket], client.service_url, controller.session[:cas_renew])
36
- if client.authenticate_ticket(ticket)
37
- logger.debug "Ticket authenticated"
38
- controller.session[:cas_user] = ticket.user
39
- controller.session[:cas_renew] = nil
40
- return true
41
- else
42
- logger.warn "Ticket authentication failed: #{ticket.failure_message}"
43
- logout(controller)
44
- logger.debug "Renew login credentials"
45
- redirect_to_cas_login(controller, true)
46
- return false
47
- end
48
- end
49
-
50
- ##
51
- # The login url of the Cas server. This page has the login form.
52
- def login_url(params={})
53
- client = Client.new(:cas_server_url => @cas_server_url, :service_url => @service_url)
54
- client.login_url(params)
55
- end
56
-
57
- ##
58
- # The logout url of the Cas server.
59
- def logout_url(params={})
60
- client = Client.new(:cas_server_url => @cas_server_url, :service_url => @service_url)
61
- client.logout_url(params)
62
- end
63
-
64
- ##
65
- # Logs out of the Cas server.
66
- def logout(controller)
67
- controller.session[:cas_user] = nil
68
- end
69
-
70
- def logger
71
- Client.logger
72
- end
73
-
74
- private
75
-
76
- def redirect_to_cas_login(controller, renew)
77
- controller.session[:cas_renew] = renew
78
- controller.send(:redirect_to, login_url(:renew => renew))
79
- end
80
-
81
- def renew?
82
- @renew
83
- end
84
-
85
- end
86
- end
87
-
88
- end