Cassette::Client
Library to generate and validate STs and TGTs
Installation
Add this line to your application's Gemfile:
gem 'cassette'
And then execute:
$ bundle
Usage
Require this library and create an intializer to set its configuration:
Cassette.config = config
where config is an object that responds to the methods #base for the base CAS uri, #username and #password if you are authenticating on other systems and #service and #base_authority if you are using the authentication filter to authenticate your app
You may also set the caching backend using the .backend= module method:
Cassette::Cache.backend = ActiveSupport::Cache::MemcacheStorage.new
By default, Cassette::Cache will check if you have Rails.cache defined or instantiate a new ActiveSupport::Cache::MemoryStore
To authenticate your Rails app, add to your ApplicationController (or any authenticated controller):
class ApplicationController < ActionController::Base
include Cassette::Authentication::Filter
# ...
end
You should also rescue from Cassette::Errors::Forbidden with more friendly errors
If you wish to have actions that skip the authentication filter, add to your controller:
class SomeController < ApplicationController
skip_authentication # [*options]
# skip_authentication only: "index"
end
Where options are the same options you can pass to Rails' skip_before_filter method
RubyCAS client helpers
If you are authenticating users with RubyCAS and want role checking, in your rubycas initializer:
require "cas/rubycas"
And in your ApplicationController (or any authenticated controller):
class SomeController < ApplicationController
include Cassette::Rubycas::Helper
# - Allow only employees:
#
# before_filter :employee_only_filter
#
# rescue_from Cassette::Errors::NotAnEmployee do
# redirect_to '/403.html'
# end
# - Allow only customers:
#
# before_filter :customer_only_filter
#
# rescue_from Cassette::Errors::NotACustomer do
# redirect_to '/403.html'
# end
end
Instantiating Cassette::Client and Cassette::Authentication
You can create your own instances of Cassette::Client (st/tgt generator) and Cassette::Authentication (st validator).
The constructor accepts a hash with keys (as symbols) for the values of cache, logger, http_client and configuration.
All values default to the same values used when accessing the class methods directly.
Please check the constructors or integration specs for details.
About caching and tests
It is a good idea to always clear the cache between tests, specially if you're
using VCR. You can do it by using the invoking the #clear method of the cache
backend in use. The following excerpt will clear the cache of the default client
Cassette::Client instance:
Cassette::Client.cache.backend.clear
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Added some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request