casful_authentication_generator for Rails 2.x applications
Helper methods to make authenticating your site with CAS a little easier. Based on Restful Authentication, and uses the rubycas-client plugin.
Installation
sudo gem install casful_authentication_generator
Usage
In your Rails application’s root folder, run this:
ruby script/generate casful_authentication user https://cas.example.com/
This will install the rubycas-client plugin and will create the helper file and the initializer to set up CAS.
Then, add
include CasAuthentication
to either ApplicationController or specific controllers that need protecting.
Finally, use
before_filter :login_required
to protect your controllers.
Customization
There are a few ways to customize this code:
Locating users
The plugin assumes you have a User table and each user has a login
attribute. When CAS sends the username back to your app, the helpers will look up the user in your table by the login name.
Want to change this? Redefine the locate_user
method in your controller.
def locate_user
User.find_by_username(session[:cas_user]) if session[:cas_user]
end
The name of this method depends on how you called the generator. aIt would be locate_account
if you generated the code using “account” instead of “user”.
Access Denied
By default, the access_denied method will be called if the user supplied by CAS is not found in your system. If you want to change the behavior, implement the method access_denied
in your controller.
def access_denied
render :text => "You don't have access to this"
end
Skipping plugin installation
Run the generator with the --skip-plugin switch to keep it from installing the rubycas-client plugin.
History
0.3.0 = September 23 2010
-
login_from_cas returns the user object now instead of a boolean for current_user. Thought we had this fixed previously.
-
Installs CAS plugin from git://github.com/gunark/rubycas-client.git now instead of the old dead version.
0.2.1 = June 17th, 2010
-
Fixed a nasty bug preventing the current_user variable from being returned correctly
-
Fixed a method name bug in the generator.
0.1.0 = May 26th, 2009
Initial release
Copyright
Copyright © 2009 Brian Hogan. See LICENSE for details.