Permalink
Browse files

First working version

  • Loading branch information...
1 parent 8c1bd88 commit 9adeb88b8c85e85d1b0e5980fd6c06015c7d26c7 @mirek mirek committed May 5, 2010
Showing with 108 additions and 0 deletions.
  1. +10 −0 README.rdoc
  2. +4 −0 config/locales/en.yml
  3. +2 −0 init.rb
  4. +2 −0 lang/en.yml
  5. +85 −0 lib/redmine_cas.rb
  6. +5 −0 test/test_helper.rb
View
@@ -0,0 +1,10 @@
+= Redmine CAS Plugin
+
+Redmine CAS authentication plugin.
+
+= Requirements
+
+ruby script/plugin install git@github.com:ifad/redmine-cas-plugin.git
+Tested with Redmine 0.9.x
+
+
@@ -0,0 +1,4 @@
+# English strings go here for Rails i18n
+en:
+ cas_authenticated_user_not_found: "Username %s authenticated with CAS but not found in Redmine. Please create user in Redmine."
+
View
@@ -0,0 +1,2 @@
+require 'redmine'
+require 'redmine_cas'
View
@@ -0,0 +1,2 @@
+# English strings go here
+my_label: "My label"
View
@@ -0,0 +1,85 @@
+require 'casclient'
+require 'casclient/frameworks/rails/filter'
+
+unless Setting.respond_to?(:cas_server_url)
+
+ Redmine::Plugin.register :redmine_cas do
+ name "Redmine CAS plugin [disabled]"
+ author 'Mirek'
+ description "Redmine CAS authentication. To enable this plugin define 'cas_server_url' setting."
+ version '0.0.1'
+ end
+
+else
+
+ Redmine::Plugin.register :redmine_cas do
+ name "Redmine CAS plugin"
+ author 'Mirek Rusin <mirek [at] me [dot] com>'
+ description "Redmine CAS authentication (#{Setting.cas_server_url})"
+ version '0.0.1'
+ #menu :account_menu, :cas_sign_in, { :controller => 'account', :action => 'cas_login' }, :caption => 'CAS sign in'
+
+ settings :default => {
+ 'tab_text' => '',
+ 'tab_name' => 'Tab Name',
+ 'system_tab_text' => '',
+ 'system_tab_name' => 'System Tab Name',
+ :cas => {
+ :server => '',
+ :autocreate_users => false
+ }
+ }, :partial => 'settings/redminetab_settings'
+
+ end
+
+ CASClient::Frameworks::Rails::Filter.configure(
+ :cas_base_url => Setting.cas_server_url
+ )
+
+ ActionController::Dispatcher.to_prepare do
+
+ AccountController.class_eval do
+
+ def login_with_cas
+ if params[:username].blank? && params[:password].blank? && Setting.respond_to?(:cas_server_url)
+ if session[:user_id]
+ true
+ else
+ if CASClient::Frameworks::Rails::Filter.filter(self)
+ if user = User.find_by_login(session[:cas_user])
+ session[:user_id] = user.id
+ user_setup
+ redirect_to :controller => 'my', :action => 'page'
+ else
+ unless flash[:error]
+ flash[:error] = l(:cas_authenticated_user_not_found, session[:cas_user])
+ redirect_to :controller => params[:controller],
+ :action => params[:action],
+ :back_url => params[:back_url]
+ end
+ end
+ end
+ end
+ else
+ login_without_cas
+ end
+ end
+
+ alias_method_chain :login, :cas
+
+ def logout_with_cas
+ if Setting.respond_to?(:cas_server_url)
+ logout_user
+ CASClient::Frameworks::Rails::Filter.logout(self, home_url)
+ else
+ logout_without_cas
+ end
+ end
+
+ alias_method_chain :logout, :cas
+
+ end
+
+ end
+
+end
View
@@ -0,0 +1,5 @@
+# Load the normal Rails helper
+require File.expand_path(File.dirname(__FILE__) + '/../../../../test/test_helper')
+
+# Ensure that we are using the temporary fixture path
+Engines::Testing.set_fixture_path

0 comments on commit 9adeb88

Please sign in to comment.