From 87f77507a1ea50767c5d818beb85434df80d9bbe Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Tue, 1 Mar 2011 18:20:54 +0300 Subject: [PATCH] SONAR-1923 Add option to force downcase of username during authentication --- .../main/webapp/WEB-INF/lib/need_authentication.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/lib/need_authentication.rb b/sonar-server/src/main/webapp/WEB-INF/lib/need_authentication.rb index eb07a596720..8df6024d53f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/lib/need_authentication.rb +++ b/sonar-server/src/main/webapp/WEB-INF/lib/need_authentication.rb @@ -88,17 +88,25 @@ module NeedAuthentication # def authenticate(login, password) return nil if login.blank? + java_facade = Java::OrgSonarServerUi::JRubyFacade.new + + # Downcase login (typically for Active Directory) + # Note that login in Sonar DB is case-sensitive, however in this case authentication and automatic user creation will always happen with downcase login + downcase = java_facade.getConfigurationValue('sonar.authenticator.downcase') + if downcase == 'true' + login = login.downcase + end + return nil if !AuthenticatorFactory.authenticator.authenticate?(login, password) user = User.find_by_login(login) # Automatically create a user in the sonar db if authentication has been successfully done - java_facade = Java::OrgSonarServerUi::JRubyFacade.new - create_user = java_facade.getConfigurationValue('sonar.authenticator.createUsers'); + create_user = java_facade.getConfigurationValue('sonar.authenticator.createUsers') if !user && create_user=='true' user=User.new(:login => login, :name => login, :email => '', :password => password, :password_confirmation => password) user.save! - default_group_name = java_facade.getConfigurationValue('sonar.defaultGroup') || 'sonar-users'; + default_group_name = java_facade.getConfigurationValue('sonar.defaultGroup') || 'sonar-users' default_group=Group.find_by_name(default_group_name) if default_group user.groups<