authlogic_cloudfuji 0.9.3

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 (80) hide show
  1. data/.gitignore +17 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +4 -0
  4. data/Rakefile +2 -0
  5. data/app/controllers/authlogic/cas/cas_authentication_controller.rb +7 -0
  6. data/app/controllers/authlogic/cas/cas_client_controller.rb +7 -0
  7. data/authlogic_bushido.gemspec +22 -0
  8. data/config/routes.rb +3 -0
  9. data/lib/authlogic_bushido.rb +1 -0
  10. data/lib/authlogic_cas.rb +104 -0
  11. data/lib/authlogic_cas/controller_actions/service.rb +72 -0
  12. data/lib/authlogic_cas/controller_actions/session.rb +32 -0
  13. data/lib/authlogic_cas/engine.rb +6 -0
  14. data/lib/authlogic_cas/rails_routes.rb +16 -0
  15. data/lib/authlogic_cas/single_sign_out/cache.rb +38 -0
  16. data/spec/authlogic_cas_spec.rb +150 -0
  17. data/spec/controllers/service_controller_spec.rb +51 -0
  18. data/spec/controllers/session_controller_spec.rb +31 -0
  19. data/spec/scenario/.gitignore +15 -0
  20. data/spec/scenario/Gemfile +5 -0
  21. data/spec/scenario/Rakefile +7 -0
  22. data/spec/scenario/app/assets/images/rails.png +0 -0
  23. data/spec/scenario/app/assets/javascripts/application.js +9 -0
  24. data/spec/scenario/app/assets/javascripts/main_controller.js.coffee +3 -0
  25. data/spec/scenario/app/assets/javascripts/user_sessions.js.coffee +3 -0
  26. data/spec/scenario/app/assets/javascripts/users.js.coffee +3 -0
  27. data/spec/scenario/app/assets/stylesheets/application.css +7 -0
  28. data/spec/scenario/app/assets/stylesheets/main_controller.css.scss +3 -0
  29. data/spec/scenario/app/assets/stylesheets/scaffolds.css.scss +56 -0
  30. data/spec/scenario/app/assets/stylesheets/user_sessions.css.scss +3 -0
  31. data/spec/scenario/app/assets/stylesheets/users.css.scss +3 -0
  32. data/spec/scenario/app/controllers/application_controller.rb +17 -0
  33. data/spec/scenario/app/controllers/main_controller.rb +8 -0
  34. data/spec/scenario/app/controllers/user_sessions_controller.rb +50 -0
  35. data/spec/scenario/app/controllers/users_controller.rb +86 -0
  36. data/spec/scenario/app/helpers/application_helper.rb +2 -0
  37. data/spec/scenario/app/helpers/main_controller_helper.rb +2 -0
  38. data/spec/scenario/app/helpers/user_sessions_helper.rb +2 -0
  39. data/spec/scenario/app/helpers/users_helper.rb +2 -0
  40. data/spec/scenario/app/mailers/.gitkeep +0 -0
  41. data/spec/scenario/app/models/.gitkeep +0 -0
  42. data/spec/scenario/app/models/user.rb +3 -0
  43. data/spec/scenario/app/models/user_session.rb +2 -0
  44. data/spec/scenario/app/views/layouts/application.html.erb +25 -0
  45. data/spec/scenario/app/views/main/another_cool_page.html.erb +3 -0
  46. data/spec/scenario/app/views/main/index.html.erb +2 -0
  47. data/spec/scenario/app/views/user_sessions/_form.html.erb +25 -0
  48. data/spec/scenario/app/views/user_sessions/edit.html.erb +3 -0
  49. data/spec/scenario/app/views/user_sessions/index.html.erb +25 -0
  50. data/spec/scenario/app/views/user_sessions/new.html.erb +5 -0
  51. data/spec/scenario/app/views/user_sessions/show.html.erb +15 -0
  52. data/spec/scenario/app/views/users/_form.html.erb +34 -0
  53. data/spec/scenario/app/views/users/edit.html.erb +6 -0
  54. data/spec/scenario/app/views/users/index.html.erb +27 -0
  55. data/spec/scenario/app/views/users/new.html.erb +5 -0
  56. data/spec/scenario/app/views/users/show.html.erb +20 -0
  57. data/spec/scenario/config.ru +4 -0
  58. data/spec/scenario/config/application.rb +54 -0
  59. data/spec/scenario/config/boot.rb +6 -0
  60. data/spec/scenario/config/environment.rb +17 -0
  61. data/spec/scenario/config/environments/development.rb +30 -0
  62. data/spec/scenario/config/environments/production.rb +60 -0
  63. data/spec/scenario/config/environments/test.rb +39 -0
  64. data/spec/scenario/config/initializers/authlogic_cas.rb +5 -0
  65. data/spec/scenario/config/initializers/backtrace_silencers.rb +7 -0
  66. data/spec/scenario/config/initializers/inflections.rb +10 -0
  67. data/spec/scenario/config/initializers/mime_types.rb +5 -0
  68. data/spec/scenario/config/initializers/secret_token.rb +7 -0
  69. data/spec/scenario/config/initializers/session_store.rb +8 -0
  70. data/spec/scenario/config/initializers/wrap_parameters.rb +14 -0
  71. data/spec/scenario/config/locales/en.yml +5 -0
  72. data/spec/scenario/config/routes.rb +16 -0
  73. data/spec/scenario/db/migrate/20120223141435_create_users.rb +17 -0
  74. data/spec/scenario/db/migrate/20120226154646_add_sessions_table.rb +16 -0
  75. data/spec/scenario/db/schema.rb +40 -0
  76. data/spec/scenario/db/seeds.rb +7 -0
  77. data/spec/scenario/script/rails +6 -0
  78. data/spec/single_sign_out/cache_spec.rb +47 -0
  79. data/spec/spec_helper.rb +22 -0
  80. metadata +256 -0
@@ -0,0 +1,51 @@
1
+ require "spec_helper"
2
+
3
+ describe Authlogic::Cas::CasClientController do
4
+
5
+ before :all do
6
+ @ticket_name = "abc123"
7
+ @user = Authlogic::Cas.actor_model.new
8
+ @unique_cas_id = "xyz123"
9
+ end
10
+
11
+ describe "GET service" do
12
+ it "should authenticate the user" do
13
+ Authlogic::Cas.actor_model.should_receive(:authenticate_with_cas_ticket).with(instance_of(::CASClient::ServiceTicket))
14
+ get 'service', {:ticket => @ticket_name}
15
+ end
16
+
17
+ it "should create a session for the user if on successful authentication" do
18
+
19
+ AuthTestModel = Class.new
20
+ AuthTestModel.stub!(:create)
21
+ Authlogic::Cas.authentication_model = AuthTestModel
22
+
23
+ ticket = double ::CASClient::ServiceTicket
24
+ ticket.stub!(:user).and_return(@unique_cas_id)
25
+ ticket.stub!(:ticket).and_return(@ticket_name)
26
+ controller.stub!(:ticket_from).and_return(ticket)
27
+
28
+ Authlogic::Cas.actor_model.should_receive(:authenticate_with_cas_ticket).with(ticket).and_return(@user)
29
+
30
+ Authlogic::Cas.
31
+ authentication_model.
32
+ should_receive(:create).
33
+ with(@user)
34
+
35
+ get 'service', {:ticket => @ticket_name}
36
+ end
37
+ end
38
+
39
+ describe "POST service" do
40
+ it "should signout the user if a valid service ticket was passed" do
41
+ ::Authlogic::Cas::SingleSignOut::Cache.
42
+ should_receive(:find_unique_cas_id_by_service_ticket).
43
+ and_return(@unique_cas_id)
44
+
45
+ controller.should_receive(:update_persistence_token_for).with(@unique_cas_id)
46
+ post 'single_signout', {
47
+ 'logoutRequest' => "<samlp:LogoutRequest><samlp:SessionIndex>#{@ticket_name}</samlp:SessionIndex></samlp:LogoutRequest>"
48
+ }
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+
3
+ describe Authlogic::Cas::CasAuthenticationController do
4
+
5
+ describe "GET new_cas_session" do
6
+ it "should redirect to the cas_login_url if the user is not returning after CAS login" do
7
+ cas_login_url = controller.send(:cas_login_url)
8
+
9
+ get 'new_cas_session'
10
+ response.should redirect_to(cas_login_url)
11
+ end
12
+ end
13
+
14
+ describe "destroy_cas_session" do
15
+ it "should destroy the user session and redirect to the logout page on the CAS server" do
16
+ AuthSession = Class.new
17
+
18
+ Authlogic::Cas.authentication_model = AuthSession
19
+ session = Object.new
20
+ AuthSession.should_receive(:find).and_return(session)
21
+ session.should_receive(:destroy)
22
+
23
+ get 'destroy_cas_session'
24
+ end
25
+ end
26
+
27
+ it "should redirect to te CAS logout url once logged out" do
28
+
29
+ end
30
+ end
31
+
@@ -0,0 +1,15 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+
13
+ # Ignore all logfiles and tempfiles.
14
+ /log/*.log
15
+ /tmp
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rails', '3.2.1'
4
+ gem 'authlogic'
5
+ gem 'authlogic_cloudfuji', :path => "../../"
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Altry::Application.load_tasks
@@ -0,0 +1,9 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require jquery
8
+ //= require jquery_ujs
9
+ //= require_tree .
@@ -0,0 +1,3 @@
1
+ # Place all the behaviors and hooks related to the matching controller here.
2
+ # All this logic will automatically be available in application.js.
3
+ # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3 @@
1
+ # Place all the behaviors and hooks related to the matching controller here.
2
+ # All this logic will automatically be available in application.js.
3
+ # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3 @@
1
+ # Place all the behaviors and hooks related to the matching controller here.
2
+ # All this logic will automatically be available in application.js.
3
+ # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,7 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require_tree .
7
+ */
@@ -0,0 +1,3 @@
1
+ // Place all the styles related to the MainController controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,56 @@
1
+ body {
2
+ background-color: #fff;
3
+ color: #333;
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px; }
7
+
8
+ p, ol, ul, td {
9
+ font-family: verdana, arial, helvetica, sans-serif;
10
+ font-size: 13px;
11
+ line-height: 18px; }
12
+
13
+ pre {
14
+ background-color: #eee;
15
+ padding: 10px;
16
+ font-size: 11px; }
17
+
18
+ a {
19
+ color: #000;
20
+ &:visited {
21
+ color: #666; }
22
+ &:hover {
23
+ color: #fff;
24
+ background-color: #000; } }
25
+
26
+ div {
27
+ &.field, &.actions {
28
+ margin-bottom: 10px; } }
29
+
30
+ #notice {
31
+ color: green; }
32
+
33
+ .field_with_errors {
34
+ padding: 2px;
35
+ background-color: red;
36
+ display: table; }
37
+
38
+ #error_explanation {
39
+ width: 450px;
40
+ border: 2px solid red;
41
+ padding: 7px;
42
+ padding-bottom: 0;
43
+ margin-bottom: 20px;
44
+ background-color: #f0f0f0;
45
+ h2 {
46
+ text-align: left;
47
+ font-weight: bold;
48
+ padding: 5px 5px 5px 15px;
49
+ font-size: 12px;
50
+ margin: -7px;
51
+ margin-bottom: 0px;
52
+ background-color: #c00;
53
+ color: #fff; }
54
+ ul li {
55
+ font-size: 12px;
56
+ list-style: square; } }
@@ -0,0 +1,3 @@
1
+ // Place all the styles related to the user_sessions controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,3 @@
1
+ // Place all the styles related to the Users controller here.
2
+ // They will automatically be included in application.css.
3
+ // You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,17 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+
4
+ helper_method :current_user
5
+
6
+ private
7
+
8
+ def current_user_session
9
+ return @current_user_session if defined?(@current_user_session)
10
+ @current_user_session = UserSession.find
11
+ end
12
+
13
+ def current_user
14
+ return @current_user if defined?(@current_user)
15
+ @current_user = current_user_session && current_user_session.record
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ class MainController < ApplicationController
2
+ def index
3
+ puts "CURRENT USER #{current_user.inspect}"
4
+ end
5
+
6
+ def another_cool_page
7
+ end
8
+ end
@@ -0,0 +1,50 @@
1
+ class UserSessionsController < ApplicationController
2
+
3
+ def new
4
+ puts "Trying new user session"
5
+ redirect_to(cas_login_url) unless returning_from_cas?
6
+ end
7
+
8
+
9
+ # POST /user_sessions
10
+ # POST /user_sessions.json
11
+ def create
12
+ @user_session = UserSession.new(params[:user_session])
13
+
14
+ respond_to do |format|
15
+ if @user_session.save
16
+ format.html { redirect_to root_path, notice: 'User session was successfully created.' }
17
+ format.json { render json: @user_session, status: :created, location: @user_session }
18
+ else
19
+ format.html { render action: "new" }
20
+ format.json { render json: @user_session.errors, status: :unprocessable_entity }
21
+ end
22
+ end
23
+ end
24
+
25
+
26
+ def destroy
27
+ @user_session = UserSession.find
28
+ @user_session.destroy
29
+
30
+ respond_to do |format|
31
+ format.html { redirect_to root_url }
32
+ format.json { head :ok }
33
+ end
34
+ end
35
+
36
+
37
+ protected
38
+ def returning_from_cas?
39
+ params[:ticket] || request.referer =~ /^#{::Authlogic::Cas.cas_client.cas_base_url}/
40
+ end
41
+
42
+
43
+ def cas_login_url
44
+ login_url = ::Authlogic::Cas.cas_client.add_service_to_login_url(users_service_url)
45
+ redirect_url = ""# "&redirect=#{cas_return_to_url}"
46
+ return "#{login_url}#{redirect_url}"
47
+ end
48
+ helper_method :cas_login_url
49
+
50
+ end
@@ -0,0 +1,86 @@
1
+ class UsersController < ApplicationController
2
+
3
+ ##########################################
4
+
5
+ # GET /users
6
+ # GET /users.json
7
+ def index
8
+ @users = User.all
9
+
10
+ respond_to do |format|
11
+ format.html # index.html.erb
12
+ format.json { render json: @users }
13
+ end
14
+ end
15
+
16
+ # GET /users/1
17
+ # GET /users/1.json
18
+ def show
19
+ @user = User.find(params[:id])
20
+
21
+ respond_to do |format|
22
+ format.html # show.html.erb
23
+ format.json { render json: @user }
24
+ end
25
+ end
26
+
27
+ # GET /users/new
28
+ # GET /users/new.json
29
+ def new
30
+ @user = User.new
31
+
32
+ respond_to do |format|
33
+ format.html # new.html.erb
34
+ format.json { render json: @user }
35
+ end
36
+ end
37
+
38
+ # GET /users/1/edit
39
+ def edit
40
+ @user = current_user
41
+ end
42
+
43
+ # POST /users
44
+ # POST /users.json
45
+ def create
46
+ @user = User.new(params[:user])
47
+
48
+ respond_to do |format|
49
+ if @user.save
50
+ format.html { redirect_to root_path, notice: 'Registration successful' }
51
+ format.json { render json: @user, status: :created, location: @user }
52
+ else
53
+ format.html { render action: "new" }
54
+ format.json { render json: @user.errors, status: :unprocessable_entity }
55
+ end
56
+ end
57
+ end
58
+
59
+ # PUT /users/1
60
+ # PUT /users/1.json
61
+ def update
62
+ @user = current_user
63
+
64
+ respond_to do |format|
65
+ if @user.update_attributes(params[:user])
66
+ format.html { redirect_to @user, notice: 'User was successfully updated.' }
67
+ format.json { head :ok }
68
+ else
69
+ format.html { render action: "edit" }
70
+ format.json { render json: @user.errors, status: :unprocessable_entity }
71
+ end
72
+ end
73
+ end
74
+
75
+ # DELETE /users/1
76
+ # DELETE /users/1.json
77
+ def destroy
78
+ @user = User.find(params[:id])
79
+ @user.destroy
80
+
81
+ respond_to do |format|
82
+ format.html { redirect_to users_url }
83
+ format.json { head :ok }
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module MainControllerHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module UserSessionsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module UsersHelper
2
+ end
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ acts_as_authentic
3
+ end
@@ -0,0 +1,2 @@
1
+ class UserSession < Authlogic::Session::Base
2
+ end
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Altry</title>
5
+ <%= csrf_meta_tags %>
6
+ </head>
7
+ <body>
8
+ <div class="user_nav">
9
+
10
+ <%- if notice %>
11
+ <div id="notice"><%= notice %></div>
12
+ <%- end %>
13
+
14
+ <%- if current_user %>
15
+ <%= current_user.email %>
16
+ <%= link_to "Logout", logout_path, :method => :delete %>
17
+ <%- else %>
18
+ <%= link_to "Register", new_user_path %>
19
+ <%= link_to "Login", login_path %>
20
+ <%- end %>
21
+ </div>
22
+ <%= yield %>
23
+
24
+ </body>
25
+ </html>