2014-10-13 15:24:05 +00:00
|
|
|
# Load a specific server configuration
|
|
|
|
module Gitlab
|
|
|
|
module LDAP
|
|
|
|
class Config
|
|
|
|
attr_accessor :provider, :options
|
|
|
|
|
|
|
|
def self.enabled?
|
|
|
|
Gitlab.config.ldap.enabled
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.servers
|
2014-10-14 11:11:53 +00:00
|
|
|
Gitlab.config.ldap.servers.values
|
2014-10-13 15:24:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.providers
|
2014-10-14 11:11:53 +00:00
|
|
|
servers.map {|server| server['provider_name'] }
|
2014-10-13 15:24:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(provider)
|
|
|
|
@provider = provider
|
|
|
|
invalid_provider unless valid_provider?
|
|
|
|
@options = config_for(provider)
|
|
|
|
end
|
|
|
|
|
|
|
|
def enabled?
|
|
|
|
base_config.enabled
|
|
|
|
end
|
|
|
|
|
|
|
|
def adapter_options
|
|
|
|
{
|
|
|
|
host: options['host'],
|
|
|
|
port: options['port'],
|
|
|
|
encryption: encryption
|
|
|
|
}.tap do |options|
|
|
|
|
options.merge!(auth_options) if has_auth?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def base
|
|
|
|
options['base']
|
|
|
|
end
|
|
|
|
|
|
|
|
def uid
|
|
|
|
options['uid']
|
|
|
|
end
|
|
|
|
|
|
|
|
def sync_ssh_keys?
|
|
|
|
sync_ssh_keys.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
# The LDAP attribute in which the ssh keys are stored
|
|
|
|
def sync_ssh_keys
|
|
|
|
options['sync_ssh_keys']
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_filter
|
|
|
|
options['user_filter']
|
|
|
|
end
|
|
|
|
|
|
|
|
def group_base
|
|
|
|
options['group_base']
|
|
|
|
end
|
|
|
|
|
|
|
|
def admin_group
|
|
|
|
options['admin_group']
|
|
|
|
end
|
|
|
|
|
|
|
|
def active_directory
|
|
|
|
options['active_directory']
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
def base_config
|
|
|
|
Gitlab.config.ldap
|
|
|
|
end
|
|
|
|
|
|
|
|
def config_for(provider)
|
2014-10-14 11:11:53 +00:00
|
|
|
base_config.servers.values.find { |server| server['provider_name'] == provider }
|
2014-10-13 15:24:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def encryption
|
|
|
|
case options['method'].to_s
|
|
|
|
when 'ssl'
|
|
|
|
:simple_tls
|
|
|
|
when 'tls'
|
|
|
|
:start_tls
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def valid_provider?
|
|
|
|
self.class.providers.include?(provider)
|
|
|
|
end
|
|
|
|
|
|
|
|
def invalid_provider
|
|
|
|
raise "Unknown provider (#{provider}). Available providers: #{self.class.providers}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def auth_options
|
|
|
|
{
|
|
|
|
auth: {
|
|
|
|
method: :simple,
|
|
|
|
username: options['bind_dn'],
|
|
|
|
password: options['password']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def has_auth?
|
|
|
|
options['password'] || options['bind_dn']
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|