devise_cloudfuji_authenticatable 1.0.4

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 (62) hide show
  1. data/.gitignore +4 -0
  2. data/.project +12 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +10 -0
  6. data/README.md +121 -0
  7. data/Rakefile +1 -0
  8. data/app/controllers/devise/cas_sessions_controller.rb +101 -0
  9. data/app/views/devise/cas_sessions/new.html.erb +1 -0
  10. data/app/views/devise/cas_sessions/unregistered.html.erb +150 -0
  11. data/app/views/devise/cas_sessions/unregistered.html.erb.old +2 -0
  12. data/devise_cloudfuji_authenticatable.gemspec +36 -0
  13. data/lib/devise_cas_authenticatable.rb +135 -0
  14. data/lib/devise_cas_authenticatable/exceptions.rb +10 -0
  15. data/lib/devise_cas_authenticatable/missing_session_helpers.rb +9 -0
  16. data/lib/devise_cas_authenticatable/model.rb +56 -0
  17. data/lib/devise_cas_authenticatable/routes.rb +37 -0
  18. data/lib/devise_cas_authenticatable/schema.rb +13 -0
  19. data/lib/devise_cas_authenticatable/single_sign_out.rb +22 -0
  20. data/lib/devise_cas_authenticatable/single_sign_out/session_store/active_record.rb +12 -0
  21. data/lib/devise_cas_authenticatable/single_sign_out/session_store/redis.rb +27 -0
  22. data/lib/devise_cas_authenticatable/single_sign_out/strategies.rb +58 -0
  23. data/lib/devise_cas_authenticatable/single_sign_out/strategies/base.rb +11 -0
  24. data/lib/devise_cas_authenticatable/single_sign_out/strategies/rails_cache.rb +31 -0
  25. data/lib/devise_cas_authenticatable/strategy.rb +56 -0
  26. data/lib/devise_cloudfuji_authenticatable.rb +8 -0
  27. data/lib/devise_cloudfuji_authenticatable/version.rb +3 -0
  28. data/rails/init.rb +1 -0
  29. data/spec/devise_cas_authenticatable/model_spec.rb +39 -0
  30. data/spec/routes_spec.rb +38 -0
  31. data/spec/scenario/.gitignore +4 -0
  32. data/spec/scenario/app/controllers/application_controller.rb +3 -0
  33. data/spec/scenario/app/controllers/home_controller.rb +7 -0
  34. data/spec/scenario/app/models/user.rb +3 -0
  35. data/spec/scenario/app/views/layouts/application.html.erb +17 -0
  36. data/spec/scenario/config.ru +4 -0
  37. data/spec/scenario/config/application.rb +38 -0
  38. data/spec/scenario/config/boot.rb +13 -0
  39. data/spec/scenario/config/castronaut.yml +32 -0
  40. data/spec/scenario/config/database.yml +22 -0
  41. data/spec/scenario/config/environment.rb +5 -0
  42. data/spec/scenario/config/environments/development.rb +25 -0
  43. data/spec/scenario/config/environments/production.rb +49 -0
  44. data/spec/scenario/config/environments/test.rb +35 -0
  45. data/spec/scenario/config/initializers/backtrace_silencers.rb +7 -0
  46. data/spec/scenario/config/initializers/castronaut.rb +1 -0
  47. data/spec/scenario/config/initializers/devise.rb +3 -0
  48. data/spec/scenario/config/initializers/inflections.rb +10 -0
  49. data/spec/scenario/config/initializers/mime_types.rb +5 -0
  50. data/spec/scenario/config/initializers/secret_token.rb +7 -0
  51. data/spec/scenario/config/initializers/session_store.rb +8 -0
  52. data/spec/scenario/config/locales/en.yml +5 -0
  53. data/spec/scenario/config/routes.rb +8 -0
  54. data/spec/scenario/config/rubycas-server.yml +13 -0
  55. data/spec/scenario/db/migrate/20100401102949_create_tables.rb +15 -0
  56. data/spec/scenario/db/migrate/20111002012903_add_sessions_table.rb +16 -0
  57. data/spec/scenario/db/schema.rb +25 -0
  58. data/spec/scenario/public/.gitkeep +0 -0
  59. data/spec/spec_helper.rb +23 -0
  60. data/spec/strategy_spec.rb +87 -0
  61. data/spec/support/migrations.rb +4 -0
  62. metadata +236 -0
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/devise_cas_authenticatable'
2
+
3
+ module Devise
4
+ def self.on_cloudfuji?
5
+ return false if ENV['CLOUDFUJI_APP_KEY'].nil?
6
+ true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module DeviseCloudfujiAuthenticatable
2
+ VERSION = "1.0.4"
3
+ end
@@ -0,0 +1 @@
1
+ require "devise_cas_authenticatable"
@@ -0,0 +1,39 @@
1
+ require "spec_helper"
2
+
3
+ describe Devise::Models::CloudfujiAuthenticatable do
4
+
5
+ class ExampleAuth
6
+ include Devise::Models::CloudfujiAuthenticatable
7
+ end
8
+
9
+ describe "authenticate_with_cas_ticket" do
10
+
11
+ before :each do
12
+ @ticket = Object.new
13
+ @user = Object.new
14
+
15
+ @ticket.should_receive(:user).and_return(@user)
16
+ @ticket.should_receive(:has_been_validated?).and_return(true)
17
+ @ticket.should_receive(:is_valid?).and_return(true)
18
+ ::Devise.cas_create_user = true
19
+
20
+ ExampleAuth.should_receive(:find_for_authentication).and_return(@user)
21
+ @user.should_receive(:save)
22
+ end
23
+
24
+ it "should call the cloudfuji_extra_attributes method if it's defined on the devise resource" do
25
+ @ticket.should_receive(:extra_attributes)
26
+ @user.should_receive(:cloudfuji_extra_attributes)
27
+ ExampleAuth.authenticate_with_cas_ticket(@ticket)
28
+ end
29
+
30
+ it "should *not* call the cloudfuji_extra_attributes method if it's *not* defined on the devise resource" do
31
+
32
+ @user.should_receive(:respond_to?).and_return(false)
33
+ @user.should_not_receive(:cloudfuji_extra_attributes)
34
+
35
+ ExampleAuth.authenticate_with_cas_ticket(@ticket)
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe "routing" do
4
+ include RSpec::Rails::RoutingExampleGroup
5
+
6
+ it "routes to #service" do
7
+ get("/users/service").should route_to("devise/cas_sessions#service")
8
+ end
9
+
10
+ it "routes to #new" do
11
+ get("/users/sign_in").should route_to("devise/cas_sessions#new")
12
+ end
13
+
14
+ it "routes to #create" do
15
+ post("/users/sign_in").should route_to("devise/cas_sessions#create")
16
+ end
17
+
18
+ it "routes to #destroy" do
19
+ get("/users/sign_out").should route_to("devise/cas_sessions#destroy")
20
+ end
21
+
22
+ it "routes to #unregistered" do
23
+ get("/users/unregistered").should route_to("devise/cas_sessions#unregistered")
24
+ end
25
+ end
26
+
27
+ describe Devise::CasSessionsController do
28
+ include RSpec::Rails::ControllerExampleGroup
29
+
30
+ it "should have the right route names" do
31
+ controller.should respond_to("user_service_path", "new_user_session_path", "user_session_path", "destroy_user_session_path")
32
+ controller.user_service_path.should == "/users/service"
33
+ controller.new_user_session_path.should == "/users/sign_in"
34
+ controller.user_session_path.should == "/users/sign_in"
35
+ controller.destroy_user_session_path.should == "/users/sign_out"
36
+ controller.unregistered_user_session_path.should == "/users/unregistered"
37
+ end
38
+ end
@@ -0,0 +1,4 @@
1
+ .bundle
2
+ db/*.sqlite3
3
+ log/*.log
4
+ tmp/**/*
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,7 @@
1
+ class HomeController < ApplicationController
2
+ before_filter :authenticate_user!
3
+
4
+ def index
5
+ head(:ok)
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ devise :cloudfuji_authenticatable, :rememberable
3
+ end
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Scenario</title>
5
+ <%= stylesheet_link_tag :all %>
6
+ <%= javascript_include_tag :defaults %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+
11
+ <p class="alert"><%= alert %></p>
12
+ <p class="notice"><%= notice %></p>
13
+
14
+ <%= yield %>
15
+
16
+ </body>
17
+ </html>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Scenario::Application
@@ -0,0 +1,38 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require(:default, Rails.env) if defined?(Bundler)
6
+
7
+ require 'castronaut'
8
+ class TestAdapter
9
+ def self.reset_valid_users!
10
+ @@valid_users = {
11
+ "joeuser" => "joepassword"
12
+ }
13
+ end
14
+ reset_valid_users!
15
+
16
+ def self.register_valid_user(username, password)
17
+ @@valid_users[username] = password
18
+ end
19
+
20
+ def self.authenticate(username, password)
21
+ error_message = if @@valid_users[username] == password
22
+ nil
23
+ else
24
+ "Invalid password"
25
+ end
26
+
27
+ Castronaut::AuthenticationResult.new(username, error_message)
28
+ end
29
+ end
30
+
31
+ Castronaut::Adapters.register("test_adapter", TestAdapter)
32
+ Castronaut.config = Castronaut::Configuration.load(File.expand_path(File.join(File.dirname(__FILE__), "castronaut.yml")))
33
+
34
+ module Scenario
35
+ class Application < Rails::Application
36
+ config.active_support.deprecation = :stderr
37
+ end
38
+ end
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ gemfile = File.expand_path('../../Gemfile', __FILE__)
5
+ begin
6
+ ENV['BUNDLE_GEMFILE'] = gemfile
7
+ require 'bundler'
8
+ Bundler.setup
9
+ rescue Bundler::GemNotFound => e
10
+ STDERR.puts e.message
11
+ STDERR.puts "Try running `bundle install`."
12
+ exit!
13
+ end if File.exist?(gemfile)
@@ -0,0 +1,32 @@
1
+ organization_name: Foo Bar Baz Industries, LLC Inc. A division of Holdings Co.
2
+
3
+ environment: development
4
+ # The port the CAS webserver will start on
5
+ server_port: 4567
6
+
7
+ log_directory: log
8
+
9
+ log_level: Logger::DEBUG
10
+
11
+ ssl_enabled: false
12
+
13
+ cas_database:
14
+ adapter: sqlite3
15
+ database: db/cas.sqlite3
16
+ timeout: 5000
17
+
18
+ cas_adapter:
19
+ adapter: test_adapter
20
+
21
+ # Use this example if you are using LDAP as your authentication source
22
+ # cas_adapter:
23
+ # adapter: ldap
24
+ # host: localhost
25
+ # port: 389
26
+ # prefix: cn=
27
+ # base: dc=example, dc=com
28
+
29
+ # Uncomment these to enable authentication callbacks
30
+ # callbacks:
31
+ # on_authentication_success: http://example.com/authentication/success
32
+ # on_authentication_failed: http://example.com/authentication/failed
@@ -0,0 +1,22 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
+ development:
4
+ adapter: sqlite3
5
+ database: db/development.sqlite3
6
+ pool: 5
7
+ timeout: 5000
8
+
9
+ # Warning: The database defined as "test" will be erased and
10
+ # re-generated from your development database when you run "rake".
11
+ # Do not set this db to the same as development or production.
12
+ test:
13
+ adapter: sqlite3
14
+ database: db/test.sqlite3
15
+ pool: 5
16
+ timeout: 5000
17
+
18
+ production:
19
+ adapter: sqlite3
20
+ database: db/production.sqlite3
21
+ pool: 5
22
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Scenario::Application.initialize!
@@ -0,0 +1,25 @@
1
+ Scenario::Application.configure do
2
+ # Settings specified here will take precedence over those in config/environment.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the webserver when you make code changes.
7
+ config.cache_classes = false
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.consider_all_requests_local = 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
18
+
19
+ # Print deprecation notices to the Rails logger
20
+ config.active_support.deprecation = :log
21
+
22
+ # Only use best-standards-support built into browsers
23
+ config.action_dispatch.best_standards_support = :builtin
24
+ end
25
+
@@ -0,0 +1,49 @@
1
+ Scenario::Application.configure do
2
+ # Settings specified here will take precedence over those in config/environment.rb
3
+
4
+ # The production environment is meant for finished, "live" apps.
5
+ # Code is not reloaded between requests
6
+ config.cache_classes = true
7
+
8
+ # Full error reports are disabled and caching is turned on
9
+ config.consider_all_requests_local = false
10
+ config.action_controller.perform_caching = true
11
+
12
+ # Specifies the header that your server uses for sending files
13
+ config.action_dispatch.x_sendfile_header = "X-Sendfile"
14
+
15
+ # For nginx:
16
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
17
+
18
+ # If you have no front-end server that supports something like X-Sendfile,
19
+ # just comment this out and Rails will serve the files
20
+
21
+ # See everything in the log (default is :info)
22
+ # config.log_level = :debug
23
+
24
+ # Use a different logger for distributed setups
25
+ # config.logger = SyslogLogger.new
26
+
27
+ # Use a different cache store in production
28
+ # config.cache_store = :mem_cache_store
29
+
30
+ # Disable Rails's static asset server
31
+ # In production, Apache or nginx will already do this
32
+ config.serve_static_assets = false
33
+
34
+ # Enable serving of images, stylesheets, and javascripts from an asset server
35
+ # config.action_controller.asset_host = "http://assets.example.com"
36
+
37
+ # Disable delivery errors, bad email addresses will be ignored
38
+ # config.action_mailer.raise_delivery_errors = false
39
+
40
+ # Enable threaded mode
41
+ # config.threadsafe!
42
+
43
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
44
+ # the I18n.default_locale when a translation can not be found)
45
+ config.i18n.fallbacks = true
46
+
47
+ # Send deprecation notices to registered listeners
48
+ config.active_support.deprecation = :notify
49
+ end
@@ -0,0 +1,35 @@
1
+ Scenario::Application.configure do
2
+ # Settings specified here will take precedence over those in config/environment.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Log error messages when you accidentally call methods on nil.
11
+ config.whiny_nils = true
12
+
13
+ # Show full error reports and disable caching
14
+ config.consider_all_requests_local = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Raise exceptions instead of rendering exception templates
18
+ config.action_dispatch.show_exceptions = false
19
+
20
+ # Disable request forgery protection in test environment
21
+ config.action_controller.allow_forgery_protection = false
22
+
23
+ # Tell Action Mailer not to deliver emails to the real world.
24
+ # The :test delivery method accumulates sent emails in the
25
+ # ActionMailer::Base.deliveries array.
26
+ config.action_mailer.delivery_method = :test
27
+
28
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
29
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
30
+ # like if you have constraints or database-specific column types
31
+ # config.active_record.schema_format = :sql
32
+
33
+ # Print deprecation notices to the stderr
34
+ config.active_support.deprecation = :stderr
35
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1 @@
1
+ Castronaut.config.connect_activerecord
@@ -0,0 +1,3 @@
1
+ Devise.setup do |config|
2
+ require "devise/orm/active_record"
3
+ end
@@ -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,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Scenario::Application.config.secret_token = '70d2ec936ec5a91e883a9dc74bfeadd5a96cc242d3fd0857aa0151112ac71721475e01ae788e5c976a09ab62dd20240678cdc393c37cb777e872e59ea74adaad'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Scenario::Application.config.session_store :cookie_store, :key => '_scenario_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rake db:sessions:create")
8
+ Scenario::Application.config.session_store :active_record_store
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,8 @@
1
+ require 'castronaut/application'
2
+ Castronaut::Application.set(:path, "/cas_server")
3
+
4
+ Scenario::Application.routes.draw do
5
+ devise_for :users
6
+ mount Castronaut::Application, :at => "/cas_server"
7
+ root :to => "home#index"
8
+ end