Skip to content
Browse files

add cas login

  • Loading branch information...
1 parent 5031c59 commit 4c92dad2c5c062aa53ee060c99392e020d8ba764 @jlapier committed Feb 14, 2012
View
2 Gemfile
@@ -22,6 +22,8 @@ gem 'RedCloth', :require => 'redcloth'
gem 'ruby-openid', :require => 'openid'
gem "will_paginate", "~> 3.0.pre2"
+gem 'rubycas-client-rails', :git => 'git://github.com/thegekko/rubycas-client-rails.git'
+
group :development, :test do
gem 'annotate'
gem 'acts_as_fu'
View
11 Gemfile.lock
@@ -13,6 +13,14 @@ GIT
specs:
acts_as_revisable (1.1.2)
+GIT
+ remote: git://github.com/thegekko/rubycas-client-rails.git
+ revision: fc2c5a5e1ce4951089ca5c994ae5678435cd4c7f
+ specs:
+ rubycas-client-rails (0.1.1)
+ rails (>= 3.0.0)
+ rubycas-client (>= 2.3.5)
+
GEM
remote: http://rubygems.org/
specs:
@@ -140,6 +148,8 @@ GEM
railties (~> 3.0)
rspec (~> 2.7.0)
ruby-openid (2.1.8)
+ rubycas-client (2.3.8)
+ activesupport
rubyzip (0.9.5)
selenium-webdriver (2.14.0)
childprocess (>= 0.2.1)
@@ -188,6 +198,7 @@ DEPENDENCIES
rcov
rspec-rails
ruby-openid
+ rubycas-client-rails!
sqlite3-ruby
webrat
will_paginate (~> 3.0.pre2)
View
12 app/controllers/application_controller.rb
@@ -1,6 +1,8 @@
class ApplicationController < ActionController::Base
rescue_from ActiveRecord::RecordNotFound, :with => :broken_link
+ before_filter RubyCAS::GatewayFilter
+
PUBLIC_RESOURCES = {
EventCalendar::Event => [:read],
FileAttachment => [:read, :download],
@@ -194,7 +196,15 @@ def current_user_session
def current_user
return @current_user if defined?(@current_user)
- @current_user = current_user_session && current_user_session.record
+ if session[:cas_user]
+ @current_user = User.find(:first,
+ :conditions => ["LOWER(users.email) = ?",
+ session[:cas_user].mb_chars.downcase])
+ # ,
+ # :include => [:user_collections, :main_role])
+ else
+ @current_user = current_user_session && current_user_session.record
+ end
end
def require_user
View
1 app/controllers/forums_controller.rb
@@ -1,5 +1,4 @@
class ForumsController < ApplicationController
-
before_filter :require_admin_user, :except => [:index, :show]
before_filter :get_forum, :only => [:show, :edit, :update, :destroy, :search]
before_filter :require_forum_read_access, :only => [:show]
View
21 app/controllers/user_sessions_controller.rb
@@ -1,4 +1,5 @@
class UserSessionsController < ApplicationController
+ before_filter RubyCAS::Filter, :only => :cas_login
before_filter :require_no_user, :only => [:create]
before_filter :require_user, :only => :destroy
@@ -19,8 +20,22 @@ def create
end
def destroy
- current_user_session.destroy
- flash[:notice] = "Logout successful!"
- redirect_back_or_default login_url
+ if session[:cas_user]
+ session[:cas_user] = nil
+ redirect_to "http://auth.tadnet.org/logout"
+ else
+ current_user_session.destroy if current_user_session
+ flash[:notice] = "Logout successful!"
+ redirect_back_or_default login_url
+ end
+ end
+
+ def cas_login
+ if current_user
+ flash[:notice] = "Logged in with CAS"
+ else
+ flash[:warning] = "Problem logging in with CAS"
+ end
+ redirect_back_or_default '/'
end
end
View
2 app/helpers/application_helper.rb
@@ -125,7 +125,7 @@ def user_box(my_options={})
end
else
out += link_to("Register", new_account_path) + options[:link_separator].html_safe +
- link_to( "Log In", new_user_session_path)
+ link_to( "Log In", login_path)
end
if options[:include_blog_link]
other_links << link_to("Blog", blog_posts_path)
View
12 config/application.rb
@@ -63,5 +63,17 @@ class Application < Rails::Application
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
+
+ config.rubycas.cas_base_url = 'http://auth.tadnet.org/'
+ config.rubycas.logger = Rails.logger
end
end
+
+module RubyCAS
+ class GatewayFilter < Filter
+ def self.use_gatewaying?
+ return true unless @@config[:use_gatewaying] == false
+ end
+ end
+end
+
View
5 config/routes.rb
@@ -157,10 +157,13 @@
# end
# end
- resource :user_session
+ resource :user_session do
+ get :cas_login
+ end
resources :password_resets
match '/register' => 'users#new', :as => :register
match '/login' => 'user_sessions#new', :as => :login
+ match '/cas_login' => 'user_sessions#cas_login', :as => :cas_login
match '/' => 'content_pages#home'
match '*a', :to => 'errors#routing'

0 comments on commit 4c92dad

Please sign in to comment.
Something went wrong with that request. Please try again.