LDAP ObjectClass

ldap 中 ObjectClass 详解(转)

初学LDAP时关于objectClass和Attribute之间的关系总是困扰着我,找过许多的中文资料都没有得到答案。最近终于彻底弄明白了这个问题,决定记录下来,以让后学者少走弯路。非常奇妙的是他们之间的关系与Java里面的一些概念很相似,接下来我会结合Java 来讲讲LDAP中的objectClass与Attribute。
LDAP中每一个Entry必须属于某一个objectClass,用Java的方式来理解这个Entry对应着一个Instance,而 objectClass自然就是class了。
在Java中Class大致可以分为Abstract,concrete两种,只有concrete Class才能生成instance。而在LDAP中objectClass分为三种:Abstract,Structural,AUXIALIARY。具体定义如下:
* Abstract object classes are only intended to be extended by other object classes. An entry must not contain any abstract class unless it also contains a structural or auxiliary class that dervies from that abstract class (i.e., includes a non-abstract object class which has the abstract class in its inheritance chain). All entries must contain at least the “top” abstract object class, in the inheritance chain for their structural class. They may or may not contain other abstract classes in the inheritance chains for their structural class or any of their auxiliary classes.

* Structural object classes are intended to define the crux of what an entry represents. Every entry must include exactly one structural object class chain, and the root of that chain must ultimately be the “top” abstract object class. The structural object class for an entry is not allowed to be changed.

* Auxiliary object classes are intended to define additional qualities of entries. An entry may contain zero or more auxiliary classes, and the set of auxiliary classes associated with an entry may change over time.

简单描述就是:Abstract只用来被其它object class继承,只有当其被Structural object class继承时才出现。要定义一个Entry必须有且只有一个Structural类型的ObjectClass。 Top是一个顶级Abstract ObjectClass,里面定义了一个MUST Attribute:ObjectClass,这就决定了必须有一个其它的Structural ObjectClass才能定义一个Entry.其中ObjectClass又可以存在继承关系,该继承关系于Java中有点相似,子ObjectClass会继承父ObjectClass中的全部Attributes.

接下来看一看ObjectClass与Attribute的关系。
如同Java里面的一个类可以包括多个Field,在业务上可能会定义某些Field是必须的,另外一些是可选的。在LDAP中也存在类似关系,每一个 ObjectClass都定义了一些Attribute,其Attribute仍然可以是ObjectClass。在这些Attriubte中分为两种类型MUST,MAY, MUST表示这个Entry必须包括的属性,MAY为可选。一个ObjectClass的Attribute也包括所有继承自父ObjectClass和自身定义的ObjectClass。
下面用一个类型进行说明:
objectclass ( 2.5.6.0 NAME ‘top’ ABSTRACT
MUST objectClass )
objectclass ( 1.3.6.1.4.1.1466.344 NAME ‘dcObject’
DESC ‘RFC2247: domain component object’
SUP top AUXILIARY
MUST dc )
上面是两个objectclass的定义,其中top为ABSTRACT,dcObject为AUXILIARY,这两个类型都不能定义Entry.下面这个LDIF文件在导入到LDAP时会出错:
dn: dc=java,dc=com
objectClass:dcObject
dc: java.com

要定义这个Entry必须找到一个STRUCTURAL类型的ObjectClass。
objectClasses: ( 2.5.6.4 NAME ‘organization’
DESC ‘RFC2256: an organization’ SUP top STRUCTURAL
MUST o
MAY ( userPassword $ searchGuide $ seeAlso $ businessCategory
$ x121Address $ registeredAddress $ destinationIndicator
$ preferredDeliveryMethod $ telexNumber $ teletexTerminalIdentifier
$ telephoneNumber $ internationaliSDNNumber $ facsimileTelephoneNumber
$ street $ postOfficeBox $ postalCode $ postalAddress
$ physicalDeliveryOfficeName $ st $ l $ description ) )
这个objectClass的类型为STRUCTURAL,因此可以用来定义Entry.具体定义如下
dn: dc=java,dc=com
objectClass:dcObject
objectClass:organization
dc: java.com
o: java.com

其中dc:java.com为dcObject的MUST Attribute,o: java.com为organization的MUST Attribute。

你可能感兴趣的:(LDAP ObjectClass)