summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-01-29 18:43:06 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-01-29 18:43:06 +0100
commitbf3af8f8a444365f3040da2928837986409fa016 (patch)
treefa731414747a0dc664b8299aaeeb7f583821fba7
parent75fb68c4d1eb647a268890c080da2dc3875c0e77 (diff)
Single Sign On via a ENV['USER_NAME'] mechanism.
-rw-r--r--app/controllers/application_controller.rb18
-rw-r--r--db/migrate/20130129154700_add_sso_key.rb9
-rw-r--r--db/schema.rb2
3 files changed, 24 insertions, 5 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 2d49890..2aadf19 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -122,11 +122,21 @@ class ApplicationController < ActionController::Base
private
def current_user
- if session[:user_id] && User.where(:id => session[:user_id]).any?
- return User.where(:id => session[:user_id]).first
+ if session[:user_id] || GsParameter.get('SingleSignOnEnvUserNameKey').blank?
+ if session[:user_id] && User.where(:id => session[:user_id]).any?
+ return User.where(:id => session[:user_id]).first
+ else
+ session[:user_id] = nil
+ return nil
+ end
else
- session[:user_id] = nil
- return nil
+ if User.where(:user_name => request.env[GsParameter.get('SingleSignOnEnvUserNameKey')]).any?
+ auth_user = User.where(:user_name => request.env[GsParameter.get('SingleSignOnEnvUserNameKey')]).first
+ session[:user_id] = auth_user.id
+ return auth_user
+ else
+ return nil
+ end
end
end
diff --git a/db/migrate/20130129154700_add_sso_key.rb b/db/migrate/20130129154700_add_sso_key.rb
new file mode 100644
index 0000000..2e47f39
--- /dev/null
+++ b/db/migrate/20130129154700_add_sso_key.rb
@@ -0,0 +1,9 @@
+class AddSsoKey < ActiveRecord::Migration
+ def up
+ GsParameter.create(:name => 'SingleSignOnEnvUserNameKey', :section => 'Generic', :value => '', :class_type => 'Nil', :description => 'When set to a string this env variable will be used to authenticate the user. e.g. REMOTE_USER')
+ end
+
+ def down
+ GsParameter.create(:name => 'SingleSignOnEnvUserNameKey').destroy_all
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 7bae5fd..e1bed77 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20130128121800) do
+ActiveRecord::Schema.define(:version => 20130129154700) do
create_table "access_authorizations", :force => true do |t|
t.string "access_authorizationable_type"