Module ActiveLdap::Validations
In: lib/active_ldap/validations.rb
Error AttributeAssignmentError AdapterNotSpecified OperationNotPermitted RequiredObjectClassMissed ConnectionError RequiredAttributeMissed LdifInvalid LdapError DistinguishedNameNotSetError EntryNotFound SaveError StrongAuthenticationRequired AdapterNotFound ConnectionNotEstablished TimeoutError AuthenticationError AttributeValueInvalid EntryNotSaved DistinguishedNameInputInvalid EntryAlreadyExist ObjectClassError UnknownAttribute EntryInvalid DeleteError ConfigurationError DistinguishedNameInvalid DistinguishedName Base Reloadable::Deprecated Reloadable::Subclasses Enumerable Ldif Collection EntryAttribute StandardError Children HasManyWrap HasMany BelongsToMany Proxy BelongsTo Common Find LDIF Delete Update Normalizable GetText Parser ActiveRecord::Callbacks ActiveRecord::Validations Base\n[lib/active_ldap/adapter/base.rb\nlib/active_ldap/adapter/jndi.rb\nlib/active_ldap/adapter/ldap.rb\nlib/active_ldap/adapter/net_ldap.rb] Jndi Ldap NetLdap GetTextSupport Schema\n[lib/active_ldap/schema.rb\nlib/active_ldap/schema/syntaxes.rb] JndiConnection lib/active_ldap/distinguished_name.rb lib/active_ldap/base.rb lib/active_ldap/schema.rb lib/active_ldap/entry_attribute.rb lib/active_ldap/ldif.rb lib/active_ldap/ldap_error.rb ClassMethods Associations LdapBenchmarking ActionController Populate lib/active_ldap/association/has_many_wrap.rb lib/active_ldap/association/children.rb lib/active_ldap/association/collection.rb lib/active_ldap/association/proxy.rb lib/active_ldap/association/belongs_to_many.rb lib/active_ldap/association/belongs_to.rb lib/active_ldap/association/has_many.rb HasManyUtils Association ClassMethods Tree Acts Command Update Common ModifyNameRecordLoadable AddOperationModifiable DeleteOperationModifiable ReplaceOperationModifiable ModifyRecordLoadable DeleteRecordLoadable AddRecordLoadable ContentRecordLoadable LDIF Delete Find Operations GetTextSupport Escape ClassMethods Normalizable Attributes ClassMethods Configuration ClassMethods ObjectClass lib/active_ldap/get_text/parser.rb GetText ClassMethods Callbacks Validations lib/active_ldap/adapter/jndi_connection.rb lib/active_ldap/adapter/net_ldap.rb lib/active_ldap/adapter/ldap.rb lib/active_ldap/adapter/jndi.rb Adapter Helper GetTextFallback ClassMethods HumanReadable Salt UserPassword ClassMethods Connection ActiveLdap dot/m_44_0.png

Methods

Included Modules

ActiveRecord::Validations

External Aliases

human_attribute_name -> human_attribute_name_active_ldap
human_attribute_name -> human_attribute_name_active_record
human_attribute_name_active_ldap -> human_attribute_name

Public Class methods

[Source]

    # File lib/active_ldap/validations.rb, line 5
 5:     def self.append_features(base)
 6:       super
 7: 
 8:       base.class_eval do
 9:         alias_method :new_record?, :new_entry?
10:         class << self
11:           alias_method :human_attribute_name_active_ldap,
12:                        :human_attribute_name
13:         end
14:         include ActiveRecord::Validations
15:         class << self
16:           alias_method :human_attribute_name_active_record,
17:                        :human_attribute_name
18:           alias_method :human_attribute_name,
19:                        :human_attribute_name_active_ldap
20:           unless method_defined?(:human_attribute_name_with_gettext)
21:             def human_attribute_name_with_gettext(attribute_key_name)
22:               s_("#{self}|#{attribute_key_name.humanize}")
23:             end
24:           end
25:         end
26: 
27:         # Workaround for GetText's ugly implementation
28:         begin
29:           instance_method(:save_without_validation)
30:         rescue NameError
31:           alias_method_chain :save, :validation
32:           alias_method_chain :save!, :validation
33:           alias_method_chain :update_attribute, :validation_skipping
34:         end
35: 
36:         validate_on_create :validate_duplicated_dn_creation
37:         validate :validate_excluded_classes
38:         validate :validate_required_ldap_values
39:         validate :validate_ldap_values
40: 
41:         class << self
42:           if method_defined?(:evaluate_condition)
43:             def evaluate_condition_with_active_ldap_support(condition, entry)
44:               evaluate_condition_without_active_ldap_support(condition, entry)
45:             rescue ActiveRecord::ActiveRecordError
46:               raise Error, $!.message
47:             end
48:             alias_method_chain :evaluate_condition, :active_ldap_support
49:           end
50:         end
51: 
52:         def save_with_active_ldap_support!
53:           save_without_active_ldap_support!
54:         rescue ActiveRecord::RecordInvalid
55:           raise EntryInvalid, $!.message
56:         end
57:         alias_method_chain :save!, :active_ldap_support
58: 
59:         private
60:         def run_validations_with_active_ldap_support(validation_method)
61:           run_validations_without_active_ldap_support(validation_method)
62:         rescue ActiveRecord::ActiveRecordError
63:           raise Error, $!.message
64:         end
65:         if private_method_defined?(:run_validations)
66:           alias_method_chain :run_validations, :active_ldap_support
67:         else
68:           alias_method(:run_callbacks_with_active_ldap_support,
69:                        :run_validations_with_active_ldap_support)
70:           alias_method_chain :run_callbacks, :active_ldap_support
71:           alias_method(:run_validations_without_active_ldap_support,
72:                        :run_callbacks_without_active_ldap_support)
73:         end
74:       end
75:     end

[Source]

    # File lib/active_ldap/validations.rb, line 43
43:             def evaluate_condition_with_active_ldap_support(condition, entry)
44:               evaluate_condition_without_active_ldap_support(condition, entry)
45:             rescue ActiveRecord::ActiveRecordError
46:               raise Error, $!.message
47:             end

[Source]

    # File lib/active_ldap/validations.rb, line 21
21:             def human_attribute_name_with_gettext(attribute_key_name)
22:               s_("#{self}|#{attribute_key_name.humanize}")
23:             end

Public Instance methods

[Source]

    # File lib/active_ldap/validations.rb, line 60
60:         def run_validations_with_active_ldap_support(validation_method)
61:           run_validations_without_active_ldap_support(validation_method)
62:         rescue ActiveRecord::ActiveRecordError
63:           raise Error, $!.message
64:         end

[Source]

    # File lib/active_ldap/validations.rb, line 52
52:         def save_with_active_ldap_support!
53:           save_without_active_ldap_support!
54:         rescue ActiveRecord::RecordInvalid
55:           raise EntryInvalid, $!.message
56:         end

Private Instance methods

[Source]

    # File lib/active_ldap/validations.rb, line 78
78:     def validate_duplicated_dn_creation
79:       if id and exist?
80:         if ActiveLdap.get_text_supported?
81:           format = _("%{fn} is duplicated: %s")
82:         else
83:           format = _("is duplicated: %s")
84:         end
85:         errors.add("dn", format % dn)
86:       end
87:     end

[Source]

     # File lib/active_ldap/validations.rb, line 89
 89:     def validate_excluded_classes
 90:       return if self.class.excluded_classes.empty?
 91: 
 92:       _schema = schema
 93:       unexpected_classes = self.class.excluded_classes.collect do |name|
 94:         _schema.object_class(name)
 95:       end
 96:       unexpected_classes -= classes.collect do |name|
 97:         _schema.object_class(name)
 98:       end
 99:       return if unexpected_classes.empty?
100: 
101:       names = unexpected_classes.collect do |object_class|
102:         self.class.human_object_class_name(object_class)
103:       end
104:       if ActiveLdap.get_text_supported?
105:         format = n_("%{fn} has excluded value: %s",
106:                     "%{fn} has excluded values: %s",
107:                     names.size)
108:       else
109:         if names.size == 1
110:           format = "has excluded value: %s"
111:         else
112:           format = "has excluded values: %s"
113:         end
114:       end
115:       errors.add("objectClass", format % names.join(", "))
116:     end

[Source]

     # File lib/active_ldap/validations.rb, line 168
168:     def validate_ldap_value(attribute, name, value)
169:       failed_reason, option = attribute.validate(value)
170:       return if failed_reason.nil?
171:       params = [self.class.human_readable_format(value),
172:                 self.class.human_syntax_description(attribute.syntax),
173:                 failed_reason]
174:       if ActiveLdap.get_text_supported?
175:         if option
176:           format =
177:             _("%{fn} (%s) has invalid format: %s: required syntax: %s: %s")
178:         else
179:           format = _("%{fn} has invalid format: %s: required syntax: %s: %s")
180:         end
181:       else
182:         if option
183:           format = _("(%s) has invalid format: %s: required syntax: %s: %s")
184:         else
185:           format = _("has invalid format: %s: required syntax: %s: %s")
186:         end
187:       end
188:       params.unshift(option) if option
189:       errors.add(name, format % params)
190:     end

[Source]

     # File lib/active_ldap/validations.rb, line 160
160:     def validate_ldap_values
161:       entry_attribute.schemata.each do |name, attribute|
162:         value = self[name]
163:         next if value.nil?
164:         validate_ldap_value(attribute, name, value)
165:       end
166:     end

validate_required_ldap_values

Basic validation:

  • Verify that every ‘MUST’ specified in the schema has a value defined

[Source]

     # File lib/active_ldap/validations.rb, line 122
122:     def validate_required_ldap_values
123:       _schema = nil
124:       # Make sure all MUST attributes have a value
125:       entry_attribute.object_classes.each do |object_class|
126:         object_class.must.each do |required_attribute|
127:           # Normalize to ensure we catch schema problems
128:           # needed?
129:           real_name = to_real_attribute_name(required_attribute.name, true)
130:           raise UnknownAttribute.new(required_attribute) if real_name.nil?
131: 
132:           value = @data[real_name] || []
133:           next unless self.class.blank_value?(value)
134: 
135:           _schema ||= schema
136:           aliases = required_attribute.aliases.collect do |name|
137:             self.class.human_attribute_name(name)
138:           end
139:           args = [self.class.human_object_class_name(object_class)]
140:           if ActiveLdap.get_text_supported?
141:             if aliases.empty?
142:               format = _("%{fn} is required attribute by objectClass '%s'")
143:             else
144:               format = _("%{fn} is required attribute by objectClass " \
145:                          "'%s': aliases: %s")
146:               args << aliases.join(', ')
147:             end
148:           else
149:             format = "is required attribute by objectClass '%s'"
150:             unless aliases.empty?
151:               format << ": aliases: %s"
152:               args << aliases.join(', ')
153:             end
154:           end
155:           errors.add(real_name, format % args)
156:         end
157:       end
158:     end

[Validate]