From 4cc4175806a86cc2bce5321ab64478e348a7f3e7 Mon Sep 17 00:00:00 2001
From: Romain Vrignaud <romain@yakaz.com>
Date: Tue, 15 Nov 2011 17:10:40 +0100
Subject: [PATCH] Fixes #1300 with REMOTE_USER support

---
 app/controllers/application_controller.rb |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 0783d91..70c9b0e 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -63,6 +63,14 @@ class ApplicationController < ActionController::Base
           logger.warn("Failed authentcation from #{request.remote_ip} #{user}") if User.current.nil?
           return !User.current.nil?
         end
+	# if login delegation authorized and REMOTE_USER not empty, authenticate user without using password
+	if SETTINGS[:authorize_login_delegation] == true and !request.env["REMOTE_USER"].nil?
+	  user = User.find_by_login(request.env["REMOTE_USER"])
+	  User.current = user.is_a?(User) ? user : nil
+	  logger.warn("Failed authentcation from REMOTE_USER") if User.current.nil?
+	  session[:user] = User.current.id
+	  return !User.current.nil?
+	end
         session[:original_uri] = request.request_uri # keep the old request uri that we can redirect later on
         redirect_to login_users_path and return
       else
-- 
1.7.2.5

