Syntax
syntax是LDAP中的“语法”,其实就是LDAP中会用到的数据类型和数据约束,这个语法是遵从X.500中数据约束的定义的。其定义需要有一个ID(遵从X.500)以及说明(DESP)
Commonly Used Syntaxes | ||
Name | OID | Description |
boolean | 1.3.6.1.4.1.1466.115.121.1.7 | boolean value |
distinguishedName | 1.3.6.1.4.1.1466.115.121.1.12 | DN |
directoryString | 1.3.6.1.4.1.1466.115.121.1.15 | UTF-8 string |
IA5String | 1.3.6.1.4.1.1466.115.121.1.26 | ASCII string |
Integer | 1.3.6.1.4.1.1466.115.121.1.27 | integer |
Name and Optional UID | 1.3.6.1.4.1.1466.115.121.1.34 | DN plus UID |
Numeric String | 1.3.6.1.4.1.1466.115.121.1.36 | numeric string |
OID | 1.3.6.1.4.1.1466.115.121.1.38 | object identifier |
Octet String | 1.3.6.1.4.1.1466.115.121.1.40 | arbitary octets |
Printable String | 1.3.6.1.4.1.1466.115.121.1.44 | printable string |
Matching Rules
是用来指定某属性的匹配规则,实际上就是定义一个特殊的Syntax的别名,让LDAP服务器可以识别,并对定义的属性进行匹配。
Commonly Used Matching Rules | ||
Name | Type | Description |
booleanMatch | equality | boolean |
octetStringMatch | equality | octet string |
objectIdentiferMatch | equality | OID |
distinguishedNameMatch | equality | DN |
uniqueMemberMatch | equality | Name with optional UID |
numericStringMatch | equality | numerical |
numericStringOrderingMatch | ordering | numerical |
numericStringSubstringsMatch | substrings | numerical |
caseIgnoreMatch | equality | case insensitive, space insensitive |
caseIgnoreOrderingMatch | ordering | case insensitive, space insensitive |
caseIgnoreSubstringsMatch | substrings | case insensitive, space insensitive |
caseExactMatch | equality | case sensitive, space insensitive |
caseExactOrderingMatch | ordering | case sensitive, space insensitive |
caseExactSubstringsMatch | substrings | case sensitive, space insensitive |
caseIgnoreIA5Match | equality | case insensitive, space insensitive |
caseIgnoreIA5OrderingMatch | ordering | case insensitive, space insensitive |
caseIgnoreIA5SubstringsMatch | substrings | case insensitive, space insensitive |
caseExactIA5Match | equality | case sensitive, space insensitive |
caseExactIA5OrderingMatch | ordering | case sensitive, space insensitive |
caseExactIA5SubstringsMatch | substrings | case sensitive, space insensitive |
例子:
package com.mayocase.domain;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import javax.naming.Name;
import org.springframework.ldap.odm.annotations.Attribute;
import org.springframework.ldap.odm.annotations.Entry;
import org.springframework.ldap.odm.annotations.Id;
/**
* Automatically generated to represent the LDAP object classes
* "organizationalunit", "top".
*/
@Entry(objectClasses = { "organizationalUnit", "top" })
public final class OrganizationalUnit {
@Id
private Name dn;
@Attribute(name = "objectClass", syntax = "1.3.6.1.4.1.1466.115.121.1.38")
private List<String> objectClass = new ArrayList<String>();
@Attribute(name = "ou", syntax = "1.3.6.1.4.1.1466.115.121.1.15")
private String ou;
@Attribute(name = "street", syntax = "1.3.6.1.4.1.1466.115.121.1.15")
private String street;
@Attribute(name = "description", syntax = "1.3.6.1.4.1.1466.115.121.1.15")
private String description;
public OrganizationalUnit() {
}
public OrganizationalUnit(Name dn, String street, String description) {
this.dn = dn;
this.street = street;
this.description = description;
objectClass.add("top");
objectClass.add("organizationalUnit");
int size = dn.size();
if (size > 1) {
ou = dn.get(size - 1).split("=")[1];
} else {
ou = "";
}
}
public Name getDn() {
return dn;
}
public void setDn(Name dn) {
this.dn = dn;
}
public List<String> getObjectClasses() {
return Collections.unmodifiableList(objectClass);
}
public String getOu() {
return ou;
}
public String getStreet() {
return street;
}
public void setStreet(String st) {
street = st;
}
public String getDescription() {
return description;
}
@Override
public String toString() {
return String.format("objectClasses=%1$s | dn=%2$s | ou=%3$s | street=%4$s | description=%5$s", objectClass,
dn, ou, street, description);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((dn == null) ? 0 : dn.hashCode());
result = prime * result + ((objectClass == null) ? 0 : new HashSet<String>(objectClass).hashCode());
result = prime * result + ((ou == null) ? 0 : ou.hashCode());
result = prime * result + ((street == null) ? 0 : street.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
OrganizationalUnit other = (OrganizationalUnit) obj;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (dn == null) {
if (other.dn != null)
return false;
} else if (!dn.equals(other.dn))
return false;
if (objectClass == null) {
if (other.objectClass != null)
return false;
} else
if (objectClass.size()!=other.objectClass.size() ||
!(new HashSet<String>(objectClass)).equals(new HashSet<String>(other.objectClass)))
return false;
if (ou == null) {
if (other.ou != null)
return false;
} else if (!ou.equals(other.ou))
return false;
if (street == null) {
if (other.street != null)
return false;
} else if (!street.equals(other.street))
return false;
return true;
}
}