From: Jan Provaznik <jprovazn(a)redhat.com>
- LDAP auth is now more configurable, whole username distinguish name
can be set in settings.yml, it's now also compatible with Active Directory.
- also switched to symbols in config/settings.yml to avoid mess (existing :iwhd tag)
---
src/app/models/provider.rb | 2 +-
src/app/models/user.rb | 2 +-
src/config/initializers/warden.rb | 2 +-
src/config/settings.yml | 16 ++++++++++------
src/lib/ldap.rb | 7 ++++---
5 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb
index 84106d3..1b11029 100644
--- a/src/app/models/provider.rb
+++ b/src/app/models/provider.rb
@@ -37,7 +37,7 @@ class Provider < ActiveRecord::Base
require 'util/conductor'
include PermissionedObject
- DEFAULT_DELTACLOUD_URL = SETTINGS_CONFIG['default_deltacloud_url']
+ DEFAULT_DELTACLOUD_URL = SETTINGS_CONFIG[:default_deltacloud_url]
has_many :provider_accounts, :dependent => :destroy
has_many :hardware_profiles, :dependent => :destroy
diff --git a/src/app/models/user.rb b/src/app/models/user.rb
index c4f87c8..3d275b6 100644
--- a/src/app/models/user.rb
+++ b/src/app/models/user.rb
@@ -106,7 +106,7 @@ class User < ActiveRecord::Base
end
def self.authenticate_using_ldap(username, password)
- if Ldap.valid_ldap_authentication?(username, password,
SETTINGS_CONFIG['auth']['ldap'])
+ if Ldap.valid_ldap_authentication?(username, password,
SETTINGS_CONFIG[:auth][:ldap])
u = User.find_by_login(username) || create_ldap_user!(username)
return u
else
diff --git a/src/config/initializers/warden.rb b/src/config/initializers/warden.rb
index 251fb42..33e7dfd 100644
--- a/src/config/initializers/warden.rb
+++ b/src/config/initializers/warden.rb
@@ -5,7 +5,7 @@ Rails.configuration.middleware.use RailsWarden::Manager do |config|
# all UI requests are handled in the default scope
config.scope_defaults(
:user,
- :strategies => [SETTINGS_CONFIG['auth']['strategy'].to_sym],
+ :strategies => [SETTINGS_CONFIG[:auth][:strategy].to_sym],
:store => true,
:action => 'unauthenticated'
)
diff --git a/src/config/settings.yml b/src/config/settings.yml
index 621500c..0a629f1 100644
--- a/src/config/settings.yml
+++ b/src/config/settings.yml
@@ -1,10 +1,14 @@
-default_deltacloud_url:
http://localhost:3002/api
+:default_deltacloud_url:
http://localhost:3002/api
-auth:
+:auth:
# supported strategies: database, ldap
- strategy: database
- ldap:
- host: localhost
- base: ou=People,dc=my-domain,dc=com
+ :strategy: database
+ :ldap:
+ :host: localhost
+ # '%s' expression in username_dn string will be replaced
+ # by user's login
+ # username_dn: "deltacloud\%s"
+ :username_dn: uid=%s,ou=People,dc=my-domain,dc=com
+ # :port: 389
:iwhd:
:url:
http://localhost:9090
diff --git a/src/lib/ldap.rb b/src/lib/ldap.rb
index 53f6978..2f91ba6 100644
--- a/src/lib/ldap.rb
+++ b/src/lib/ldap.rb
@@ -23,13 +23,14 @@ module Ldap
def initialize(config)
@ldap = Net::LDAP.new
- @ldap.host = config['host']
- @base = config['base']
+ @ldap.host = config[:host]
+ @ldap.port = config[:port] || 389
+ @username_dn = config[:username_dn]
end
def bind?(uid, password)
begin
- @ldap.auth "uid=#{uid},#{@base}", password
+ @ldap.auth(@username_dn % uid, password)
@ldap.bind
rescue Exception => e
Rails.logger.error e.message
--
1.7.6