vibes-rubycas-client 2.3.0.alpha

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 (50) hide show
  1. data/.rvmrc +1 -0
  2. data/.source_index +0 -0
  3. data/CHANGELOG.txt +1 -0
  4. data/Gemfile +15 -0
  5. data/Gemfile.lock +22 -0
  6. data/History.txt +192 -0
  7. data/LICENSE.txt +26 -0
  8. data/README.rdoc +321 -0
  9. data/Rakefile +53 -0
  10. data/VERSION +1 -0
  11. data/examples/merb/.gitignore +18 -0
  12. data/examples/merb/README.textile +12 -0
  13. data/examples/merb/Rakefile +35 -0
  14. data/examples/merb/merb.thor +2020 -0
  15. data/examples/merb/merb_auth_cas.rb +67 -0
  16. data/examples/merb/spec/spec_helper.rb +24 -0
  17. data/examples/rails/README +16 -0
  18. data/examples/rails/app/controllers/advanced_example_controller.rb +31 -0
  19. data/examples/rails/app/controllers/application.rb +2 -0
  20. data/examples/rails/app/controllers/simple_example_controller.rb +16 -0
  21. data/examples/rails/app/views/advanced_example/index.html.erb +13 -0
  22. data/examples/rails/app/views/advanced_example/my_account.html.erb +11 -0
  23. data/examples/rails/app/views/simple_example/index.html.erb +6 -0
  24. data/examples/rails/config/boot.rb +109 -0
  25. data/examples/rails/config/environment.rb +39 -0
  26. data/examples/rails/config/environments/development.rb +17 -0
  27. data/examples/rails/config/environments/production.rb +22 -0
  28. data/examples/rails/config/environments/test.rb +22 -0
  29. data/examples/rails/config/initializers/inflections.rb +10 -0
  30. data/examples/rails/config/initializers/mime_types.rb +5 -0
  31. data/examples/rails/config/initializers/new_rails_defaults.rb +17 -0
  32. data/examples/rails/config/routes.rb +4 -0
  33. data/examples/rails/log/development.log +946 -0
  34. data/examples/rails/log/production.log +0 -0
  35. data/examples/rails/log/server.log +0 -0
  36. data/examples/rails/log/test.log +0 -0
  37. data/examples/rails/script/about +4 -0
  38. data/examples/rails/script/console +3 -0
  39. data/examples/rails/script/server +3 -0
  40. data/lib/casclient.rb +89 -0
  41. data/lib/casclient/client.rb +271 -0
  42. data/lib/casclient/frameworks/merb/filter.rb +105 -0
  43. data/lib/casclient/frameworks/merb/strategy.rb +110 -0
  44. data/lib/casclient/frameworks/rails/cas_proxy_callback_controller.rb +76 -0
  45. data/lib/casclient/frameworks/rails/filter.rb +415 -0
  46. data/lib/casclient/responses.rb +197 -0
  47. data/lib/casclient/tickets.rb +38 -0
  48. data/lib/vibes-rubycas-client.rb +1 -0
  49. data/vibes-rubycas-client.gemspec +100 -0
  50. metadata +198 -0
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ree-1.8.7-2011.03@rubycas-client
Binary file
@@ -0,0 +1 @@
1
+ See History.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.2"
12
+ gem "rcov", ">= 0"
13
+ end
14
+
15
+ gem "activesupport", "~> 2.3.11"
@@ -0,0 +1,22 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (2.3.12)
5
+ git (1.2.5)
6
+ jeweler (1.6.2)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rake (0.9.2)
11
+ rcov (0.9.9)
12
+ shoulda (2.11.3)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ activesupport (~> 2.3.11)
19
+ bundler (~> 1.0.0)
20
+ jeweler (~> 1.6.2)
21
+ rcov
22
+ shoulda
@@ -0,0 +1,192 @@
1
+ = RubyCAS-Client Changelog
2
+
3
+ == Version 2.2.1 :: 2010-06-24
4
+
5
+ * Removed a 3rd party patch to the logging mechanism that broke the client under
6
+ some circumstances. Ouch. 2.2.0 should never have made it through QA.
7
+
8
+ == Version 2.2.0 :: 2010-06-22
9
+
10
+ RubyCAS-Client is now licensed under the MIT License.
11
+ See http://www.opensource.org/licenses/mit-license.php
12
+
13
+ * New functionality:
14
+ * Added config parameter force_ssl_verification (self explanatory) [Roberto Klein]
15
+ * Added explicit SingleSignutFilter for Rails (convenient?) [Adam Elliot]
16
+ * Added support for faking out the filter; useful when testing. See
17
+ http://github.com/gunark/rubycas-client/commit/1eb10cc285d59193eede3d4406f95cad9db9d93a
18
+ [Brian Hogan]
19
+
20
+ * Changes to existing functionality:
21
+ * Unauthorized requests to URLs ending in .xml now show an XML formatted
22
+ response (<errors><error>#{failure_message}</error></errors>) [Roberto Klein]
23
+ * Accepts HTTPFound (302) as a successful response from the CAS server (in
24
+ addition to HTTPSuccess (2xx) [taryneast]
25
+
26
+ * Bug fixes:
27
+ * Got rid of warnings if @valid is not initialized in Responses [jamesarosen]
28
+ * Fixed warning when setting the logger [jamesarosen]
29
+ * Client should no longer crap out when using CAS v1 and extra_attributes is
30
+ empty [jorahood]
31
+
32
+
33
+ == Version 2.1.0 :: 2009-08-18
34
+
35
+ * New functionality:
36
+ * Added an adapter for the Merb framework. Thanks to Andrew O'Brien and
37
+ Antono Vasiljev.
38
+ * Implemented single-sign-out functionality. The client will now intercept
39
+ single-sign-out requests and deal with them appropriately if the
40
+ :enable_single_sign_out config option is set to true. This is currently
41
+ disabled by default. (Currently this is only implemented for the Rails
42
+ adapter)
43
+ * Added logout method to Rails adapter to simplify the logout process. The
44
+ logout method resets the local Rails session and redirects to the CAS
45
+ logout page.
46
+ * Added login_url method to the Rails filter. This will return the login
47
+ URL for the current controller; useful when you want to show a "Login"
48
+ link in a gatewayed page for an unauthenticated user.
49
+ * Added cas_server_is_up? method to the client, as requested in issue #5.
50
+ * Extra user attributes are now automatically unserialized if the incoming data
51
+ is in YAML format.
52
+
53
+ * Changes to existing functionality:
54
+ * The 'service' parameter in the logout method has been renamed to
55
+ 'destination' to better match the behaviour of other CAS clients. So for
56
+ example, when you call logout_url("http://foo.example"), the method will
57
+ now return "https://cas.example?destination=https%3A%2F%2Ffoo.example"
58
+ instead of the old "https://cas.example?service=https%3A%2F%2Ffoo.example".
59
+ RubyCAS-Server has been modified to deal with this as of version 0.6.0.
60
+ * We now accept HTTP responses from the CAS server with status code 422 since
61
+ RubyCAS-Server 0.7.0+ generates these in response to requests that are
62
+ processable but contain invalid CAS data (for example an invalid service
63
+ ticket).
64
+ * Some behind-the-scenes changes to the way previous authentication info is
65
+ reused by the Rails filter in subsequent requests (see the note below
66
+ in the 2.0.1 release). From the user's and integrator's point of view
67
+ there shouldn't be any obvious difference from 2.0.1.
68
+ * Redirection loop interception: The client now logs a warning message when it
69
+ believes that it is stuck in a redirection loop with the CAS server. If more
70
+ than three of these redirects occur within one second, the client will
71
+ redirect back to the login page with renew=1, forcing the user to try
72
+ authenticating again.
73
+ * Somewhat better handling and logging of errors resulting from CAS server
74
+ connection/response problems.
75
+
76
+ * Bug Fixes:
77
+ * Fixed bug where the the service/destination parameter in the logout url
78
+ would sometimes retain the 'ticket' value. The ticket is now automatically
79
+ stripped from the logout url.
80
+ * The client will no longer attempt to retrieve a PGT for an IOU that had
81
+ already been previously retrieved. [yipdw1]
82
+
83
+ * Misc:
84
+ * Added complete CAS client integration examples for Rails and Merb
85
+ applications under /examples.
86
+
87
+ == Version 2.0.1 :: 2008-02-27
88
+
89
+ * The Rails filter no longer by default redirects to the CAS server on
90
+ every request. This restores the behaviour of RubyCAS-Client 1.x.
91
+ In other words, if a session[:cas_user] value exists, the filter
92
+ will assume that the user is authenticated without going through the
93
+ CAS server. This behaviour can be disabled (so that a CAS re-check is
94
+ done on every request) by setting the 'authenticate_on_every_request'
95
+ option to true. See the "Re-authenticating on every request" section
96
+ in the README.txt for details.
97
+
98
+ == Version 2.0.0 :: 2008-02-14
99
+
100
+ * COMPLETE RE-WRITE OF THE ENTIRE CLIENT FROM THE GROUND UP. Oh yes.
101
+ * Core client has been abstracted out of the Rails adapter. It should now
102
+ be possible to use the client in other frameworks (e.g. Camping).
103
+ * Configuration syntax has completely changed. In other words, your old
104
+ rubycas-client-1.x configuration will no longer work. See the README
105
+ for details.
106
+ * Added support for reading extra attributes from the CAS response (i.e. in
107
+ addition to just the username). However currently this is somewhat useless
108
+ since RubyCAS-Server does not yet provide a method for adding extra
109
+ attributes to the responses it generates.
110
+
111
+ ------------------------------------------------------------------------------
112
+
113
+ == Version 1.1.0 :: 2007-12-21
114
+
115
+ * Fixed serious bug having to do with logouts. You can now end the
116
+ CAS session on the client-side (i.e. force the client to re-authenticate)
117
+ by setting session[:casfilteruser] = nil.
118
+ * Added new GatewayFilter. This is identical to the normal Filter but
119
+ has the gateway option set to true by default. This should make
120
+ using the gateway option easier.
121
+ * The CAS::Filter methods are now properly documented.
122
+ * Simplified guess_service produces better URLs when redirecting to the CAS
123
+ server for authentication and the service URL is not explicitly specified.
124
+ [delagoya]
125
+ * The correct method for overriding the service URL for the client is now
126
+ properly documented. You should use service_url=, as server_name= no longer
127
+ works and instead generates a warning message.
128
+ * logout_url() now takes an additional 'service' parameter. If specified, this
129
+ URL will be passed on to the CAS server as part of the logout URL.
130
+
131
+ == Version 1.0.0 :: 2007-07-26
132
+
133
+ * RubyCAS-Client has matured to the point where it is probably safe to
134
+ take it out of beta and release version 1.0.
135
+ * Non-SSL CAS URLs will now work. This may be useful for demo purposes,
136
+ but certainly shouldn't be used in production. The client automatically
137
+ disables SSL if the CAS URL starts with http (rather than https). [rubywmq]
138
+
139
+ == Version 0.12.0
140
+
141
+ * Prior to redirecting to the CAS login page, the client now stores the
142
+ current service URI in a session variable. This value is used to
143
+ validate the service ticket after the user comes back from the CAS
144
+ server's login page. This should address issues where redirection
145
+ from the CAS server resulted in a slightly different URI from the original
146
+ one used prior to login redirection (for example due to variations in the
147
+ way routing rules are applied by the server).
148
+ * The client now handles malformed CAS server responses more gracefully.
149
+ This makes debugging a malfunctioning CAS server somewhat easier.
150
+ * When receiving a proxy-granting ticket, the cas_proxy_callback_controller
151
+ can now take a parameter called 'pgt' (which is what ought to be used
152
+ according to the published CAS spec) or 'pgtId' (which is what the JA-SIG
153
+ CAS server uses).
154
+ * Logging has been somewhat quieted down. Many messages that were previously
155
+ logged as INFO are now logged as DEBUG.
156
+
157
+ == Version 0.11.0
158
+
159
+ * Added this changelog to advise users of major changes to the library.
160
+ * Large chunks of the library have been re-written. Beware of the possibility
161
+ of new bugs (although the re-write was meant to fix a whole slew of existing
162
+ bugs, so you're almost certainly better off upgrading).
163
+ * service and targetService parameters in requests are now properly URI-encoded,
164
+ so the filter should behave properly when your service has query parameters.
165
+ Thanks sakazuki for pointing out the problem.
166
+ * You can now force the CAS client to re-authenticate itself with the CAS server
167
+ (i.e. override the authentication stored in the session) by providing a new
168
+ service ticket in the URI. In other words, the client will authenticate with
169
+ CAS if: a) you have a 'ticket' parameter in the URI, and there is currently no
170
+ authentication info in the session, or b) you have a 'ticket' parameter in the
171
+ URI and this ticket is different than the ticket that was used to authenticat
172
+ the existing session. This is especially useful when you are using CAS proxying,
173
+ since it allows you to force re-authentication in proxied applications (for
174
+ example, when the user has logged out and a new user has logged in in the parent
175
+ proxy-granting application).
176
+ * If your service URI has a 'ticket' parameter, it will now be automatically
177
+ removed when passing the service as a parameter in any CAS request. This is
178
+ done because at least some CAS servers will happily accept a service URI with
179
+ a 'ticket' parameter, which will result in a URI with multiple 'ticket'
180
+ parameters once you are redirected back to CAS (and that in turn can result
181
+ in an endless redirection loop).
182
+ * Logging has been greatly improved, which should make debugging your CAS
183
+ installation much easier. Look for the logs under log/cas_client_RAILS_ENV.log
184
+ * When you install RubyCAS-Client as a Rails plugin, it will now by default
185
+ use a custom logger. You can change this by explicitly setting your own
186
+ logger in your environment.rb, or by modifying the plugin's init.rb.
187
+ * CasProxyCallbackController no longer checks to make sure that the incoming
188
+ request is secure. The check is impossible since the secure header is not
189
+ passed on by at least some reverse proxies (like Pound), and if you are using
190
+ the callback controller then you are almost certainly also using a reverse
191
+ proxy.
192
+ * Cleaned up and updated documentation, fixed some example code.
@@ -0,0 +1,26 @@
1
+ Portions of RubyCAS-Client contributed by Matt Zukowski are copyright (c) 2009 Urbacon Ltd.
2
+ Other portions are copyright of their respective authors.
3
+
4
+ The MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person
7
+ obtaining a copy of this software and associated documentation
8
+ files (the "Software"), to deal in the Software without
9
+ restriction, including without limitation the rights to use,
10
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the
12
+ Software is furnished to do so, subject to the following
13
+ conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
+ OTHER DEALINGS IN THE SOFTWARE.
26
+
@@ -0,0 +1,321 @@
1
+ = RubyCAS-Client
2
+
3
+ Author:: Matt Zukowski <matt AT roughest DOT net>; inspired by code by Ola Bini <ola.bini AT ki DOT se> and Matt Walker <mwalker AT tamu DOT edu>
4
+ Copyright:: Portions contributed by Matt Zukowski are copyright (c) 2009 Urbacon Ltd.
5
+ Other portions are copyright of their respective authors.
6
+ License:: MIT License
7
+ Websites:: http://github.com/gunark/rubycas-client
8
+ http://code.google.com/p/rubycas-client
9
+ http://rubyforge.org/projects/rubycas-client
10
+
11
+
12
+
13
+ === RubyCAS-Client is a Ruby client library for Yale's Central Authentication Service (CAS) protocol.
14
+
15
+ CAS provides a secure single sign on solution for web-based applications. The user logs in to your
16
+ organization's CAS server, and is automatically authenticated for all other CAS-enabled applications.
17
+
18
+ For general information about the open CAS protocol, please have a look at http://www.ja-sig.org/products/cas.
19
+
20
+ If your organization does not already have a CAS server, you may be interested in RubyCAS-Client's sister project,
21
+ RubyCAS-Server[http://code.google.com/p/rubycas-server/].
22
+
23
+ The RubyCAS-Client package includes adapters for Rails and Merb, although the client library itself can be
24
+ adapted for other frameworks (for example an implementation for Camping is available via the Picnic[http://github.com/zuk/picnic/tree/master]
25
+ library).
26
+
27
+
28
+ == Getting help and reporting problems
29
+
30
+ If you need help, try posting to the RubyCAS discussion group at http://groups.google.com/group/rubycas-server.
31
+
32
+ To report problems, please use the Google Code issue tracker at http://code.google.com/p/rubycas-client/issues/list.
33
+
34
+ API documentation (i.e. the RDocs) are available at http://rubycas-client.rubyforge.org
35
+
36
+
37
+ == Installation
38
+
39
+ <b>NOTE:</b> For compatibility with Rails 3 have a look at https://github.com/zuk/rubycas-client-rails
40
+
41
+ You can download the latest version of RubyCAS-Client from the project's rubyforge page at
42
+ http://rubyforge.org/projects/rubycas-client.
43
+
44
+ However, if you're using Rails, it's easier to install the CAS client as a plugin:
45
+
46
+ cd <your rails app>
47
+ ./script/plugin install git://github.com/gunark/rubycas-client.git
48
+
49
+ Alternatively, the library is also installable as a RubyGem[http://rubygems.org]:
50
+
51
+ gem install rubycas-client
52
+
53
+ If your Rails application is under Subversion control, you can also install the plugin as an svn:external, ensuring that
54
+ you always have the latest bleeding-edge version of RubyCAS-Client:
55
+
56
+ ./script/plugin install -x http://svn.github.com/gunark/rubycas-client.git
57
+
58
+
59
+ == Usage Examples
60
+
61
+ If you'd rather jump right in, have a look at the example Rails and Merb applications pre-configured for CAS
62
+ authentication:
63
+
64
+ http://github.com/gunark/rubycas-client/tree/master/examples
65
+
66
+
67
+ Otherwise, continue reading for a step-by-step guide for integrating RubyCAS-Client with Rails:
68
+
69
+
70
+ ==== Using RubyCAS-Client in Rails controllers
71
+
72
+ <i>Note that from this point on we are assuming that you have a working CAS server up and running!</i>
73
+
74
+ After installing RubyCAS-Client as a plugin (see above), add the following to your app's <tt>config/environment.rb</tt>
75
+ (make sure that you put it at the bottom of the file, *after* the Rails Initializer):
76
+
77
+ CASClient::Frameworks::Rails::Filter.configure(
78
+ :cas_base_url => "https://cas.example.foo/"
79
+ )
80
+
81
+ (Change the <tt>:cas_base_url</tt> value to your CAS server's base URL; also note that many CAS servers are configured
82
+ with a base URL that looks more like "https://cas.example.foo/cas".)
83
+
84
+ Then, in your <tt>app/controllers/application.rb</tt> (or in whichever controller you want to add the CAS filter for):
85
+
86
+ before_filter CASClient::Frameworks::Rails::Filter
87
+
88
+ That's it. You should now find that you are redirected to your CAS login page whenever you try to access any action
89
+ in your protected controller. You can of course qualify the <tt>before_filter</tt> as you would with any other ActionController
90
+ filter. For example:
91
+
92
+ before_filter CASClient::Frameworks::Rails::Filter, :except => [ :unprotected_action, :another_unprotected_action ]
93
+
94
+ <b>Once the user has been authenticated, their authenticated username is available under <tt>session[:cas_user]</tt>,</b>
95
+ If you want to do something with this username (for example load a user record from the database), you can append another
96
+ filter method that checks for this value and does whatever you need it to do.
97
+
98
+ <b>Note:</b> If Rails complains about missing constants, try adding this before the CASClient configuration:
99
+
100
+ require 'casclient'
101
+ require 'casclient/frameworks/rails/filter'
102
+
103
+
104
+ ==== A more complicated example
105
+
106
+ Here is a more complicated configuration showing most of the configuration options along with their default values
107
+ (this does not show proxy options, which are covered in the next section):
108
+
109
+ # enable detailed CAS logging
110
+ cas_logger = CASClient::Logger.new(RAILS_ROOT+'/log/cas.log')
111
+ cas_logger.level = Logger::DEBUG
112
+
113
+ CASClient::Frameworks::Rails::Filter.configure(
114
+ :cas_base_url => "https://cas.example.foo/",
115
+ :login_url => "https://cas.example.foo/login",
116
+ :logout_url => "https://cas.example.foo/logout",
117
+ :validate_url => "https://cas.example.foo/proxyValidate",
118
+ :username_session_key => :cas_user,
119
+ :extra_attributes_session_key => :cas_extra_attributes,
120
+ :logger => cas_logger,
121
+ :enable_single_sign_out => true
122
+ )
123
+
124
+ Note that normally it is not necessary to specify <tt>:login_url</tt>, <tt>:logout_url</tt>, and <tt>:validate_url</tt>.
125
+ These values are automatically set to standard CAS defaults based on the given <tt>:cas_base_url</tt>.
126
+
127
+ The <tt>:username_session_key</tt> value determines the key under which you can find the CAS username in the Rails session hash.
128
+
129
+ Any additional info that the CAS server might have supplied about the user during authentication will be found under the
130
+ <tt>:extra_attributes_session_key</tt> value in the Rails session hash (i.e. given the above configuration, you would find this
131
+ info under <tt>session[:cas_extra_attributes]</tt>).
132
+
133
+ An arbitrary Logger instance can be given as the :logger parameter. In the example above we log all CAS activity to a
134
+ <tt>log/cas.log</tt> file in your Rails app's directory.
135
+
136
+ ==== Re-authenticating on every request (i.e. the "single sign-out problem")
137
+
138
+ By default, the Rails filter will only authenticate with the CAS server when no session[:cas_user] value exists. Once the user
139
+ has been authenticated, no further CAS forwarding is done until the user's session is wiped. This saves you
140
+ the trouble of having to do this check yourself (since in most cases it is not advisable to go through the CAS server
141
+ on every request -- this is slow and would potentially lead to problems, for example for AJAX requests). However,
142
+ the disadvantage is that the filter no longer checks to make sure that the user's CAS session is still actually open.
143
+ In other words it is possible for the user's authentication session to be closed on the CAS server without the
144
+ client application knowing about it.
145
+
146
+ To address this, RubyCAS-Client now supports the new "Single Sign-Out" functionality in CAS 3.1, allowing the server to
147
+ notify the client application that the CAS session is closed. The client will automatically intercept Single Sign-Out
148
+ requsts from the CAS server, but in order for this to work you must configure your Rails application as follows:
149
+
150
+ 1. The Rails session store must be set to ActiveRecord: <tt>config.action_controller.session_store = :active_record_store</tt>
151
+ 2. The server must be able to read and write to RAILS_ROOT/tmp/sessions. If you are in a clustered environment,
152
+ the contents of this directory must be shared between all server instances.
153
+ 3. Cross-site request forgery protection must be disabled. In your <tt>application.rb</tt>: <tt>self.allow_forgery_protection = false</tt>.
154
+ (Or rather you may want to disable forgery protection only for actions that are behind the CAS filter.)
155
+ 4. Finally, you must add <tt>:enable_single_sign_out => true</tt> to your CAS client config (a similar option must be
156
+ enabled on the CAS server, if you're using RubyCAS-Server).
157
+
158
+ The best way to debug single-sign out functionality is to configure your CAS client with logging (see above) and then watch the
159
+ log to ensure that single-sign out requests from the server are being processed correctly.
160
+
161
+
162
+ Alternatively, it is possible to disable authentication persistence in the client by setting the <tt>:authenticate_on_every_request</tt>
163
+ configuration option to true as, in the example in the previous section. However, this is not recommended as it will almost
164
+ certainly have a deleterious impact on performance and can interfere with certain HTTP transactions (AJAX requests, for example).
165
+
166
+
167
+ ==== Defining a 'logout' action
168
+
169
+ Your Rails application's controller(s) will probably have some sort of logout function. Here you can do any necessary local
170
+ cleanup, and then call <tt>CASClient::Frameworks::Rails::Filter.logout(controller)</tt>. For example:
171
+
172
+ class ApplicationController < ActionController::Base
173
+
174
+ # ...
175
+
176
+ def logout
177
+ # optionally do some local cleanup here
178
+ # ...
179
+
180
+ CASClient::Frameworks::Rails::Filter.logout(self)
181
+ end
182
+ end
183
+
184
+ By default, the logout method will clear the local Rails session, do some local CAS cleanup, and redirect to the CAS
185
+ logout page. Additionally, the <tt>request.referer</tt> value from the <tt>controller</tt> instance is passed to the
186
+ CAS server as a 'destination' parameter. This allows RubyCAS server to provide a follow-up login page allowing
187
+ the user to log back in to the service they just logged out from using a different username and password. Other
188
+ CAS server implemenations may use this 'destination' parameter in different ways.
189
+
190
+ ==== Gatewayed (i.e. optional) authentication
191
+
192
+ "Gatewaying" essentially allows for optional CAS authentication. Users who already have a pre-existing CAS SSO session
193
+ will be automatically authenticated for the gatewayed service, while those who do not will be allowed to access the service
194
+ without authentication. This is useful for example when you want to show some additional private content on a homepage to
195
+ authenticated users, but also want anonymous users to be able to access the page without first logging in.
196
+
197
+ To allow users to access a page without authenticatin, simply use <tt>CASClient::Frameworks::Rails::GatewayFilter</tt>
198
+ in place of <tt>CASClient::Frameworks::Rails::Filter</tt> in your controller. For example, you may want to require
199
+ CAS authentication for all actions in a controller except the index action:
200
+
201
+ class ExampleController < ApplicationController
202
+ before_filter CASClient::Frameworks::Rails::GatewayFilter, :only => :index
203
+ before_filter CASClient::Frameworks::Rails::Filter, :except => :index
204
+
205
+ # ...
206
+ end
207
+
208
+ To provide a login URL for unauthenticated users:
209
+
210
+ <%= link_to("Login", CASClient::Frameworks::Rails::Filter.login_url(controller)) %>
211
+
212
+ ==== How to act as a CAS proxy
213
+
214
+ CAS 2.0 has a built-in mechanism that allows a CAS-authenticated application to pass on its authentication to other applications.
215
+ An example where this is useful might be a portal site, where the user logs in to a central website and then gets forwarded to
216
+ various other sites that run independently of the portal system (but are always accessed via the portal). The exact mechanism
217
+ behind this is rather complicated so I won't go over it here. If you wish to learn more about CAS proxying, a great walkthrough
218
+ is available at http://www.ja-sig.org/wiki/display/CAS/Proxy+CAS+Walkthrough.
219
+
220
+ RubyCAS-Client fully supports proxying, so a CAS-protected Rails application can act as a CAS proxy.
221
+
222
+ Additionally, RubyCAS-Client comes with a controller that can act as a CAS proxy callback receiver. This is necessary because
223
+ when your application requests to act as a CAS proxy, the CAS server must contact your application to deposit the proxy-granting-ticket
224
+ (PGT). Note that in this case the CAS server CONTACTS YOU, rather than you contacting the CAS server (as in all other CAS operations).
225
+
226
+ Confused? Don't worry, you don't really have to understand this to use it. To enable your Rails app to act as a CAS proxy,
227
+ all you need to do is this:
228
+
229
+ In your <tt>config/environment.rb</tt>:
230
+
231
+ # enable detailed CAS logging for easier troubleshooting
232
+ cas_logger = CASClient::Logger.new(RAILS_ROOT+'/log/cas.log')
233
+ cas_logger.level = Logger::DEBUG
234
+
235
+ CASClient::Frameworks::Rails::Filter.configure(
236
+ :cas_base_url => "https://cas.example.foo/",
237
+ :proxy_retrieval_url => "https://cas-proxy-callback.example.foo/cas_proxy_callback/retrieve_pgt",
238
+ :proxy_callback_url => "https://cas-proxy-callback.example.foo/cas_proxy_callback/receive_pgt",
239
+ :logger => cas_logger
240
+ )
241
+
242
+ In <tt>config/routes.rb</tt> make sure that you have a route that will allow requests to /cas_proxy_callback/:action to be routed to the
243
+ CasProxyCallbackController. This should work as-is with the standard Rails routes setup, but if you have disabled the default
244
+ route, you should add the following:
245
+
246
+ map.cas_proxy_callback 'cas_proxy_callback/:action', :controller => 'cas_proxy_callback'
247
+
248
+ Now here's a big giant caveat: <b>your CAS callback application and your CAS proxy application must run on separate Rails servers</b>.
249
+ In other words, if you want a Rails app to act as a CAS ticket-granting proxy, the cas_proxy_callback controller
250
+ must run on a different server. This is because Rails does not properly support handling of concurrent requests. The CAS proxy mechanism
251
+ acts in such a way that if your proxy application and your callback controller were on the same server
252
+ you would end up with a deadlock (the CAS server would be waiting for its callback to be accepted by your Rails server,
253
+ but your Rails server wouldn't respond to the CAS server's callback until the CAS server responded back first).
254
+
255
+ The simplest workaround is this:
256
+
257
+ 1. Create an empty rails app (i.e. something like <tt>rails cas_proxy_callback</tt>)
258
+ 2. Make sure that you have the CAS plugin installed. If you installed it as a gem, you don't have to do anything since
259
+ it is already installed. If you want to install as a plugin, see the instructions in the "Installing" section above.
260
+ 3. Make sure that the server is up and running, and configure your proxy_callback_url and proxy_retrieval_url to point
261
+ to the new server as described above (or rather, make Pound point to the new server, if that's how you're handling https).
262
+
263
+ That's it. The proxy_callback_controller doesn't require any additional configuration. It doesn't access the database
264
+ or anything of that sort.
265
+
266
+ Once your user logs in to CAS via your application, you can do the following to obtain a service ticket that can then be used
267
+ to authenticate another application:
268
+
269
+ service_uri = "http://some-other-application.example.foo"
270
+ proxy_granting_ticket = session[:cas_pgt]
271
+ proxy_ticket = CASClient::Frameworks::Rails::Filter.client.request_proxy_ticket(service_uri, proxy_granting_ticket)
272
+
273
+ <tt>proxy_ticket</tt> should now contain a valid proxy ticket. You can use it to authenticate other services by sending it together with
274
+ the service URI as parameters to your target application:
275
+
276
+ http://some-other-application.example.foo?service=#{CGI::escape(proxy_ticket.service)}&ticket=#{proxy_ticket.ticket}
277
+
278
+ This is of course assuming that http://some-other-application.example.foo is also protected by the CAS filter.
279
+ Note that you should always URI-encode your service parameter inside URIs!
280
+
281
+ Note that #request_proxy_ticket returns a CASClient::ProxyTicket object, which is why we need to call #ticket on it
282
+ to retrieve the actual service ticket string.
283
+
284
+ ===== Additional proxying notes and caveats
285
+
286
+ <b>The proxy url must be an https address.</b> Otherwise CAS will refuse to communicate with it. This means that if you are using
287
+ the bundled cas_proxy_callback controller, you will have to host your application on an https-enabled server. This can be a bit
288
+ tricky with Rails. WEBrick's SSL support is difficult to configure, and Mongrel doesn't support SSL at all. One workaround is to
289
+ use a reverse proxy like Pound[http://www.apsis.ch/pound/], which will accept https connections and locally re-route them
290
+ to your Rails application. Also, note that <i>self-signed SSL certificates likely won't work</i>. You will probably need to use
291
+ a real certificate purchased from a trusted CA authority (there are ways around this, but good luck :)
292
+
293
+
294
+ == SSL Support
295
+
296
+ Make sure you have the Ruby OpenSSL library installed. Otherwise you may get errors like:
297
+
298
+ no such file to load -- net/https
299
+
300
+ To install the library on an Debian/Ubuntu system:
301
+
302
+ sudo apt-get install libopenssl-ruby
303
+
304
+ For other platforms you'll have to figure it out yourself.
305
+
306
+ == Testing
307
+
308
+ In some cases, especially those using Cucumber or other tools that simply can't work with
309
+ CAS, it may be necessary to work around CAS instead.
310
+
311
+ In your test or Cucumber step definition, simply fake out CAS.
312
+
313
+ CASClient::Frameworks::Rails::Filter.fake("homer")
314
+
315
+ This functionality was present in the original version of this plugin.
316
+ The value of the username is stored in session[:cas_user] (or the user specified field) and session[:casfilteruser] for backwards-compatibility.
317
+
318
+ == License
319
+
320
+ RubyCAS-Client is licensed for use under the terms of the MIT License.
321
+ See the LICENSE.txt file bundled with the official RubyCAS-Client distribution for details.