Repository is archived
No commit activity in last 3 years
No release in over 3 years
Generator to quickly put CAS authentication on your Rails application. Provides a currnet_user method to controllers and views to make it work like Restful Authentication and other plugins.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

casful_authentication_generator for Rails 3.x applications¶ ↑

Helper methods to make authenticating your site with CAS a little easier. Based on Restful Authentication, and uses the rubycas-client gem.

Installation¶ ↑

sudo gem install casful_authentication_generator

Usage¶ ↑

In your Rails application’s root folder, run this:

rails g casful_authentication user https://cas.example.com/

This will add the rubycas-client gem to your Gemfile and will create the helper file and the initializer to set up CAS.

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 gem installation¶ ↑

Run the generator with the --skip-gem switch to keep it from installing the rubycas-client gem.

Testing with Cucumber¶ ↑

Working with CAS and Cucumber can be somewhat tricky, so you can use the Fake capabilities of the CAS client library. You can use a matcher like this to set the session variable with the username you desire, and your application will think that a user has been logged in to CAS elsewhere.

Given /^I have authenticated to Central Authentication with my username "([^"]*)"$/ do |username|
  CASClient::Frameworks::Rails::Filter.fake(username)
end

This approach can also be useful when testing with other methods.

Known issues¶ ↑

* No baked in support for handling situations where you want users who are not in CAS to authenticate. This is in the works.

History¶ ↑

0.5.1 = February 16th, 2012¶ ↑

  • Updated to use the rubycas-client gem instead of the plugin.

0.5.0 = May 11th, 2011¶ ↑

  • Updated to work in rails 3.

0.4.1 = February 14th, 2011¶ ↑

  • MAJOR release. Corrected a double-render situation relating to current_user and login_required.

    • The current_user helper no longer invokes the routine to authenticate a user against CAS and instead now simply loads the user from session.

  • Added testing notes to the README

  • Added comments to the generated files.

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 © 2009 Brian Hogan. See LICENSE for details.