Class ActiveLdap::Schema
In: lib/active_ldap/schema.rb
Parent: Object
Error DeleteError AdapterNotSpecified OperationNotPermitted LdapError RequiredAttributeMissed AttributeAssignmentError RequiredObjectClassMissed DistinguishedNameNotSetError StrongAuthenticationRequired ConnectionError SaveError EntryNotFound AuthenticationError EntryNotSaved UnknownAttribute ConnectionNotEstablished TimeoutError ConfigurationError AdapterNotFound DistinguishedNameInvalid ObjectClassError EntryInvalid EntryAlreadyExist Reloadable::Deprecated Base Reloadable::Subclasses Enumerable Collection StandardError HasMany HasManyWrap BelongsToMany Proxy BelongsTo Base\n[lib/active_ldap/adapter/base.rb\nlib/active_ldap/adapter/ldap.rb\nlib/active_ldap/adapter/net_ldap.rb] Ldap NetLdap ActiveRecord::Callbacks ActiveRecord::Validations Schema DistinguishedName lib/active_ldap/base.rb lib/active_ldap/schema.rb lib/active_ldap/distinguished_name.rb lib/active_ldap/ldap_error.rb ClassMethods Associations lib/active_ldap/association/has_many_wrap.rb lib/active_ldap/association/has_many.rb lib/active_ldap/association/proxy.rb lib/active_ldap/association/collection.rb lib/active_ldap/association/belongs_to_many.rb lib/active_ldap/association/belongs_to.rb Association ClassMethods Configuration Command lib/active_ldap/adapter/net_ldap.rb lib/active_ldap/adapter/ldap.rb lib/active_ldap/adapter/base.rb Adapter ClassMethods Attributes ClassMethods ObjectClass Callbacks ClassMethods Connection Validations Salt UserPassword ActiveLdap dot/m_26_0.png

Methods

Constants

NUMERIC_OID_RE = "\\d[\\d\\.]+"
DESCRIPTION_RE = "[a-zA-Z][a-zA-Z\\d\\-]*"
OID_RE = "(?:#{NUMERIC_OID_RE}|#{DESCRIPTION_RE}-oid)"
RESERVED_NAMES_RE = /(?:#{reserved_names.join('|')})/

Public Class methods

[Source]

   # File lib/active_ldap/schema.rb, line 3
3:     def initialize(entries)
4:       @entries = default_entries.merge(entries || {})
5:       @schema_info = {}
6:       @class_attributes_info = {}
7:       @cache = {}
8:     end

Public Instance methods

[](group, id_or_name, attribute_name)

Alias for attribute

attr(group, id_or_name, attribute_name)

Alias for attribute

attribute

This is just like LDAP::Schema#attribute except that it allows look up in any of the given keys. e.g.

 attribute('attributeTypes', 'cn', 'DESC')
 attribute('ldapSyntaxes', '1.3.6.1.4.1.1466.115.121.1.5', 'DESC')

[Source]

    # File lib/active_ldap/schema.rb, line 25
25:     def attribute(group, id_or_name, attribute_name)
26:       return [] if attribute_name.empty?
27:       attribute_name = normalize_attribute_name(attribute_name)
28:       value = attributes(group, id_or_name)[attribute_name]
29:       value ? value.dup : []
30:     end

attribute_aliases

Returns all names from the LDAP schema for the attribute given.

[Source]

    # File lib/active_ldap/schema.rb, line 78
78:     def attribute_aliases(name)
79:       cache([:attribute_aliases, name]) do
80:         attribute_type(name, 'NAME')
81:       end
82:     end

[Source]

    # File lib/active_ldap/schema.rb, line 37
37:     def attributes(group, id_or_name)
38:       return {} if group.empty? or id_or_name.empty?
39: 
40:       unless @entries.has_key?(group)
41:         raise ArgumentError, "Unknown schema group: #{group}"
42:       end
43: 
44:       # Initialize anything that is required
45:       info, ids, aliases = ensure_schema_info(group)
46:       id, name = determine_id_or_name(id_or_name, aliases)
47: 
48:       # Check already parsed options first
49:       return ids[id] if ids.has_key?(id)
50: 
51:       schemata = @entries[group] || []
52:       while schema = schemata.shift
53:         next unless /\A\s*\(\s*(#{OID_RE})\s*(.*)\s*\)\s*\z/ =~ schema
54:         schema_id = $1
55:         rest = $2
56:         next if ids.has_key?(schema_id)
57: 
58:         attributes = {}
59:         ids[schema_id] = attributes
60: 
61:         parse_attributes(rest, attributes)
62:         (attributes["NAME"] || []).each do |v|
63:           normalized_name = normalize_schema_name(v)
64:           aliases[normalized_name] = schema_id
65:           id = schema_id if id.nil? and name == normalized_name
66:         end
67: 
68:         break if id == schema_id
69:       end
70: 
71:       ids[id || aliases[name]] || {}
72:     end

binary?

Returns true if the given attribute‘s syntax is X-NOT-HUMAN-READABLE or X-BINARY-TRANSFER-REQUIRED

[Source]

     # File lib/active_ldap/schema.rb, line 109
109:     def binary?(name)
110:       cache([:binary?, name]) do
111:         # Get syntax OID
112:         syntax = attribute_type(name, 'SYNTAX')[0]
113:         !syntax.nil? and
114:           (ldap_syntax(syntax, 'X-NOT-HUMAN-READABLE') == ["TRUE"] or
115:            ldap_syntax(syntax, 'X-BINARY-TRANSFER-REQUIRED') == ["TRUE"])
116:       end
117:     end

binary_required?

Returns true if the value MUST be transferred in binary

[Source]

     # File lib/active_ldap/schema.rb, line 122
122:     def binary_required?(name)
123:       cache([:binary_required?, name]) do
124:         # Get syntax OID
125:         syntax = attribute_type(name, 'SYNTAX')[0]
126:         !syntax.nil? and
127:           ldap_syntax(syntax, 'X-BINARY-TRANSFER-REQUIRED') == ["TRUE"]
128:       end
129:     end

class_attributes

Returns an Array of all the valid attributes (but not with full aliases) for the given objectClass

[Source]

     # File lib/active_ldap/schema.rb, line 135
135:     def class_attributes(objc)
136:       cache([:class_attributes, objc]) do
137:         # First get all the current level attributes
138:         must = object_class(objc, 'MUST')
139:         may = object_class(objc, 'MAY')
140: 
141:         # Now add all attributes from the parent object (SUPerclasses)
142:         # Hopefully an iterative approach will be pretty speedy
143:         # 1. build complete list of SUPs
144:         # 2. Add attributes from each
145:         sups = object_class(objc, 'SUP')
146:         loop do
147:           start_size = sups.size
148:           new_sups = []
149:           sups.each do |sup|
150:             new_sups.concat(object_class(sup, 'SUP'))
151:           end
152: 
153:           sups.concat(new_sups)
154:           sups.uniq!
155:           break if sups.size == start_size
156:         end
157:         sups.each do |sup|
158:           must.concat(object_class(sup, 'MUST'))
159:           may.concat(object_class(sup, 'MAY'))
160:         end
161: 
162:         # Clean out the dupes.
163:         must.uniq!
164:         may.uniq!
165:         if objc == "inetOrgPerson"
166:           may.collect! do |name|
167:             if name == "x500uniqueIdentifier"
168:               "x500UniqueIdentifier"
169:             else
170:               name
171:             end
172:           end
173:         end
174: 
175:         {:must => must, :may => may}
176:       end
177:     end

[Source]

    # File lib/active_ldap/schema.rb, line 14
14:     def exist_name?(group, name)
15:       alias_map(group).has_key?(normalize_schema_name(name))
16:     end

[Source]

    # File lib/active_ldap/schema.rb, line 10
10:     def names(group)
11:       alias_map(group).keys
12:     end

read_only?

Returns true if an attribute is read-only NO-USER-MODIFICATION

[Source]

    # File lib/active_ldap/schema.rb, line 88
88:     def read_only?(name)
89:       cache([:read_only?, name]) do
90:         attribute_type(name, 'NO-USER-MODIFICATION')[0] == 'TRUE'
91:       end
92:     end

single_value?

Returns true if an attribute can only have one value defined SINGLE-VALUE

[Source]

     # File lib/active_ldap/schema.rb, line 99
 99:     def single_value?(name)
100:       cache([:single_value?, name]) do
101:         attribute_type(name, 'SINGLE-VALUE')[0] == 'TRUE'
102:       end
103:     end

Private Instance methods

[Source]

     # File lib/active_ldap/schema.rb, line 270
270:     def alias_map(group)
271:       ensure_parse(group)
272:       return {} if @schema_info[group].nil?
273:       @schema_info[group][:aliases] || {}
274:     end

[Source]

     # File lib/active_ldap/schema.rb, line 251
251:     def attribute_type(name, attribute_name)
252:       cache([:attribute_type, name, attribute_name]) do
253:         attribute("attributeTypes", name, attribute_name)
254:       end
255:     end

[Source]

     # File lib/active_ldap/schema.rb, line 180
180:     def cache(key)
181:       (@cache[key] ||= [yield])[0]
182:     end

[Source]

     # File lib/active_ldap/schema.rb, line 291
291:     def default_entries
292:       {
293:         "objectClasses" => [],
294:         "attributeTypes" => [],
295:         "ldapSyntaxes" => [],
296:       }
297:     end

[Source]

     # File lib/active_ldap/schema.rb, line 190
190:     def determine_id_or_name(id_or_name, aliases)
191:       if /\A[\d\.]+\z/ =~ id_or_name
192:         id = id_or_name
193:         name = nil
194:       else
195:         name = normalize_schema_name(id_or_name)
196:         id = aliases[name]
197:       end
198:       [id, name]
199:     end

[Source]

     # File lib/active_ldap/schema.rb, line 276
276:     def ensure_parse(group)
277:       return if @entries[group].nil?
278:       unless @entries[group].empty?
279:         attribute(group, 'nonexistent', 'nonexistent')
280:       end
281:     end

[Source]

     # File lib/active_ldap/schema.rb, line 184
184:     def ensure_schema_info(group)
185:       @schema_info[group] ||= {:ids => {}, :aliases => {}}
186:       info = @schema_info[group]
187:       [info, info[:ids], info[:aliases]]
188:     end

[Source]

     # File lib/active_ldap/schema.rb, line 257
257:     def ldap_syntax(name, attribute_name)
258:       return [] unless @entries.has_key?("ldapSyntaxes")
259:       cache([:ldap_syntax, name, attribute_name]) do
260:         attribute("ldapSyntaxes", name, attribute_name)
261:       end
262:     end

[Source]

     # File lib/active_ldap/schema.rb, line 287
287:     def normalize_attribute_name(name)
288:       name.upcase.gsub(/_/, "-")
289:     end

[Source]

     # File lib/active_ldap/schema.rb, line 283
283:     def normalize_schema_name(name)
284:       name.downcase.sub(/;.*$/, '')
285:     end

[Source]

     # File lib/active_ldap/schema.rb, line 264
264:     def object_class(name, attribute_name)
265:       cache([:object_class, name, attribute_name]) do
266:         attribute("objectClasses", name, attribute_name)
267:       end
268:     end

[Source]

     # File lib/active_ldap/schema.rb, line 223
223:     def parse_attributes(str, attributes)
224:       str.scan(/([A-Z\-_]+)\s+
225:                 (?:\(\s*([\w\-]+(?:\s+\$\s+[\w\-]+)+)\s*\)|
226:                    \(\s*([^\)]*)\s*\)|
227:                    '([^\']*)'|
228:                    ((?!#{RESERVED_NAMES_RE})[a-zA-Z][a-zA-Z\d\-;]*)|
229:                    (\d[\d\.\{\}]+)|
230:                    ()
231:                 )/x
232:                ) do |name, multi_amp, multi, string, literal, syntax, no_value|
233:         case
234:         when multi_amp
235:           values = multi_amp.rstrip.split(/\s*\$\s*/)
236:         when multi
237:           values = multi.scan(/\s*'([^\']*)'\s*/).collect {|value| value[0]}
238:         when string
239:           values = [string]
240:         when literal
241:           values = [literal]
242:         when syntax
243:           values = [syntax]
244:         when no_value
245:           values = ["TRUE"]
246:         end
247:         attributes[normalize_attribute_name(name)] = values
248:       end
249:     end

[Validate]