﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-liuzheng-文章分类-Ldap</title><link>http://www.blogjava.net/liuzheng/category/39218.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 24 Apr 2009 14:59:35 GMT</lastBuildDate><pubDate>Fri, 24 Apr 2009 14:59:35 GMT</pubDate><ttl>60</ttl><item><title>Spring-LDAP 的例子</title><link>http://www.blogjava.net/liuzheng/articles/267355.html</link><dc:creator>刘铮 </dc:creator><author>刘铮 </author><pubDate>Fri, 24 Apr 2009 06:31:00 GMT</pubDate><guid>http://www.blogjava.net/liuzheng/articles/267355.html</guid><wfw:comment>http://www.blogjava.net/liuzheng/comments/267355.html</wfw:comment><comments>http://www.blogjava.net/liuzheng/articles/267355.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/liuzheng/comments/commentRss/267355.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/liuzheng/services/trackbacks/267355.html</trackback:ping><description><![CDATA[<h3 title=""><a href="http://wangyaodi.javaeye.com/blog/202514">Spring-LDAP</a></h3>
<p>下载地址 ：<a href="http://www.springframework.org/ldap">http://www.springframework.org/ldap</a></p>
<p>用Spring LDAP最小需要：</p>
<ul>
    <li>spring-ldap（spring－ldap包） </li>
    <li>spring－core（用于框架内部的丰富的工具类） </li>
    <li>spring－beans（方便操作java beans的接口和类） </li>
    <li>spring－context（增加通过一致API为应用对象获取资源的能力） </li>
    <li>spring－dao（使经常性的错误处理跟使用中的数据访问分开的异常处理机制） </li>
    <li>commons－logging（简单的日志处理，内部使用） </li>
</ul>
<p>UserDaoLdapImpl</p>
<div>
<div>
<div>Java代码 <embed src="http://wangyaodi.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=package%20cn.com.ldap%3B%0A%0Aimport%20java.util.List%3B%0A%0Aimport%20javax.naming.NamingException%3B%0Aimport%20javax.naming.directory.Attributes%3B%0A%0Aimport%20org.springframework.ldap.core.AttributesMapper%3B%0Aimport%20org.springframework.ldap.core.LdapTemplate%3B%0A%0Aimport%20cn.com.ldap.Preson.Person%3B%0A%0A%2F**%0A%20*%20%40author%20Wangyaodi%20version%201.0%202008-6-12%20%7C%20%E4%B8%8B%E5%8D%8802%3A55%3A25%0A%20*%2F%0Apublic%20class%20UserDaoLdapImpl%20%7B%0A%09private%20LdapTemplate%20ldapTemplate%3B%0A%0A%09public%20void%20setLdapTemplate(LdapTemplate%20ldapTemplate)%20%7B%0A%09%09this.ldapTemplate%20%3D%20ldapTemplate%3B%0A%09%7D%0A%0A%09public%20List%20getAllPersonNames()%20%7B%0A%09%09return%20ldapTemplate.search(%22%22%2C%20%22(objectclass%3Dperson)%22%2C%0A%09%09%09%09new%20AttributesMapper()%20%7B%0A%09%09%09%09%09public%20Object%20mapFromAttributes(Attributes%20attrs)%0A%09%09%09%09%09%09%09throws%20NamingException%20%7B%0A%09%09%09%09%09%09return%20attrs.get(%22cn%22).get()%3B%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D)%3B%0A%09%7D%0A%0A%7D" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="14" height="15"></div>
</div>
<ol start="1">
    <li>package&nbsp;cn.com.ldap;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;</li>
    <li>import&nbsp;java.util.List;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;</li>
    <li>import&nbsp;javax.naming.NamingException;&nbsp;&nbsp;</li>
    <li>import&nbsp;javax.naming.directory.Attributes;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;</li>
    <li>import&nbsp;org.springframework.ldap.core.AttributesMapper;&nbsp;&nbsp;</li>
    <li>import&nbsp;org.springframework.ldap.core.LdapTemplate;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;</li>
    <li>import&nbsp;cn.com.ldap.Preson.Person;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;</li>
    <li>/**&nbsp;</li>
    <li>&nbsp;*&nbsp;@author&nbsp;Wangyaodi&nbsp;version&nbsp;1.0&nbsp;2008-6-12&nbsp;|&nbsp;下午02:55:25&nbsp;</li>
    <li>&nbsp;*/&nbsp;&nbsp;</li>
    <li>public&nbsp;class&nbsp;UserDaoLdapImpl&nbsp;{&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;LdapTemplate&nbsp;ldapTemplate;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;setLdapTemplate(LdapTemplate&nbsp;ldapTemplate)&nbsp;{&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.ldapTemplate&nbsp;=&nbsp;ldapTemplate;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;List&nbsp;getAllPersonNames()&nbsp;{&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;ldapTemplate.search("",&nbsp;"(objectclass=person)",&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new&nbsp;AttributesMapper()&nbsp;{&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;Object&nbsp;mapFromAttributes(Attributes&nbsp;attrs)&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throws&nbsp;NamingException&nbsp;{&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;attrs.get("cn").get();&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;</li>
    <li>}&nbsp;&nbsp;</li>
</ol>
</div>
<pre style="display: none;" name="code" class="java">package cn.com.ldap;
import java.util.List;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import org.springframework.ldap.core.AttributesMapper;
import org.springframework.ldap.core.LdapTemplate;
import cn.com.ldap.Preson.Person;
/**
* @author Wangyaodi version 1.0 2008-6-12 | 下午02:55:25
*/
public class UserDaoLdapImpl {
private LdapTemplate ldapTemplate;
public void setLdapTemplate(LdapTemplate ldapTemplate) {
this.ldapTemplate = ldapTemplate;
}
public List getAllPersonNames() {
return ldapTemplate.search("", "(objectclass=person)",
new AttributesMapper() {
public Object mapFromAttributes(Attributes attrs)
throws NamingException {
return attrs.get("cn").get();
}
});
}
}</pre>
<p>preson:</p>
<div>
<div>
<div>Java代码 <embed src="http://wangyaodi.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=package%20cn.com.ldap%3B%0A%0Apublic%20class%20Preson%20%7B%0A%09public%20class%20Person%20%7B%0A%0A%09%09private%20String%20cn%3B%0A%0A%09%09private%20String%20sn%3B%0A%0A%09%09public%20String%20getCn()%20%7B%0A%09%09%09return%20cn%3B%0A%09%09%7D%0A%0A%09%09public%20void%20setCn(String%20cn)%20%7B%0A%09%09%09this.cn%20%3D%20cn%3B%0A%09%09%7D%0A%0A%09%09public%20String%20getSn()%20%7B%0A%09%09%09return%20sn%3B%0A%09%09%7D%0A%0A%09%09public%20void%20setSn(String%20sn)%20%7B%0A%09%09%09this.sn%20%3D%20sn%3B%0A%09%09%7D%0A%0A%09%7D%0A%0A%7D%0A" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="14" height="15"></div>
</div>
<ol start="1">
    <li>package&nbsp;cn.com.ldap;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;</li>
    <li>public&nbsp;class&nbsp;Preson&nbsp;{&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;class&nbsp;Person&nbsp;{&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;String&nbsp;cn;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;String&nbsp;sn;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;String&nbsp;getCn()&nbsp;{&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;cn;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;setCn(String&nbsp;cn)&nbsp;{&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.cn&nbsp;=&nbsp;cn;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;String&nbsp;getSn()&nbsp;{&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;sn;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;setSn(String&nbsp;sn)&nbsp;{&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.sn&nbsp;=&nbsp;sn;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;</li>
    <li>}&nbsp;&nbsp;</li>
</ol>
</div>
<pre style="display: none;" name="code" class="java">package cn.com.ldap;
public class Preson {
public class Person {
private String cn;
private String sn;
public String getCn() {
return cn;
}
public void setCn(String cn) {
this.cn = cn;
}
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
}
}
</pre>
<p>applicationContext.xml</p>
<div>
<div>
<div>Xml代码 <embed src="http://wangyaodi.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%0A%3C!DOCTYPE%20beans%20PUBLIC%20%22-%2F%2FSPRING%2F%2FDTD%20BEAN%2F%2FEN%22%20%22http%3A%2F%2Fwww.springframework.org%2Fdtd%2Fspring-beans.dtd%22%3E%0A%3Cbeans%3E%0A%09%3Cbean%20id%3D%22contextSource%22%0A%09%09class%3D%22org.springframework.ldap.core.support.LdapContextSource%22%3E%0A%09%09%3Cproperty%20name%3D%22url%22%20value%3D%22ldap%3A%2F%2F192.168.16.XXX%3A389%22%20%2F%3E%0A%09%09%3Cproperty%20name%3D%22base%22%20value%3D%22OU%3DXXX%2COU%3DXXX%2COU%3DXXX%2COU%3DXXX%2CDC%3DXXX%2CDC%3DXXX%2CDC%3DXXX%22%20%2F%3E%0A%09%09%3Cproperty%20name%3D%22userName%22%20value%3D%22XXX%40headquarter%22%20%2F%3E%0A%09%09%3Cproperty%20name%3D%22password%22%20value%3D%22XXX%22%20%2F%3E%0A%09%3C%2Fbean%3E%0A%0A%09%3Cbean%20id%3D%22ldapTemplate%22%0A%09%09class%3D%22org.springframework.ldap.core.LdapTemplate%22%3E%0A%09%09%3Cconstructor-arg%20ref%3D%22contextSource%22%20%2F%3E%0A%09%3C%2Fbean%3E%0A%0A%09%3Cbean%20id%3D%22userDao%22%20class%3D%22cn.com.ldap.UserDaoLdapImpl%22%3E%0A%09%09%3Cproperty%20name%3D%22ldapTemplate%22%3E%0A%09%09%09%3Cref%20bean%3D%22ldapTemplate%22%20%2F%3E%0A%09%09%3C%2Fproperty%3E%0A%09%3C%2Fbean%3E%0A%3C%2Fbeans%3E" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="14" height="15"></div>
</div>
<ol start="1">
    <li>&lt;?xml&nbsp;version="1.0"&nbsp;encoding="UTF-8"?&gt;&nbsp;&nbsp;</li>
    <li>&lt;!DOCTYPE&nbsp;beans&nbsp;PUBLIC&nbsp;"-//SPRING//DTD&nbsp;BEAN//EN"&nbsp;"http://www.springframework.org/dtd/spring-beans.dtd"&gt;&nbsp;&nbsp;</li>
    <li>&lt;beans&gt;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&lt;bean&nbsp;id="contextSource"&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;class="org.springframework.ldap.core.support.LdapContextSource"&gt;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;property&nbsp;name="url"&nbsp;value="ldap://192.168.16.XXX:389"&nbsp;/&gt;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;property&nbsp;name="base"&nbsp;value="OU=XXX,OU=XXX,OU=XXX,OU=XXX,DC=XXX,DC=XXX,DC=XXX"&nbsp;/&gt;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;property&nbsp;name="userName"&nbsp;value="XXX@headquarter"&nbsp;/&gt;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;property&nbsp;name="password"&nbsp;value="XXX"&nbsp;/&gt;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/bean&gt;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&lt;bean&nbsp;id="ldapTemplate"&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;class="org.springframework.ldap.core.LdapTemplate"&gt;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;constructor-arg&nbsp;ref="contextSource"&nbsp;/&gt;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/bean&gt;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&lt;bean&nbsp;id="userDao"&nbsp;class="cn.com.ldap.UserDaoLdapImpl"&gt;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;property&nbsp;name="ldapTemplate"&gt;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ref&nbsp;bean="ldapTemplate"&nbsp;/&gt;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/property&gt;&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/bean&gt;&nbsp;&nbsp;</li>
    <li>&lt;/beans&gt;&nbsp;&nbsp;</li>
</ol>
</div>
<pre style="display: none;" name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"&gt;
&lt;beans&gt;
&lt;bean id="contextSource"
class="org.springframework.ldap.core.support.LdapContextSource"&gt;
&lt;property name="url" value="ldap://192.168.16.XXX:389" /&gt;
&lt;property name="base" value="OU=XXX,OU=XXX,OU=XXX,OU=XXX,DC=XXX,DC=XXX,DC=XXX" /&gt;
&lt;property name="userName" value="XXX@headquarter" /&gt;
&lt;property name="password" value="XXX" /&gt;
&lt;/bean&gt;
&lt;bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate"&gt;
&lt;constructor-arg ref="contextSource" /&gt;
&lt;/bean&gt;
&lt;bean id="userDao" class="cn.com.ldap.UserDaoLdapImpl"&gt;
&lt;property name="ldapTemplate"&gt;
&lt;ref bean="ldapTemplate" /&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;/beans&gt;</pre>
<p>main&nbsp;</p>
<div>
<div>
<div>Java代码 <embed src="http://wangyaodi.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=public%20static%20void%20main(String%5B%5D%20args)%20%7B%0A%09%09ApplicationContext%20cxt%20%3D%20new%20ClassPathXmlApplicationContext(%22applicationContext.xml%22)%3B%0A%09%09UserDaoLdapImpl%20userDao%20%3D%20(UserDaoLdapImpl)cxt.getBean(%22userDao%22)%3B%0A%09%09List%20users%20%3D%20userDao.getAllPersonNames()%3B%0A%09%09System.out.println(users.size())%3B%0A%09%7D" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="14" height="15"></div>
</div>
<ol start="1">
    <li>public&nbsp;static&nbsp;void&nbsp;main(String[]&nbsp;args)&nbsp;{&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ApplicationContext&nbsp;cxt&nbsp;=&nbsp;new&nbsp;ClassPathXmlApplicationContext("applicationContext.xml");&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UserDaoLdapImpl&nbsp;userDao&nbsp;=&nbsp;(UserDaoLdapImpl)cxt.getBean("userDao");&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List&nbsp;users&nbsp;=&nbsp;userDao.getAllPersonNames();&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(users.size());&nbsp;&nbsp;</li>
    <li>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp; <br />
    </li>
</ol>
</div>
<img src ="http://www.blogjava.net/liuzheng/aggbug/267355.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/liuzheng/" target="_blank">刘铮 </a> 2009-04-24 14:31 <a href="http://www.blogjava.net/liuzheng/articles/267355.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>经典的Ldap的组织图</title><link>http://www.blogjava.net/liuzheng/articles/267327.html</link><dc:creator>刘铮 </dc:creator><author>刘铮 </author><pubDate>Fri, 24 Apr 2009 03:49:00 GMT</pubDate><guid>http://www.blogjava.net/liuzheng/articles/267327.html</guid><wfw:comment>http://www.blogjava.net/liuzheng/comments/267327.html</wfw:comment><comments>http://www.blogjava.net/liuzheng/articles/267327.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/liuzheng/comments/commentRss/267327.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/liuzheng/services/trackbacks/267327.html</trackback:ping><description><![CDATA[<p>Data must be structured for LDAP. Our internet-domain is zirndorf.de, so
I use that. Under that there is a unit in which all the people are.</p>
<p><img src="http://lena.franken.de/ldap/simple_structure.gif" alt="simple_structure.gif" width="715" border="0" height="1025" /></p>
<img src ="http://www.blogjava.net/liuzheng/aggbug/267327.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/liuzheng/" target="_blank">刘铮 </a> 2009-04-24 11:49 <a href="http://www.blogjava.net/liuzheng/articles/267327.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ldap 很好的学习网站</title><link>http://www.blogjava.net/liuzheng/articles/267317.html</link><dc:creator>刘铮 </dc:creator><author>刘铮 </author><pubDate>Fri, 24 Apr 2009 03:08:00 GMT</pubDate><guid>http://www.blogjava.net/liuzheng/articles/267317.html</guid><wfw:comment>http://www.blogjava.net/liuzheng/comments/267317.html</wfw:comment><comments>http://www.blogjava.net/liuzheng/articles/267317.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/liuzheng/comments/commentRss/267317.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/liuzheng/services/trackbacks/267317.html</trackback:ping><description><![CDATA[http://www.zytrax.com/books/ldap/
<img src ="http://www.blogjava.net/liuzheng/aggbug/267317.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/liuzheng/" target="_blank">刘铮 </a> 2009-04-24 11:08 <a href="http://www.blogjava.net/liuzheng/articles/267317.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ldap schema 自定义</title><link>http://www.blogjava.net/liuzheng/articles/267316.html</link><dc:creator>刘铮 </dc:creator><author>刘铮 </author><pubDate>Fri, 24 Apr 2009 03:07:00 GMT</pubDate><guid>http://www.blogjava.net/liuzheng/articles/267316.html</guid><wfw:comment>http://www.blogjava.net/liuzheng/comments/267316.html</wfw:comment><comments>http://www.blogjava.net/liuzheng/articles/267316.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/liuzheng/comments/commentRss/267316.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/liuzheng/services/trackbacks/267316.html</trackback:ping><description><![CDATA[<p>An <strong>LDAP schema</strong> is nothing more than a convenient packaging unit for containing broadly similar <a title="" href="http://www.zytrax.com/books/ldap/apd/index.html#objectclasses" class="t-db">objectClasses</a> and <a title="" href="http://www.zytrax.com/books/ldap/apd/index.html#attributes" class="t-db">attributes</a>.</p>
<p>There may have been a time when a single schema was designed to hold
everything required for an LDAP implementation (like a relational
database schema) but that is no longer true. You will find useful
attributes and objectclases scattered all over the place - the power of
LDAP arguably comes from the ease of creating and using this apparent
anarchy.</p>
<p>The rule is: Every attribute or objectclass (including its superior
objectclass or attribute) used in an LDAP implementation must be
defined in a <strong>schema</strong> and that schema must be <strong>known</strong> to the LDAP server. In OpenLDAP the schemas are made known using the <a href="http://www.zytrax.com/books/ldap/ch6/index.html#include" class="t-db">include</a> statement in the <a title="" href="http://www.zytrax.com/books/ldap/ch6" class="t-db">slapd.conf</a> configuration file).</p>
<p>The following diagram illustrates the use of schemas as packaging units:</p>
<p align="center"><img title="" src="http://www.zytrax.com/books/ldap/images/ldap-schemas-packaging.gif" alt="LDAP - Schema, objectClasses and Attributes" border="0" />
</p>
<p><a href="http://www.zytrax.com/books/ldap/ch3/#contents"><img src="http://www.zytrax.com/images/go_up.gif" alt="Up Arrow" border="0" /></a></p>
<h2>3.3 LDAP objectClasses</h2>
<p>An <strong>objectClass</strong> is a collection of attributes (or an attribute container) and has the following characteristics:</p>
<ol>
    <li>
    <p>An <strong>objectclass</strong> is defined within a <strong>Schema</strong></p>
    </li>
    <li>
    <p>An <strong>objectclass</strong> may be a part of an objectclass hierarchy in which case it inherits all the properties of its parents, for example, <a title="" href="http://www.zytrax.com/books/ldap/ape/inetorgperson.html#inetorgperson" class="t-db">inetOrgPerson</a> is the child of <a title="" href="http://www.zytrax.com/books/ldap/ape/core-schema.html#organizationalperson" class="t-db">organizationalPerson</a> which is the child of <a title="" href="http://www.zytrax.com/books/ldap/ape/core-schema.html#person" class="t-db">person</a> which is the child of <strong>top</strong> (the ABSTRACT objectClass which terminates every objectClass hirearchy).</p>
    </li>
    <li>
    <p>An <strong>objectclass</strong> has a globally unique name or identifier</p>
    </li>
    <li>
    <p>An <strong>objectclass</strong>, as well as being an attribute container, is also an attribute and may be searched on</p>
    </li>
    <li>
    <p>An <strong>objectclass</strong> defines its member attributes and whether these MUST (mandatory) be present or MAY (optional) be present in an entry.</p>
    </li>
    <li>
    <p>One or more <strong>objectclass(es)</strong> must be present in an LDAP <a href="http://www.zytrax.com/books/ldap/apd/index.html#entry" class="t-db">entry</a>.</p>
    </li>
    <li>
    <p>Each <strong>objectclass</strong> supported by a LDAP server forms part of a <strong>collection</strong> called <strong>objectclasses</strong> which can be discovered via the <a title="" href="http://www.zytrax.com/books/ldap/ch3/#operational" class="t-db"><strong>subschema</strong></a>.</p>
    </li>
</ol>
<h3>Defining an objectClass</h3>
<p>The formal objectclass definition is defined in <a href="http://www.zytrax.com/books/ldap/apc/rfc2252.txt" class="t-db">RFC 2252 section 4.4</a> and looks like this:</p>
<pre>ObjectClassDescription = "(" whsp<br />
numericoid whsp      ; ObjectClass identifier<br />
[ "NAME" qdescrs ]<br />
[ "DESC" qdstring ]<br />
[ "OBSOLETE" whsp ]<br />
[ "SUP" oids ]       ; Superior ObjectClasses<br />
[ ( "ABSTRACT" / "STRUCTURAL" / "AUXILIARY" ) whsp ]<br />
; default structural<br />
[ "MUST" oids ]      ; AttributeTypes<br />
[ "MAY" oids ]       ; AttributeTypes<br />
whsp ")"<br />
</pre>
<p>Ooof! <strong>whsp</strong> means a space character and when they say it
should be there believe them. Rather than try and explain all these
entries lets start with some examples.</p>
<p>An <strong>objectClass</strong> is defined using <a title="" href="http://www.zytrax.com/books/ldap/apd/index.html#asn1" class="t-db">ASN.1</a> notation - the following is a simple standard objectclass definition for <a title="" href="http://www.zytrax.com/books/ldap/ape/core-schema.html#country" class="t-db">country</a> taken from the <a title="" href="http://www.zytrax.com/books/ldap/ape/core-schema.html" class="t-db">core.schema</a> supplied with OpenLDAP distributions.</p>
<pre>objectclass ( 2.5.6.2 NAME 'country' SUP top STRUCTURAL<br />
MUST c<br />
MAY ( searchGuide $ description ) )<br />
</pre>
<p>Now lets deconstruct this definition:</p>
<p><strong>objectclass</strong> is a keyword indicating this is an objectclass definition - see it's not so complicated!</p>
<p><strong>2.5.6.2 NAME 'country'</strong> defines a <strong>globally unique</strong> name for this objectclass and is comprised of two parts: <strong>NAME 'country'</strong> just allows you to refer to this objectclass by some semi-understandable text - in this case the english word <strong>country</strong>. The <strong>globally unique</strong> part is defined by <strong>2.5.6.2</strong> which is called an <a title="" href="http://www.zytrax.com/books/ldap/apa/oid.html" class="t-db">OID (ObjectIdentifier)</a>.
The OID 2.5.6.2 was probably the third objectclass ever defined by
X.500 (2.5.6 is the joint itu-iso x.500 object classes, the last 2 is a
sequence number within that family of OIDs). It does not matter what
organization assigns this number but it must be UNIQUE. Obtaining an
enterprise OID that allows you to define your own <strong>attributes</strong> and <strong>objectclasses</strong> is a trivial and zero cost process via <a href="http://pen.iana.org/pen/PenApplication.page" class="t-db">IANA</a>. It is a VERY BAD THING&#8482; to re-use existing OIDs.</p>
<p><strong>SUP 'top'</strong> indicates that this objectclass has a PARENT (or
SUPerior) objectclass - it is part of a hierarchy. In this case the
parent is <strong>top</strong> which is a special class that terminates (is the
highest level) in all objectclasses. An objectclass may have one or
more objectclass(es) as Parents.</p>
<p><strong>STRUCTURAL</strong> indicates that this objectclass contains data and can form an <a href="http://www.zytrax.com/books/ldap/apd/index.html#entry" class="t-db">entry</a> in a DIT. <strong>objectClasses</strong> may also be ABSTRACT which indicates a non-existent objectclass used for convenience. The most common ABSTRACT objectclass is <strong>top</strong> which just terminates an objectclass hierarchy. Finally an <strong>objectClass</strong>
may be AUXILIARY which indicates it may be used with any STRUCTURAL
objectclass to form an entry but cannot alone form an entry in a DIT.</p>
<p><strong>DESC 'description'</strong> OK so we picked a lousy example which does
not have a DESC part - but it was short. DESC is an optional value that
provides a short text description of the use or contents of the
objectclass. It's meant for human beings to read and has no other use.
Here is what <strong>country</strong> <u>could</u> have looked like with a DESC statement included:</p>
<pre>objectclass ( 2.5.6.2 NAME 'country' SUP top STRUCTURAL<br />
DESC '2 character iso assigned country code'<br />
MUST c<br />
MAY ( searchGuide $ description ) )<br />
</pre>
<p><strong>MUST c</strong> MUST indicates that the attributes in the following list are mandatory in this case the attribute <strong>c</strong>
has to be present or the entry will fail to load. Single values are
written as shown, multiple attributes are enclosed in parentheses and
separated with a $ (dollar) sign, such as ( attr1 $ attr2 $ attrn). If
there are no mandatory attributes this section is not included.</p>
<p><strong>MAY ( searchGuide $ description )</strong> MAY indicates that the
attributes in the following list are optional. Multiple values are
written as shown, single attributes do not need the parentheses (see
above). If there are no optional attributes this section is not
included.</p>
<h3>Some more objectClasses</h3>
<p>This is how the <strong>top</strong> objectclass is defined:</p>
<pre>objectclass ( 2.5.6.0 NAME 'top' ABSTRACT<br />
MUST objectClass )<br />
</pre>
<p>Illustrates the use of the ABSTRACT statement in an objectclass. Since <strong>top</strong> is always the top of a hierarchy - clearly it cannot have a <strong>SUP</strong> statement. The OID is also assigned by the X.500 standards group.</p>
<p>Many documents insist that the objectclass <strong>top</strong> is included in <a href="http://www.zytrax.com/books/ldap/apd/index.html#ldif" class="t-db">LDIF</a> files - <a href="http://www.zytrax.com/books/ldap/apa/ldif-objects.html" class="t-db">it is not always necessary</a>.</p>
<p>This is how the <strong>dcObject</strong> objectclass is defined:</p>
<pre>objectclass ( 1.3.6.1.4.1.1466.344 NAME 'dcObject'<br />
DESC 'RFC2247: domain component object'<br />
SUP top AUXILIARY MUST dc )<br />
</pre>
<p>Illustrates the use of the AUXILLIARY statement. An AUXILLIARY
cannot on its own create an entry. The OID in this example shows the
use of a <a title="" href="http://www.zytrax.com/books/ldap/apa/oid.html" class="t-db">private enterprise OID (ObjectIdentifier)</a>. The following fragment shows a fairly typical base DN definition using <strong>dcObject</strong>:</p>
<pre>dn: dc=example,dc=com<br />
dc: example.com<br />
objectclass: dcObject<br />
objectclass: organization<br />
o: Example, Inc.<br />
</pre>
<p>It is the <strong>objectclass: organization</strong> that creates the entry. <strong>dcObject</strong> piggy-backs on this objectclass.</p>
<p>This is how the <strong>pilotOrganization</strong> objectclass is defined and
illustrates that there may be one or more SUPerior (Parent)
objectclasses in which the child inherits the properties of ALL its
parents (bit like humans really):</p>
<pre>objectClasses: ( 0.9.2342.19200300.100.4.20 NAME 'pilotOrganization'<br />
SUP ( organization $ organizationalUnit ) STRUCTURAL<br />
MAY buildingName )<br />
</pre>
<p>We have omitted explaining a couple of values (well one actually) -
OBSOLETE if it is present it means the objectclass should not be used
(duh).</p>
<h2>LDAP Attributes</h2>
<p>Attributes typically contain data and have the following characteristics:</p>
<ol>
    <li>
    <p>Every <strong>attribute</strong> is included in one or more <strong>objectclass</strong>.</p>
    </li>
    <li>
    <p>An <strong>objectclass</strong> is also an <strong>attribute</strong> and can be used in searches.</p>
    </li>
    <li>
    <p>To use an <strong>attribute</strong> in an <a title="" href="http://www.zytrax.com/books/ldap/apd/index.html#entry" class="t-db">entry</a> its <strong>objectclass</strong> must be included in the entry definition and its <strong>objectclass</strong> must be included in a <strong>schema</strong> which must be identified to the LDAP server.</p>
    </li>
    <li>
    <p>An <strong>attribute</strong>'s characteristics are defined using <a title="" href="http://www.zytrax.com/books/ldap/apd/index.html#asn1" class="t-db">ASN.1</a> notation.</p>
    </li>
    <li>
    <p>An <strong>attribute</strong> can appear once in any instance of its containing <strong>ObjectClass</strong> (SINGLE-VALUE) or can apear more than once in any instance of its containing <strong>ObjectClass</strong> (MULTI-VALUE). MULTI-VALUE is default.</p>
    </li>
    <li>
    <p>An <strong>attribute</strong> definition may be part of a hierarchy in
    which case it inherits all the properties of its parents, for example,
    commonName (cn), givenName (gn), surname (sn) are all children of the <strong>name</strong> attribute.</p>
    </li>
    <li>
    <p>An <strong>attribute</strong> definition includes its type, for instance
    string, number etc., how it behaves in certain conditions, for example
    are compares case sensitive or case-insensitive and other
    characteristics (properties).</p>
    </li>
    <li>
    <p>An <strong>attribute</strong> supported by a LDAP server forms part of a <strong>collection</strong> called <strong>attributetypes</strong> which can be interrogated via the <a title="" href="http://www.zytrax.com/books/ldap/ch3/#operational" class="t-db">subschema</a>.</p>
    </li>
</ol>
<h3>Defining an Attribute</h3>
<p>The formal attribute definition is defined in <a href="http://www.zytrax.com/books/ldap/apc/rfc2252.txt" class="t-db">RFC 2252 section 4.2</a> and looks like this:</p>
<pre>AttributeTypeDescription = "(" whsp<br />
numericoid whsp     ; AttributeType identifier<br />
[ "NAME" qdescrs ]             ; name used in AttributeType<br />
[ "DESC" qdstring ]            ; description<br />
[ "OBSOLETE" whsp ]<br />
[ "SUP" woid ]                 ; derived from this other<br />
; AttributeType<br />
[ "EQUALITY" woid              ; Matching Rule name<br />
[ "ORDERING" woid              ; Matching Rule name<br />
[ "SUBSTR" woid ]              ; Matching Rule name<br />
[ "SYNTAX" whsp noidlen whsp ] ; Syntax OID<br />
[ "SINGLE-VALUE" whsp ]        ; default multi-valued<br />
[ "COLLECTIVE" whsp ]          ; default not collective<br />
[ "NO-USER-MODIFICATION" whsp ]; default user modifiable<br />
[ "USAGE" whsp AttributeUsage ]; default userApplications<br />
whsp ")"<br />
</pre>
<p>Ouch! <strong>whsp</strong> means a space character and must be present. Rather than explain each bit of gobbledegook lets again start with some examples.</p>
<p>An <strong>attribute</strong> is defined using <a title="" href="http://www.zytrax.com/books/ldap/apd/index.html#asn1" class="t-db">ASN.1</a> notation - the following is a simple standard attribute definition for <a title="" href="http://www.zytrax.com/books/ldap/ape/core-schema.html#commonname" class="t-db">commonName (cn)</a> taken from the <a title="" href="http://www.zytrax.com/books/ldap/ape/core-schema.html" class="t-db">core.schema</a> supplied with OpenLDAP distributions.</p>
<pre>attributetype ( 2.5.4.3 NAME ( 'cn' 'commonName' ) SUP name )<br />
</pre>
<p>Now lets deconstruct this definition:</p>
<p><strong>attributetype</strong> indicates this defines an attribute - wow.</p>
<p><strong>2.5.4.3 NAME ('cn' 'commonName')</strong> defines a <strong>globally unique</strong> name for this attribute and is comprised of two parts: <strong>NAME ('cn' 'commonName'</strong> just allows you to refer to this attribute by some semi-understandable text - in this case either the english word <strong>commonName</strong> OR the shortform (or alias) <strong>cn</strong>
in principle there are no limits to the number of definitions or
aliases you can have as long as they are unique. In this multiple entry
form the names are enclosed in parentheses and space separated. Since <strong>cn</strong> appears first it is called the <a href="http://www.zytrax.com/books/ldap/apd/index.html#primary" class="t-db">primary</a> name which is very important when it comes to <a href="http://www.zytrax.com/books/ldap/apa/indeces.html" class="t-db">indexing</a> entries.</p>
<p>The <strong>globally unique</strong> part is defined by <strong>2.5.4.3</strong> which is called an <a title="" href="http://www.zytrax.com/books/ldap/apa/oid.html" class="t-db">OID (ObjectIdentifier)</a>.
The OID 2.5.4.3 was possibly the fourth attribute ever defined by X.500
(2.5.4 is the joint itu-iso x.500 attribute types, the last 3 is a
sequence number within that family of OIDs). It does not matter what
organization assigns this number but it must be UNIQUE. Obtaining an
enterprise OID that allows you to define your own <strong>attributes</strong> and <strong>objectclasses</strong> is a trivial process via <a href="http://pen.iana.org/pen/PenApplication.page" class="t-db">IANA</a>. It is a VERY BAD THING&#8482; to re-use existing OIDs.</p>
<p><strong>SUP 'name'</strong> indicates that this attribute has a PARENT (or SUPerior) attribute - it is part of a hierarchy. In this case the parent is <strong>name</strong>
which we will now look at in detail since, if you recall, the child
always inherits the properties of the parent (or SUPerior) attribute
(and itself may have additional properties). The SUP entry can use
either a 'name' or an OID. The definition SUP 'top' and SUP 2.5.4.41
mean exactly the same - except to the poor reader!</p>
<p>This is the attribute definition of <a title="" href="http://www.zytrax.com/books/ldap/ape/core-schema.html#name" class="t-db">name</a> which is a much more serious definition and the SUPerior (parent) attribute of <strong>cn</strong> above:</p>
<pre>attributetype ( 2.5.4.41 NAME 'name'<br />
EQUALITY caseIgnoreMatch<br />
SUBSTR caseIgnoreSubstringsMatch<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )<br />
</pre>
<p>Now for some more serious deconstruction:</p>
<p><strong>attributetype</strong> indicates this defines an attribute - same as before.</p>
<p><strong>2.5.4.41 NAME 'name'</strong> defines the <strong>globally unique</strong> name for this attribute and as before is comprised of two parts: <strong>NAME 'name'</strong> just allows reference to this attribute by some semi-understandable text and the OID <strong>2.5.4.41</strong>
indicates it was defined by the X.500 standards group. The format used,
because there is only a single name value, does not need enclosing
parentheses as in the <strong>commonName</strong> example above.</p>
<p><strong>EQUALITY caseIgnoreMatch</strong> indicates how this (and any child attributes) will behave when used in a <a href="http://www.zytrax.com/books/ldap/apa/search.html" class="t-db">search filter</a> e.g. <strong>(cn=jimbob)</strong> (<strong>cn</strong> is a child of <strong>name</strong>) and no <strong>wildcards</strong> exist in the search. In this case it defines the match to be case-insensitive. <strong>caseIgnoreMatch</strong> is a <a href="http://www.zytrax.com/books/ldap/ch3/#matchingrules" class="t-db">matchingRule</a> and is defined in the <a href="http://www.zytrax.com/books/ldap/ch3/#operational" class="t-db">subschema</a>.</p>
<p><strong>SUBSTR caseIgnoreSubstringsMatch</strong> indicates how this (and any child attributes) will behave when used in a <a href="http://www.zytrax.com/books/ldap/apa/search.html" class="t-db">search filter</a> which uses a substring e.g. <strong>(cn=jim*)</strong> (<strong>cn</strong> is a child of <strong>name</strong>) and contains one or more <strong>wildcards</strong>. In this case it defines that the match is case-insensitive. <strong>caseIgnoreSubstringMatch</strong> is again a <a href="http://www.zytrax.com/books/ldap/ch3/#matchingrules" class="t-db">matchingRule</a> and is defined in the <a href="http://www.zytrax.com/books/ldap/ch3/#operational" class="t-db">subschema</a>.</p>
<p><strong>SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768}</strong> is an <a href="http://www.zytrax.com/books/ldap/apa/oid.html" class="t-db">OID</a> which defines the data type and what rules (data validation) are applied to the data. The full list is in <a href="http://www.zytrax.com/books/ldap/apc/rfc2252.txt" class="t-db">RFC 2252 section 4.3.2</a> and in this case the OID defines it to be a Directory String type which is defined in <a href="http://www.zytrax.com/books/ldap/apc/rfc2252.txt" class="t-db">RFC 2252 section 6.10</a> to be in the UTF-8 form of the ISO 10646 character set. The value <strong>{32768}</strong> indicates the maximum length of the string and is optional. <a href="http://www.zytrax.com/books/ldap/apa/types.html" class="t-db">Some more on LDAP Data Types</a></p>
<h2>Other Characteristics</h2>
<p><strong>SINGLE-VALUE</strong> <u>Omission</u> of this entry means that it is multi-valued i.e. it can appear more than once in an <strong>objectclass</strong> or an entry. If the attribute can only accept single values it must be explicitly defined as in the definition of <strong>dc</strong> below.</p>
<pre>attributetype ( 0.9.2342.19200300.100.1.25<br />
NAME ( 'dc' 'domainComponent' )<br />
DESC 'RFC1274/2247: domain component'<br />
EQUALITY caseIgnoreIA5Match<br />
SUBSTR caseIgnoreIA5SubstringsMatch<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 <br />
SINGLE-VALUE )<br />
</pre>
<p><strong>ORDERING 'matchingrule'</strong> is rarely defined and is used to
define the collation match - the lexicographic sorting order (allowing
searches of &lt;= and &gt;=).</p>
<pre>attributetype ( 2.5.4.46 NAME 'dnQualifier'<br />
EQUALITY caseIgnoreMatch<br />
ORDERING caseIgnoreOrderingMatch<br />
SUBSTR caseIgnoreSubstringsMatch<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.44 )<br />
</pre>
<p><a href="http://www.zytrax.com/books/ldap/ch3/#contents"><img src="http://www.zytrax.com/images/go_up.gif" alt="Up Arrow" border="0" /></a></p>
<h2>3.5 Matching Rules</h2>
<p>Matching rules are part of what is called the <a title="" href="http://www.zytrax.com/books/ldap/ch3/#operational" class="t-db">operational</a> characteristics of the LDAP server.</p>
<div>
<p><strong>matchingrules</strong> define the methods of comparison available in the LDAP server:</p>
<ol>
    <li><strong>matchingrules</strong> are typically built-in to the LDAP server and do not need to be defined explicitly.</li>
    <li>A <strong>matchingrule</strong> forms part of a <strong>collection</strong> called <strong>matchingrules</strong> which can be discovered via the <a title="" href="http://www.zytrax.com/books/ldap/ch3/#operational" class="t-db">subschema</a>.</li>
    <li>A <strong>matchingrule</strong> is defined for each <strong>attribute</strong> using the <a title="" href="http://www.zytrax.com/books/ldap/ch3/#attribute-def" class="t-db">EQUALITY, SUBSTR, ORDERING</a> properties as required - only those properties required are defined. If the search cannot use a <strong>wildcard</strong> there will be no SUBSTR property defined.</li>
</ol>
<h3>3.5.1 Defining matchingRule</h3>
<p>Most <strong>matchingrules</strong> are built-in and you almost never need to
define them but like everything in LDAP it has a defining syntax. The
following is an example of a matchingrule definition using <strong>caseIgnoreMatch</strong>:</p>
<pre>matchingRule ( 2.5.13.2 NAME 'caseIgnoreMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )<br />
</pre>
<p>The deconstruction shows the following:</p>
<p><strong>matchingrule</strong> indicates this is a matchingrule definition.</p>
<p><strong> 2.5.13.2 NAME 'caseIgnoreMatch'</strong> defines the <strong>globally unique</strong> name for this matching rule and as always is comprised of two parts: <strong>NAME 'caseIgnoreMatch'</strong> allows reference to this matchingrule using some semi-understandable text and the OID <strong>2.5.13.2</strong> indicates the matching rule was defined by the X.500 standards group. Rule description:</p>
<div>
<p>"The Case Ignore Match rule compares for equality a presented string
with an attibute value of type PrintableString, NumericString,
TeletexString, BMPString, UniversalString or DirectoryString without
regard for case (upper or lower) of the strings (e.g., "Dundee" and
"DUNDEE" match).</p>
<p>The rule returns TRUE if the strings are the same length and
corresponding characters are identical except possibly with regard to
case. </p>
</div>
<p><strong>SYNTAX 1.3.6.1.4.1.1466.115.121.1.15</strong> defines that this matchingrule operates on the type(s) defined - in this case a DirectoryString (a UTF-8 format string).</p>
<h3>OpenLDAP built-in matchingRules</h3>
<p>This list below can be found for OpenLDAP by interrogating the <strong>subschema</strong> using a command like:</p>
<pre>ldapsearch -H ldap://ldap.example.com -x -s base -b "cn=subschema"<br />
"(objectclass=*)" matchingrules<br />
# matchingrules may be changed to <br />
# attributetypes objectclasses etc., etc.<br />
</pre>
<p>The above command should be on a single line - it is split for HTML
formatting reasons only. Replace ldap.example.com with the host name of
your LDAP server. If the server is running locally you can omit the -H
argument.</p>
<p>Alternatively use any good LDAP browser with a Root DN of "cn=subschema"</p>
<p>The above command will return this list (OpenLDAP 2.1.12 on FreeBSD):</p>
<pre># Subschema<br />
dn: cn=Subschema<br />
matchingRules: ( 2.5.13.0 NAME 'objectIdentifierMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )<br />
matchingRules: ( 2.5.13.1 NAME 'distinguishedNameMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )<br />
matchingRules: ( 2.5.13.2 NAME 'caseIgnoreMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )<br />
matchingRules: ( 2.5.13.3 NAME 'caseIgnoreOrderingMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )<br />
matchingRules: ( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )<br />
matchingRules: ( 2.5.13.5 NAME 'caseExactMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )<br />
matchingRules: ( 2.5.13.6 NAME 'caseExactOrderingMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )<br />
matchingRules: ( 2.5.13.7 NAME 'caseExactSubstringsMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )<br />
matchingRules: ( 2.5.13.8 NAME 'numericStringMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )<br />
matchingRules: ( 2.5.13.10 NAME 'numericStringSubstringsMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )<br />
matchingRules: ( 2.5.13.13 NAME 'booleanMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )<br />
matchingRules: ( 2.5.13.14 NAME 'integerMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )<br />
matchingRules: ( 2.5.13.15 NAME 'integerOrderingMatch' <br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )<br />
matchingRules: ( 2.5.13.16 NAME 'bitStringMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )<br />
matchingRules: ( 2.5.13.17 NAME 'octetStringMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )<br />
matchingRules: ( 2.5.13.18 NAME 'octetStringOrderingMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )<br />
matchingRules: ( 2.5.13.20 NAME 'telephoneNumberMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )<br />
matchingRules: ( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )<br />
matchingRules: ( 2.5.13.23 NAME 'uniqueMemberMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )<br />
matchingRules: ( 2.5.13.27 NAME 'generalizedTimeMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )<br />
matchingRules: ( 2.5.13.28 NAME 'generalizedTimeOrderingMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )<br />
matchingRules: ( 2.5.13.29 NAME 'integerFirstComponentMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )<br />
matchingRules: ( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )<br />
matchingRules: ( 2.5.13.34 NAME 'certificateExactMatch'<br />
SYNTAX 1.2.826.0.1.3344810.7.1 )<br />
matchingRules: ( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )<br />
matchingRules: ( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )<br />
matchingRules: ( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )<br />
matchingRules: ( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' <br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )<br />
matchingRules: ( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )<br />
matchingRules: ( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch'<br />
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )<br />
</pre>
<p>You can find what the <strong>OIDs</strong> are and therefore the exact english description of the matchingRule using this <a title="" href="http://www.alvestrand.no/objectid/top.html" class="t-db">wonderful site</a>.</p>
<p><a href="http://www.zytrax.com/books/ldap/ch3/#contents"><img src="http://www.zytrax.com/images/go_up.gif" alt="Up Arrow" border="0" /></a></p>
<h2>3.6 LDAP Operational Attributes and Objects</h2>
<p>There are a bunch of attributes and objectclasses that are built
into the LDAP server and govern how it works or functions. These
attributes and object classes are typically called <strong>operational</strong>.</p>
<p>These <strong>operational thingies</strong> all live under the <a href="http://www.zytrax.com/books/ldap/apd/index.html#rootdse" class="t-db">rootDSE</a> and are not visible in normal operations.</p>
<p>The relationship between the DIT(s) and its entries and the RootDSE and its objects is shown below:</p>
<p align="center"><img title="" src="http://www.zytrax.com/books/ldap/images/ldap-rootdse.gif" alt="" border="0" /></p>
<p>The rootDSE can be inspected using either a suitable LDAP browser (instructions for <a href="http://www.zytrax.com/books/ldap/ch14/ldapbrowser.html#operational" class="t-db">LDAPBrowser/Editor</a>) with an empty Root DN or the following command:</p>
<pre>ldapsearch -H ldap://ldap.mydomain.com -x -s base -b "" +<br />
# note the + returns operational attributes<br />
</pre>
<p>This should return something similar to that shown below (from
OpenLDAP 2.4.8) - the values in parentheses are added explanations and
are not returned by the server:</p>
<pre>dn:<br />
structuralObjectClass: OpenLDAProotDSE<br />
configContext: cn=config<br />
namingContexts: dc=example,dc=com<br />
namingContexts: dc=example,dc=net<br />
monitorContext: cn=Monitor<br />
supportedControl: 1.3.6.1.4.1.4203.1.9.1.1 (Contentsync <a href="http://www.zytrax.com/books/ldap/apc/rfc4530.txt" class="t-db">RFC 4530</a>)<br />
supportedControl: 2.16.840.1.113730.3.4.18 (ProxiedAuthv2 <a href="http://www.zytrax.com/books/ldap/apc/rfc4370.txt" class="t-db">RFC 4370</a>)<br />
supportedControl: 2.16.840.1.113730.3.4.2 (ManageDSAIT <a href="http://www.zytrax.com/books/ldap/apc/rfc3377.txt" class="t-db">RFC3377</a>)<br />
supportedControl: 1.3.6.1.4.1.4203.1.10.1 (SubEntries <a href="http://www.zytrax.com/books/ldap/apc/rfc3673.txt" class="t-db">RFC3673</a>)<br />
supportedControl: 1.2.840.113556.1.4.319 (pagedResults <a href="http://www.zytrax.com/books/ldap/apc/rfc2696.txt" class="t-db">RFC2696</a>)<br />
supportedControl: 1.2.826.0.1.3344810.2.3 (MatchedValues <a href="http://www.zytrax.com/books/ldap/apc/rfc3876.txt" class="t-db">RFC3876</a>)<br />
supportedControl: 1.3.6.1.1.13.2 (Post Read <a href="http://www.zytrax.com/books/ldap/apc/rfc4527.txt" class="t-db">RFC4527</a>)<br />
supportedControl: 1.3.6.1.1.13.1 (Pre-Read <a href="http://www.zytrax.com/books/ldap/apc/rfc4527.txt" class="t-db">RFC4527</a>))<br />
supportedControl: 1.3.6.1.1.12 (Assertion <a href="http://www.zytrax.com/books/ldap/apc/rfc4528.txt" class="t-db">RFC4528</a>)<br />
supportedExtension: 1.3.6.1.4.1.4203.1.11.1 (ModifyPassword <a href="http://www.zytrax.com/books/ldap/apc/rfc3088.txt" class="t-db">RFC3088</a>)<br />
supportedExtension: 1.3.6.1.4.1.4203.1.11.3 (WhoAmI <a href="http://www.zytrax.com/books/ldap/apc/rfc4532.txt" class="t-db">RFC4532</a>)<br />
supportedExtension: 1.3.6.1.1.8 (Cancel <a href="http://www.zytrax.com/books/ldap/apc/rfc3909.txt" class="t-db">RFC3909</a>)<br />
supportedFeatures: 1.3.6.1.1.14 (Modify-Increment <a href="http://www.zytrax.com/books/ldap/apc/rfc4525.txt" class="t-db">RFC4525</a>)<br />
supportedFeatures: 1.3.6.1.4.1.4203.1.5.1 (OperationalAttrs <a href="http://www.zytrax.com/books/ldap/apc/rfc3674.txt" class="t-db">RFC3674</a>)<br />
supportedFeatures: 1.3.6.1.4.1.4203.1.5.2 (ObjectClassAttrs <a href="http://www.zytrax.com/books/ldap/apc/rfc4529.txt" class="t-db">RFC4529</a>)<br />
supportedFeatures: 1.3.6.1.4.1.4203.1.5.3 (TrueFalse <a href="http://www.zytrax.com/books/ldap/apc/rfc4526.txt" class="t-db">RFC4526</a>)<br />
supportedFeatures: 1.3.6.1.4.1.4203.1.5.4 (LanguageTag <a href="http://www.zytrax.com/books/ldap/apc/rfc3866.txt" class="t-db">RFC3866</a>)<br />
supportedFeatures: 1.3.6.1.4.1.4203.1.5.5 (LanguageRange <a href="http://www.zytrax.com/books/ldap/apc/rfc3866.txt" class="t-db">RFC3866</a>)<br />
supportedLDAPVersion: 3<br />
supportedSASLMechanisms: NTLM<br />
supportedSASLMechanisms: GSSAPI<br />
supportedSASLMechanisms: DIGEST-MD5<br />
supportedSASLMechanisms: CRAM-MD5<br />
entryDN:<br />
subschemaSubentry: cn=Subschema<br />
</pre>
<p>An explanation of each <strong>supportedExtension</strong> can be found using this <a title="" href="http://www.alvestrand.no/objectid/top.html" class="t-db">wonderful site</a>. The above listing shows this LDAP server supports two <a title="" href="http://www.zytrax.com/books/ldap/apd/index.html#dit" class="t-db">DITs</a> - shown as <strong>namingContexts</strong> - <a title="" href="http://www.zytrax.com/books/ldap/ch11/multi-dit.html" class="t-db">which were configured using this process</a>.</p>
<p>It is possible to add extensions using the OpenLDAP slapd.conf <a title="" href="http://www.zytrax.com/books/ldap/ch6/index.html#rootdse" class="t-db">rootDSE</a> directive.</p>
<p><br />
</p>
<p>参见URL：</p>
<p>http://www.zytrax.com/books/ldap/ch3/</p>
</div>
<img src ="http://www.blogjava.net/liuzheng/aggbug/267316.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/liuzheng/" target="_blank">刘铮 </a> 2009-04-24 11:07 <a href="http://www.blogjava.net/liuzheng/articles/267316.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ldap ldap-schema</title><link>http://www.blogjava.net/liuzheng/articles/267314.html</link><dc:creator>刘铮 </dc:creator><author>刘铮 </author><pubDate>Fri, 24 Apr 2009 03:00:00 GMT</pubDate><guid>http://www.blogjava.net/liuzheng/articles/267314.html</guid><wfw:comment>http://www.blogjava.net/liuzheng/comments/267314.html</wfw:comment><comments>http://www.blogjava.net/liuzheng/articles/267314.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/liuzheng/comments/commentRss/267314.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/liuzheng/services/trackbacks/267314.html</trackback:ping><description><![CDATA[URL:<br />
http://www.it.ufl.edu/projects/directory/ldap-schema/<br />
<br />
<img src ="http://www.blogjava.net/liuzheng/aggbug/267314.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/liuzheng/" target="_blank">刘铮 </a> 2009-04-24 11:00 <a href="http://www.blogjava.net/liuzheng/articles/267314.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>