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.
- data/.rvmrc +1 -0
- data/.source_index +0 -0
- data/CHANGELOG.txt +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +22 -0
- data/History.txt +192 -0
- data/LICENSE.txt +26 -0
- data/README.rdoc +321 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/examples/merb/.gitignore +18 -0
- data/examples/merb/README.textile +12 -0
- data/examples/merb/Rakefile +35 -0
- data/examples/merb/merb.thor +2020 -0
- data/examples/merb/merb_auth_cas.rb +67 -0
- data/examples/merb/spec/spec_helper.rb +24 -0
- data/examples/rails/README +16 -0
- data/examples/rails/app/controllers/advanced_example_controller.rb +31 -0
- data/examples/rails/app/controllers/application.rb +2 -0
- data/examples/rails/app/controllers/simple_example_controller.rb +16 -0
- data/examples/rails/app/views/advanced_example/index.html.erb +13 -0
- data/examples/rails/app/views/advanced_example/my_account.html.erb +11 -0
- data/examples/rails/app/views/simple_example/index.html.erb +6 -0
- data/examples/rails/config/boot.rb +109 -0
- data/examples/rails/config/environment.rb +39 -0
- data/examples/rails/config/environments/development.rb +17 -0
- data/examples/rails/config/environments/production.rb +22 -0
- data/examples/rails/config/environments/test.rb +22 -0
- data/examples/rails/config/initializers/inflections.rb +10 -0
- data/examples/rails/config/initializers/mime_types.rb +5 -0
- data/examples/rails/config/initializers/new_rails_defaults.rb +17 -0
- data/examples/rails/config/routes.rb +4 -0
- data/examples/rails/log/development.log +946 -0
- data/examples/rails/log/production.log +0 -0
- data/examples/rails/log/server.log +0 -0
- data/examples/rails/log/test.log +0 -0
- data/examples/rails/script/about +4 -0
- data/examples/rails/script/console +3 -0
- data/examples/rails/script/server +3 -0
- data/lib/casclient.rb +89 -0
- data/lib/casclient/client.rb +271 -0
- data/lib/casclient/frameworks/merb/filter.rb +105 -0
- data/lib/casclient/frameworks/merb/strategy.rb +110 -0
- data/lib/casclient/frameworks/rails/cas_proxy_callback_controller.rb +76 -0
- data/lib/casclient/frameworks/rails/filter.rb +415 -0
- data/lib/casclient/responses.rb +197 -0
- data/lib/casclient/tickets.rb +38 -0
- data/lib/vibes-rubycas-client.rb +1 -0
- data/vibes-rubycas-client.gemspec +100 -0
- metadata +198 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
# run very flat apps with merb -I <app file>.
|
2
|
+
|
3
|
+
# Uncomment for DataMapper ORM
|
4
|
+
# use_orm :datamapper
|
5
|
+
|
6
|
+
# Uncomment for ActiveRecord ORM
|
7
|
+
# use_orm :activerecord
|
8
|
+
|
9
|
+
# Uncomment for Sequel ORM
|
10
|
+
# use_orm :sequel
|
11
|
+
|
12
|
+
$:.unshift(File.dirname(__FILE__) / ".." / ".." / "lib")
|
13
|
+
require "casclient"
|
14
|
+
require 'casclient/frameworks/merb/filter'
|
15
|
+
#
|
16
|
+
# ==== Pick what you test with
|
17
|
+
#
|
18
|
+
|
19
|
+
# This defines which test framework the generators will use.
|
20
|
+
# RSpec is turned on by default.
|
21
|
+
#
|
22
|
+
# To use Test::Unit, you need to install the merb_test_unit gem.
|
23
|
+
# To use RSpec, you don't have to install any additional gems, since
|
24
|
+
# merb-core provides support for RSpec.
|
25
|
+
#
|
26
|
+
# use_test :test_unit
|
27
|
+
use_test :rspec
|
28
|
+
|
29
|
+
#
|
30
|
+
# ==== Choose which template engine to use by default
|
31
|
+
#
|
32
|
+
|
33
|
+
# Merb can generate views for different template engines, choose your favourite as the default.
|
34
|
+
|
35
|
+
use_template_engine :erb
|
36
|
+
# use_template_engine :haml
|
37
|
+
|
38
|
+
Merb::Config.use { |c|
|
39
|
+
c[:framework] = { :public => [Merb.root / "public", nil] }
|
40
|
+
c[:session_store] = 'cookie'
|
41
|
+
c[:exception_details] = true
|
42
|
+
c[:log_level] = :debug # or error, warn, info or fatal
|
43
|
+
c[:log_stream] = STDOUT
|
44
|
+
c[:session_secret_key] = '9f30c015f2132d217bfb81e31668a74fadbdf672'
|
45
|
+
c[:log_file] = Merb.root / "log" / "merb.log"
|
46
|
+
|
47
|
+
c[:reload_classes] = true
|
48
|
+
c[:reload_templates] = true
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
Merb::Plugins.config[:"rubycas-client"] = {
|
53
|
+
:cas_base_url => "http://localhost:7777"
|
54
|
+
}
|
55
|
+
|
56
|
+
Merb::Router.prepare do
|
57
|
+
match('/').to(:controller => 'merb_auth_cas', :action =>'index').name(:default)
|
58
|
+
end
|
59
|
+
|
60
|
+
class MerbAuthCas < Merb::Controller
|
61
|
+
include CASClient::Frameworks::Merb::Filter
|
62
|
+
before :cas_filter
|
63
|
+
|
64
|
+
def index
|
65
|
+
"Hi, #{session[:cas_user]}"
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
|
3
|
+
# Add the local gems dir if found within the app root; any dependencies loaded
|
4
|
+
# hereafter will try to load from the local gems before loading system gems.
|
5
|
+
if (local_gem_dir = File.join(File.dirname(__FILE__), '..', 'gems')) && $BUNDLE.nil?
|
6
|
+
$BUNDLE = true; Gem.clear_paths; Gem.path.unshift(local_gem_dir)
|
7
|
+
end
|
8
|
+
|
9
|
+
require "spec"
|
10
|
+
require "merb-core"
|
11
|
+
|
12
|
+
Merb::Config.use do |c|
|
13
|
+
c[:session_store] = "memory"
|
14
|
+
end
|
15
|
+
|
16
|
+
Merb.start_environment(:testing => true,
|
17
|
+
:adapter => 'runner',
|
18
|
+
:environment => ENV['MERB_ENV'] || 'test')
|
19
|
+
|
20
|
+
Spec::Runner.configure do |config|
|
21
|
+
config.include(Merb::Test::ViewHelper)
|
22
|
+
config.include(Merb::Test::RouteHelper)
|
23
|
+
config.include(Merb::Test::ControllerHelper)
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
This is a skeleton Rails application hooked up for CAS authentication.
|
2
|
+
|
3
|
+
To try this out:
|
4
|
+
|
5
|
+
1. If you have an existing CAS server, modify the CAS client settings in
|
6
|
+
config/environment.rb to point to your server. If you do not yet
|
7
|
+
have a CAS server, install rubycas-server, and configure it to run on
|
8
|
+
http://localhost:7777 (or modify environment.rb to your likings).
|
9
|
+
|
10
|
+
2. Run `ruby script/server`
|
11
|
+
|
12
|
+
3. Point your web browser to http://localhost:3000
|
13
|
+
|
14
|
+
4. Have a look at the source code in app/controllers/simple_example_controller.rb
|
15
|
+
and app/controllers/advanced_example_controller.rb. The
|
16
|
+
corresponding views under app/views might also be worth looking at.
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# A more advanced example.
|
2
|
+
# For basic usage see the SimpleExampleController.
|
3
|
+
class AdvancedExampleController < ApplicationController
|
4
|
+
# This will allow the user to view the index page without authentication
|
5
|
+
# but will process CAS authentication data if the user already
|
6
|
+
# has an SSO session open.
|
7
|
+
before_filter CASClient::Frameworks::Rails::GatewayFilter, :only => :index
|
8
|
+
|
9
|
+
# This requires the user to be authenticated for viewing allother pages.
|
10
|
+
before_filter CASClient::Frameworks::Rails::Filter, :except => :index
|
11
|
+
|
12
|
+
def index
|
13
|
+
@username = session[:cas_user]
|
14
|
+
|
15
|
+
@login_url = CASClient::Frameworks::Rails::Filter.login_url(self)
|
16
|
+
end
|
17
|
+
|
18
|
+
def my_account
|
19
|
+
@username = session[:cas_user]
|
20
|
+
|
21
|
+
# Additional user attributes are available if your
|
22
|
+
# CAS server is configured to provide them.
|
23
|
+
# See http://code.google.com/p/rubycas-server/wiki/HowToSendExtraUserAttributes
|
24
|
+
@extra_attributes = session[:cas_extra_attributes]
|
25
|
+
end
|
26
|
+
|
27
|
+
def logout
|
28
|
+
CASClient::Frameworks::Rails::Filter.logout(self)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This is the most basic, bare-bones example.
|
2
|
+
# For advanced usage see the AdvancedExampleController.
|
3
|
+
class SimpleExampleController < ApplicationController
|
4
|
+
# This will force CAS authentication before the user
|
5
|
+
# is allowed to access any action in this controller.
|
6
|
+
before_filter CASClient::Frameworks::Rails::Filter
|
7
|
+
|
8
|
+
def index
|
9
|
+
@username = session[:cas_user]
|
10
|
+
end
|
11
|
+
|
12
|
+
def logout
|
13
|
+
CASClient::Frameworks::Rails::Filter.logout(self)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<h1>AdvancedExample#index</h1>
|
2
|
+
|
3
|
+
<% if @username %>
|
4
|
+
<p>Hello, <%= @username %>! You are authenticated.</p>
|
5
|
+
<% else %>
|
6
|
+
<p>You are not yet authenticated. <%= link_to("Login", @login_url) %>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
<p>» <%= link_to("Go To My Account", :action => 'my_account') %></p>
|
10
|
+
|
11
|
+
<% if @username %>
|
12
|
+
<p>[ <%= link_to("Logout", :action => 'logout') %> ]</p>
|
13
|
+
<% end %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<h1>AdvancedExample#my_account</h1>
|
2
|
+
<p><%= @username %>'s Account page</p>
|
3
|
+
|
4
|
+
<p>
|
5
|
+
<strong>Extra Attributes</strong>:<br />
|
6
|
+
<% unless @extra_attributes.blank? %>
|
7
|
+
<%= debug(@extra_attributes) %>
|
8
|
+
<% end %>
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<p>[ <%= link_to("Logout", :action => 'logout') %> ]</p>
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# Don't change this file!
|
2
|
+
# Configure your app in config/environment.rb and config/environments/*.rb
|
3
|
+
|
4
|
+
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
class << self
|
8
|
+
def boot!
|
9
|
+
unless booted?
|
10
|
+
preinitialize
|
11
|
+
pick_boot.run
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def booted?
|
16
|
+
defined? Rails::Initializer
|
17
|
+
end
|
18
|
+
|
19
|
+
def pick_boot
|
20
|
+
(vendor_rails? ? VendorBoot : GemBoot).new
|
21
|
+
end
|
22
|
+
|
23
|
+
def vendor_rails?
|
24
|
+
File.exist?("#{RAILS_ROOT}/vendor/rails")
|
25
|
+
end
|
26
|
+
|
27
|
+
def preinitialize
|
28
|
+
load(preinitializer_path) if File.exist?(preinitializer_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def preinitializer_path
|
32
|
+
"#{RAILS_ROOT}/config/preinitializer.rb"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Boot
|
37
|
+
def run
|
38
|
+
load_initializer
|
39
|
+
Rails::Initializer.run(:set_load_path)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class VendorBoot < Boot
|
44
|
+
def load_initializer
|
45
|
+
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
|
46
|
+
Rails::Initializer.run(:install_gem_spec_stubs)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class GemBoot < Boot
|
51
|
+
def load_initializer
|
52
|
+
self.class.load_rubygems
|
53
|
+
load_rails_gem
|
54
|
+
require 'initializer'
|
55
|
+
end
|
56
|
+
|
57
|
+
def load_rails_gem
|
58
|
+
if version = self.class.gem_version
|
59
|
+
gem 'rails', version
|
60
|
+
else
|
61
|
+
gem 'rails'
|
62
|
+
end
|
63
|
+
rescue Gem::LoadError => load_error
|
64
|
+
$stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
|
65
|
+
exit 1
|
66
|
+
end
|
67
|
+
|
68
|
+
class << self
|
69
|
+
def rubygems_version
|
70
|
+
Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
|
71
|
+
end
|
72
|
+
|
73
|
+
def gem_version
|
74
|
+
if defined? RAILS_GEM_VERSION
|
75
|
+
RAILS_GEM_VERSION
|
76
|
+
elsif ENV.include?('RAILS_GEM_VERSION')
|
77
|
+
ENV['RAILS_GEM_VERSION']
|
78
|
+
else
|
79
|
+
parse_gem_version(read_environment_rb)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def load_rubygems
|
84
|
+
require 'rubygems'
|
85
|
+
min_version = '1.1.1'
|
86
|
+
unless rubygems_version >= min_version
|
87
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
|
88
|
+
exit 1
|
89
|
+
end
|
90
|
+
|
91
|
+
rescue LoadError
|
92
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
|
93
|
+
exit 1
|
94
|
+
end
|
95
|
+
|
96
|
+
def parse_gem_version(text)
|
97
|
+
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
def read_environment_rb
|
102
|
+
File.read("#{RAILS_ROOT}/config/environment.rb")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# All that for this:
|
109
|
+
Rails.boot!
|
@@ -0,0 +1,39 @@
|
|
1
|
+
RAILS_GEM_VERSION = '2.1.2' unless defined? RAILS_GEM_VERSION
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), 'boot')
|
4
|
+
|
5
|
+
Rails::Initializer.run do |config|
|
6
|
+
config.time_zone = 'UTC'
|
7
|
+
config.action_controller.session = {
|
8
|
+
:session_key => '_rails_session',
|
9
|
+
:secret => 'e2f5641ab4a3627096a2b6ca8c62cefe53f572906ad6a5fb1c949d183a0'
|
10
|
+
}
|
11
|
+
config.frameworks -= [:active_record]
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
# Basic CAS client configuration
|
16
|
+
|
17
|
+
require 'casclient'
|
18
|
+
require 'casclient/frameworks/rails/filter'
|
19
|
+
|
20
|
+
CASClient::Frameworks::Rails::Filter.configure(
|
21
|
+
:cas_base_url => "https://mzukowski.urbacon.net:6543/cas"
|
22
|
+
)
|
23
|
+
|
24
|
+
|
25
|
+
# More complicated configuration
|
26
|
+
|
27
|
+
#cas_logger = CASClient::Logger.new(RAILS_ROOT+'/log/cas.log')
|
28
|
+
#cas_logger.level = Logger::DEBUG
|
29
|
+
#
|
30
|
+
#CASClient::Frameworks::Rails::Filter.configure(
|
31
|
+
# :cas_base_url => "https://localhost:7778/",
|
32
|
+
# :login_url => "https://localhost:7778/login",
|
33
|
+
# :logout_url => "https://localhost:7778/logout",
|
34
|
+
# :validate_url => "https://localhost:7778/proxyValidate",
|
35
|
+
# :session_username_key => :cas_user,
|
36
|
+
# :session_extra_attributes_key => :cas_extra_attributes
|
37
|
+
# :logger => cas_logger,
|
38
|
+
# :authenticate_on_every_request => true
|
39
|
+
#)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
2
|
+
|
3
|
+
# In the development environment your application's code is reloaded on
|
4
|
+
# every request. This slows down response time but is perfect for development
|
5
|
+
# since you don't have to restart the webserver when you make code changes.
|
6
|
+
config.cache_classes = false
|
7
|
+
|
8
|
+
# Log error messages when you accidentally call methods on nil.
|
9
|
+
config.whiny_nils = true
|
10
|
+
|
11
|
+
# Show full error reports and disable caching
|
12
|
+
config.action_controller.consider_all_requests_local = true
|
13
|
+
config.action_view.debug_rjs = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
2
|
+
|
3
|
+
# The production environment is meant for finished, "live" apps.
|
4
|
+
# Code is not reloaded between requests
|
5
|
+
config.cache_classes = true
|
6
|
+
|
7
|
+
# Use a different logger for distributed setups
|
8
|
+
# config.logger = SyslogLogger.new
|
9
|
+
|
10
|
+
# Full error reports are disabled and caching is turned on
|
11
|
+
config.action_controller.consider_all_requests_local = false
|
12
|
+
config.action_controller.perform_caching = true
|
13
|
+
config.action_view.cache_template_loading = true
|
14
|
+
|
15
|
+
# Use a different cache store in production
|
16
|
+
# config.cache_store = :mem_cache_store
|
17
|
+
|
18
|
+
# Enable serving of images, stylesheets, and javascripts from an asset server
|
19
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
20
|
+
|
21
|
+
# Disable delivery errors, bad email addresses will be ignored
|
22
|
+
# config.action_mailer.raise_delivery_errors = false
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
2
|
+
|
3
|
+
# The test environment is used exclusively to run your application's
|
4
|
+
# test suite. You never need to work with it otherwise. Remember that
|
5
|
+
# your test database is "scratch space" for the test suite and is wiped
|
6
|
+
# and recreated between test runs. Don't rely on the data there!
|
7
|
+
config.cache_classes = true
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.action_controller.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Disable request forgery protection in test environment
|
17
|
+
config.action_controller.allow_forgery_protection = false
|
18
|
+
|
19
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
20
|
+
# The :test delivery method accumulates sent emails in the
|
21
|
+
# ActionMailer::Base.deliveries array.
|
22
|
+
config.action_mailer.delivery_method = :test
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format
|
4
|
+
# (all these examples are active by default):
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
8
|
+
# inflect.irregular 'person', 'people'
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
10
|
+
# end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# These settings change the behavior of Rails 2 apps and will be defaults
|
2
|
+
# for Rails 3. You can remove this initializer when Rails 3 is released.
|
3
|
+
|
4
|
+
if defined?(ActiveRecord)
|
5
|
+
# Include Active Record class name as root for JSON serialized output.
|
6
|
+
ActiveRecord::Base.include_root_in_json = true
|
7
|
+
|
8
|
+
# Store the full class name (including module namespace) in STI type column.
|
9
|
+
ActiveRecord::Base.store_full_sti_class = true
|
10
|
+
end
|
11
|
+
|
12
|
+
# Use ISO 8601 format for JSON serialized times and dates.
|
13
|
+
ActiveSupport.use_standard_json_time_format = true
|
14
|
+
|
15
|
+
# Don't escape HTML entities in JSON, leave that for the #json_escape helper.
|
16
|
+
# if you're including raw json in an HTML page.
|
17
|
+
ActiveSupport.escape_html_entities_in_json = false
|