Project

General

Profile

Download (3.37 KB) Statistics
| Branch: | Tag: | Revision:
#--
# 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
# 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?

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

# Duck: quick fix for #27429
def validate_excluded_classes
return if self.class.excluded_classes.empty?

current_objectclasses = self.classes.collect {|name| name.downcase }

unexpected_classes = self.class.excluded_classes.select do |name|
current_objectclasses.include? name.downcase
end
return if unexpected_classes.empty?

names = unexpected_classes.collect do |object_class|
self.class.human_object_class_name(object_class)
end
format = n_("%{fn} has excluded value: %s",
"%{fn} has excluded values: %s",
names.size)
format = format.sub(/^%\{fn\} /, '') unless ActiveLdap.get_text_supported?
errors.add("objectClass", format % names.join(", "))
end

# Duck: new method, should be hooked somewhere
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
end
(1-1/9)