Project

General

Profile

Download (3.57 KB) Statistics
| Branch: | Tag: | Revision:
bc2c2691 Marc Dequènes (Duck)
#--
# 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/>.
#++

b52f0f7d Marc Dequènes (Duck)
module ActiveLdap
module Validations
822a42a2 Marc Dequènes (Duck)
# unfinished workaround for activeldap#26720 (not sure it would work in all cases)
b52f0f7d Marc Dequènes (Duck)
def validate_required_ldap_values
_schema = nil
a38e7f81 Marc Dequènes (Duck)
@validation_skip_attributes ||= []
_validation_skip_attributes =
@validation_skip_attributes +
(self.class.validation_skip_attributes || [])
b52f0f7d Marc Dequènes (Duck)
# 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?
a38e7f81 Marc Dequènes (Duck)
next if _validation_skip_attributes.include?(real_name)
b52f0f7d Marc Dequènes (Duck)
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 " \
a38e7f81 Marc Dequènes (Duck)
"'%s': aliases: %s")
b52f0f7d Marc Dequènes (Duck)
args << aliases.join(', ')
end
unless ActiveLdap.get_text_supported?
format = format.sub(/^%\{fn\} /, '')
end
errors.add(real_name, format % args)
a38e7f81 Marc Dequènes (Duck)
end
end
b52f0f7d Marc Dequènes (Duck)
end
def load_initial_attribute_list
@initial_attribute_list ||= self.nonempty_attributes
end
end
bd714351 Marc Dequènes (Duck)
# This is useful with Base.search()
module Adapter
class Base
public :escape_filter_value
end
end
84bedafb Marc Dequènes (Duck)
# 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
76ea1583 Marc Dequènes (Duck)
if real_name == _dn_attribute
ensure_update_dn
@dn = compute_dn
end
84bedafb Marc Dequènes (Duck)
end
end
b52f0f7d Marc Dequènes (Duck)
end