|
#--
|
|
# LdapShadows, a Medium-level LDAP Access Library and Tool.
|
|
# Copyright (c) 2009-2010 Marc Dequènes (Duck) <Duck@DuckCorp.org>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#++
|
|
|
|
module ActiveLdap
|
|
module Validations
|
|
# unfinished workaround for activeldap#26720 (not sure it would work in all cases)
|
|
def validate_required_ldap_values
|
|
_schema = nil
|
|
@validation_skip_attributes ||= []
|
|
_validation_skip_attributes =
|
|
@validation_skip_attributes +
|
|
(self.class.validation_skip_attributes || [])
|
|
# Make sure all MUST attributes have a value
|
|
entry_attribute.object_classes.each do |object_class|
|
|
object_class.must.each do |required_attribute|
|
|
# Normalize to ensure we catch schema problems
|
|
# needed?
|
|
real_name = to_real_attribute_name(required_attribute.name, true)
|
|
raise UnknownAttribute.new(required_attribute) if real_name.nil?
|
|
|
|
next if required_attribute.read_only?
|
|
next if _validation_skip_attributes.include?(real_name)
|
|
|
|
value = @data[real_name] || []
|
|
next unless self.class.blank_value?(value)
|
|
|
|
# Duck: ignore attributes which were not present, as they may not
|
|
# be available because of ACL
|
|
next unless @initial_attribute_list.nil? or @initial_attribute_list.include?(real_name)
|
|
|
|
_schema ||= schema
|
|
aliases = required_attribute.aliases.collect do |name|
|
|
self.class.human_attribute_name(name)
|
|
end
|
|
args = [self.class.human_object_class_name(object_class)]
|
|
if aliases.empty?
|
|
format = _("%{fn} is required attribute by objectClass '%s'")
|
|
else
|
|
format = _("%{fn} is required attribute by objectClass " \
|
|
"'%s': aliases: %s")
|
|
args << aliases.join(', ')
|
|
end
|
|
unless ActiveLdap.get_text_supported?
|
|
format = format.sub(/^%\{fn\} /, '')
|
|
end
|
|
errors.add(real_name, format % args)
|
|
end
|
|
end
|
|
end
|
|
def load_initial_attribute_list
|
|
@initial_attribute_list ||= self.nonempty_attributes
|
|
end
|
|
end
|
|
|
|
# This is useful with Base.search()
|
|
module Adapter
|
|
class Base
|
|
public :escape_filter_value
|
|
end
|
|
end
|
|
|
|
# fix for activeldap#28433
|
|
class Base
|
|
def set_attribute(name, value)
|
|
real_name = to_real_attribute_name(name)
|
|
_dn_attribute = nil
|
|
valid_dn_attribute = true
|
|
begin
|
|
_dn_attribute = dn_attribute
|
|
rescue DistinguishedNameInvalid
|
|
valid_dn_attribute = false
|
|
end
|
|
if valid_dn_attribute and real_name == _dn_attribute
|
|
if value.is_a? Array
|
|
value = "#{value.first},#{dn.parent.to_s}"
|
|
end
|
|
real_name, value = register_new_dn_attribute(real_name, value)
|
|
end
|
|
raise UnknownAttribute.new(name) if real_name.nil?
|
|
|
|
@data[real_name] = value
|
|
@simplified_data = nil
|
|
if real_name == _dn_attribute
|
|
ensure_update_dn
|
|
@dn = compute_dn
|
|
end
|
|
end
|
|
end
|
|
end
|