Zend_Auth_Adapter_Ldap.xml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. <sect1 id="zend.auth.adapter.ldap">
  2. <title>LDAP 认证 </title>
  3. <sect2 id="zend.auth.adapter.ldap.introduction">
  4. <title> 简介 </title>
  5. <para>
  6. <code>Zend_Auth_Adapter_Ldap</code> 用 LDAP 服务支持 web 程序认证。它的功能包括用户名和域名规范化、多域认证和实效切(failover)换能力。经测试,它能与 <ulink url="http://www.microsoft.com/windowsserver2003/technologies/directory/activedirectory/">Microsoft Active Directory</ulink> 和 <ulink url="http://www.openldap.org/">OpenLDAP</ulink> 一起工作,它也应该能和其它 LDAP 服务提供者一起工作。
  7. </para>
  8. <para>
  9. 本文档包括使用 <code>Zend_Auth_Adapter_Ldap</code> 的指南、它的 API 、各种可用选项的大纲、认证问题故障排除的诊断信息和Active Directory 与 OpenLDAP 服务器的范例选项。
  10. </para>
  11. </sect2>
  12. <sect2 id="zend.auth.adapter.ldap.usage">
  13. <title> 用法 </title>
  14. <para>
  15. 为了快速把 <code>Zend_Auth_Adapter_Ldap</code> 认证集成到你的程序中,即使你不使用 <code>Zend_Controller</code>,代码的基本部分看起来是这样的:
  16. <programlisting role="php"><![CDATA[
  17. $username = $this->_request->getParam('username');
  18. $password = $this->_request->getParam('password');
  19. $auth = Zend_Auth::getInstance();
  20. $config = new Zend_Config_Ini('../application/config/config.ini',
  21. 'production');
  22. $log_path = $config->ldap->log_path;
  23. $options = $config->ldap->toArray();
  24. unset($options['log_path']);
  25. $adapter = new Zend_Auth_Adapter_Ldap($options, $username,
  26. $password);
  27. $result = $auth->authenticate($adapter);
  28. if ($log_path) {
  29. $messages = $result->getMessages();
  30. $logger = new Zend_Log();
  31. $logger->addWriter(new Zend_Log_Writer_Stream($log_path));
  32. $filter = new Zend_Log_Filter_Priority(Zend_Log::DEBUG);
  33. $logger->addFilter($filter);
  34. foreach ($messages as $i => $message) {
  35. if ($i-- > 1) { // $messages[2] and up are log messages
  36. $message = str_replace("\n", "\n ", $message);
  37. $logger->log("Ldap: $i: $message", Zend_Log::DEBUG);
  38. }
  39. }
  40. }
  41. ]]>
  42. </programlisting>
  43. 虽然日志( logging )代码是可选的,还是强烈建议使用日志。<code>Zend_Auth_Adapter_Ldap</code> 将记录任何想要的信息细节到 <code>$messages</code> (更多的信息看下面),对于难以调试的程序来说,有历史记录这是个很好的功能。
  44. </para>
  45. <para>
  46. 上面用到 <code>Zend_Config_Ini</code> 的代码是来加载适配器选项,它也是可选的,使用一个规则的数组来完成工作。下面是带有两个单独的服务器选项的 <code>application/config/config.ini</code> 文件的例子。带有多组服务器选项的适配器将按顺序来尝试每个服务器直到资格被成功认证。服务器的名字 (例如 <code>server1</code> and <code>server2</code>)是任意的,关于选项数组的细节,参见下面 <emphasis>Server Options</emphasis> 一节。 注意 <code>Zend_Config_Ini</code> 要求任何带有等号(<code>=</code>)的值需要括起来(如下面的 DNs)。
  47. <programlisting role="ini"><![CDATA[
  48. [production]
  49. ldap.log_path = /tmp/ldap.log
  50. ; Typical options for OpenLDAP
  51. ldap.server1.host = s0.foo.net
  52. ldap.server1.accountDomainName = foo.net
  53. ldap.server1.accountDomainNameShort = FOO
  54. ldap.server1.accountCanonicalForm = 3
  55. ldap.server1.username = "CN=user1,DC=foo,DC=net"
  56. ldap.server1.password = pass1
  57. ldap.server1.baseDn = "OU=Sales,DC=foo,DC=net"
  58. ldap.server1.bindRequiresDn = true
  59. ; Typical options for Active Directory
  60. ldap.server2.host = dc1.w.net
  61. ldap.server2.useSsl = true
  62. ldap.server2.accountDomainName = w.net
  63. ldap.server2.accountDomainNameShort = W
  64. ldap.server2.accountCanonicalForm = 3
  65. ldap.server2.baseDn = "CN=Users,DC=w,DC=net"
  66. ]]>
  67. </programlisting>
  68. 上述的配置将指示 <code>Zend_Auth_Adapter_Ldap</code> 首先来尝试用 OpenLDAP 服务器 <code>s0.foo.net</code> 来认证用户,如果不论什么原因认证失败,将尝试 AD 服务器 <code>dc1.w.net</code>。
  69. </para>
  70. <para>
  71. 这个配置示例了在不同的域的服务器的多域认证,也可以在同一域中用多个服务器来提供冗余。
  72. </para>
  73. <para>
  74. 注意在这个例子中,即使 OpenLDAP 不需要用于 Windows 的短 NetBIOS 风格的域名,我们仍在这里提供它以保证命名正规化 (参见下面的 <emphasis>Username Canonicalization</emphasis> 一节)。
  75. </para>
  76. </sect2>
  77. <sect2 id="zend.auth.adapter.ldap.api">
  78. <title>The API</title>
  79. <para>
  80. <code>Zend_Auth_Adapter_Ldap</code> 构造器接受三个参数。
  81. </para>
  82. <para>
  83. <code>$options</code> 参数是必需的并且是一个包含一组或多组选项的数组。注意它是 <link linkend="zend.ldap">Zend_Ldap</link> 选项的 <emphasis> 数组的数组 </emphasis> 。即使你只使用一个 LDAP 服务器,选项仍要包含在另一个数组中。
  84. </para>
  85. <para>
  86. 下面是一个选项参数包含两组服务器选项( <code>s0.foo.net</code> 和 <code>dc1.w.net</code> (和上面 INI 表示法一样的选项))的例子的 <ulink url="http://php.net/print_r"><code>print_r()</code></ulink> 输出:
  87. <programlisting role="output"><![CDATA[
  88. Array
  89. (
  90. [server2] => Array
  91. (
  92. [host] => dc1.w.net
  93. [useSsl] => 1
  94. [accountDomainName] => w.net
  95. [accountDomainNameShort] => W
  96. [accountCanonicalForm] => 3
  97. [baseDn] => CN=Users,DC=w,DC=net
  98. )
  99. [server1] => Array
  100. (
  101. [host] => s0.foo.net
  102. [accountDomainName] => foo.net
  103. [accountDomainNameShort] => FOO
  104. [accountCanonicalForm] => 3
  105. [username] => CN=user1,DC=foo,DC=net
  106. [password] => pass1
  107. [baseDn] => OU=Sales,DC=foo,DC=net
  108. [bindRequiresDn] => 1
  109. )
  110. )
  111. ]]>
  112. </programlisting>
  113. 上述每组选项提供的信息是不同的,主要是因为当绑定(参见下面 <emphasis> 服务器选项 </emphasis> 一节中的 <code>bindRequiresDn</code> 选项)时 AD 不要求在 DN 表单中的有用户名,这意味着我们可以忽略很多和为认证用户名获取 DN 相关的选项。
  114. </para>
  115. <note>
  116. <title> 什么是 DN?</title>
  117. <para>
  118. DN 或者 "distinguished name" 是一个字符串,表示在 LDAP 目录中到一个对象的路径。每个用逗号分隔的组件是一个属性并且它的值表示一个节点。组件是按反顺序来算的,例如:用户账户 <emphasis>CN=Bob Carter,CN=Users,DC=w,DC=net</emphasis> 直接位于 <emphasis>CN=Users,DC=w,DC=net container</emphasis> 里的。这种结构用 LDAP 浏览器如 ADSI Edit MMC snap-in for Active Directory 或 phpLDAPadmin 可以最好地浏览。
  119. </para>
  120. </note>
  121. <para>
  122. 服务器名(如上面的 '<code>server1</code>' 和 '<code>server2</code>')是任意的,但因为使用 <code>Zend_Config</code>,标识符(identifiers)应当以数字索引的相反出现并且不应当包含任何用于相关文件格式(例如,'<code>.</code>' INI 属性分隔符,XML 条目参考 '<code>&amp;</code>' 等)的特殊字符。
  123. </para>
  124. <para>
  125. 用多组服务器选项,适配器可以在多域的环境中认证用户并提供 failover (估计是失败后尝试下一个服务器),所以如果一个服务器不可用,将查询另一个。
  126. </para>
  127. <note>
  128. <title> 非常详细的介绍 (The Gory Details)- 在认证方法中到底发生了什么?</title>
  129. <para>
  130. 当调用 <code>authenticate()</code> 方法,适配器反复把每组服务器选项设置到内部 <code>Zend_Ldap</code> 实例并带用于认证的用户名和密码调用 <code>Zend_Ldap::bind()</code> 方法。<code>Zend_Ldap</code> 类检查用户名是否在域中合格 (例如,有域的组件如 <emphasis>alice@foo.net</emphasis> 或 <emphasis>FOO\alice</emphasis>)。如果域存在,但它不匹配任何一种服务器的域名(<emphasis>foo.net</emphasis> 或 <emphasis>FOO</emphasis>),就抛出一个特殊的异常并由 <code>Zend_Auth_Adapter_Ldap</code> 捕捉,这样那个服务器就被忽略并且选择下个服务器选项。如果域名 <emphasis> 确实 </emphasis> 匹配,但是如果用户没有提供一个合格的用户名,<code>Zend_Ldap</code> 继续尝试绑定被提供的证书(credentials)。如果绑定不成功,<code>Zend_Ldap</code> 抛出一个由 <code>Zend_Auth_Adapter_Ldap</code> 捕捉的 <code>Zend_Ldap_Exception</code> 并尝试下一组服务器选项。如果绑定成功,反复尝试(迭代?(iteration))就停止,并且适配器的 <code>authenticate()</code> 方法返回一个成功的结果。如果所有服务器选项都试过了而且都不成功,认证就失败了,<code>authenticate()</code> 返回一个失败的结果并带有最后一个尝试的错误消息。
  131. </para>
  132. </note>
  133. <para>
  134. <code>Zend_Auth_Adapter_Ldap</code> 构造器的用户名和密码参数是要被认证的证书(例如,用户通过 HTML 登录表单提供的证书(credentials))。另外,也可以通过 <code>setUsername()</code> 和 <code>setPassword()</code> 方法来设置。
  135. </para>
  136. </sect2>
  137. <sect2 id="zend.auth.adapter.ldap.server-options">
  138. <title> 服务器选项 </title>
  139. <para>
  140. <emphasis> 在 Zend_Auth_Adapter_Ldap 的上下文中</emphasis> 的每组服务器选项包含下列选项,它们基本上不可修改地传递给 <code>Zend_Ldap::setOptions()</code>:
  141. <table id="zend.auth.adapter.ldap.server-options.table">
  142. <title> 服务器选项 </title>
  143. <tgroup cols="2">
  144. <thead>
  145. <row>
  146. <entry> 名称 </entry>
  147. <entry> 描述 </entry>
  148. </row>
  149. </thead>
  150. <tbody>
  151. <row>
  152. <entry><emphasis role="strong">host</emphasis></entry>
  153. <entry>
  154. 这些选项表示的 LDAP 服务器的主机名,该选项是必需的。
  155. </entry>
  156. </row>
  157. <row>
  158. <entry><emphasis role="strong">port</emphasis></entry>
  159. <entry>
  160. LDAP 服务器监听的端口,如果 <emphasis role="strong">useSsl</emphasis> 是 <code>true</code>,缺省 <emphasis role="strong"> 端口 </emphasis> 值是 636。如果 <emphasis role="strong">useSsl</emphasis> 是 <code>false</code>,缺省 <emphasis role="strong"> 端口 </emphasis> 值是 389。
  161. </entry>
  162. </row>
  163. <row>
  164. <entry><emphasis role="strong">useSsl</emphasis></entry>
  165. <entry>
  166. 如果是 <code>true</code>,表示 LDAP 客户端应当使用 SSL / TLS 加密传输。在生产环境中强烈建议使用 <code>true</code> 值以防止明文传输密码。缺省值为 <code>false</code> 是因为服务器经常在安装之后请求被分别安装的证书。它也改变缺省 <emphasis role="strong"> 端口 </emphasis> 值( 见上面 <emphasis role="strong"> 端口 </emphasis> 的描述)。
  167. </entry>
  168. </row>
  169. <row>
  170. <entry><emphasis role="strong">username</emphasis></entry>
  171. <entry>
  172. 账户的 DN, 用来执行账户 DN 查找。LDAP servers that require the username to be in DN form when performing the "bind" require this option (这句没有理解)。
  173. 如果 <emphasis role="strong">bindRequiresDn</emphasis> 是 <code>true</code>,这个选项是必需的。这个账户不需要是优先账户 - a account with read-only
  174. access to objects under the <emphasis role="strong">baseDn</emphasis> is all that is necessary (and preferred based on the <emphasis>Principle of Least Privilege</emphasis>).
  175. </entry>
  176. </row>
  177. <row>
  178. <entry><emphasis role="strong">password</emphasis></entry>
  179. <entry>
  180. 账户的密码,用来执行账户 DN 查找。如果没有提供这个选项,当执行账户 DN 查找时,LDAP 客户端将尝试“匿名绑定”。
  181. </entry>
  182. </row>
  183. <row>
  184. <entry><emphasis role="strong">bindRequiresDn</emphasis></entry>
  185. <entry>
  186. 一些 LDAP 服务器要求用户名以 DN 格式来绑定,如 <emphasis>CN=Alice Baker,OU=Sales,DC=foo,DC=net</emphasis> (基本上 <emphasis> 除了 </emphasis> AD 以外所有的服务器)。如果这个选项是 <code>true</code>,<code>Zend_Ldap</code> 自动获取被认证的用户所对应的 DN。如果它不是 DN 格式,那就重新绑定合适的 DN。缺省值是 <code>false</code>。目前,当绑定时,只有微软的 Active Directory 服务器(ADS)<emphasis> 不 </emphasis> 要求用户名为 DN 格式,所以和 AD 一起使用,这个选项可以是 <code>false</code> (而且应当是,因为获取 DN 需要额外的过程(round trip)到服务器),否则,这个选项必需设置为 <code>true</code> (例如,OpenLDAP)。当搜索账户时,这个选项也控制缺省的 <emphasis role="strong">acountFilterFormat</emphasis>,参见 <emphasis role="strong">accountFilterFormat</emphasis> 选项。
  187. </entry>
  188. </row>
  189. <row>
  190. <entry><emphasis role="strong">baseDn</emphasis></entry>
  191. <entry>
  192. 定位所有被认证账户下的 DN,这个选项是必需的。如果你不能确定正确的 <emphasis role="strong">baseDn</emphasis> 值,可以用 <emphasis>DC=</emphasis> 组件从用户的 DNS 域来产生它,例如,如果用户的基本名是 <emphasis>alice@foo.net</emphasis>,<emphasis>DC=foo,DC=net</emphasis> 的 <emphasis role="strong">baseDn</emphasis> 应当工作。然而更精确的位置(例如 <emphasis>OU=Sales,DC=foo,DC=net</emphasis> )将更有效。
  193. </entry>
  194. </row>
  195. <row>
  196. <entry><emphasis role="strong">accountCanonicalForm</emphasis></entry>
  197. <entry>
  198. 一个是 2、3 或 4 的值,用来指示那个账户名在成功认证后需要规范化。值的解释具体如下:2 表示传统的用户名(例如 <emphasis>alice</emphasis> ),3 表示反斜杠式(backslash-style)名称(例如 <emphasis>FOO\alice</emphasis>),或者 4 表示基本式用户名(例如 <emphasis>alice@foo.net</emphasis>)。缺省值为 4 (例如 <emphasis>alice@foo.net</emphasis> )。例如,当值为 3,由 <code>Zend_Auth_Result::getIdentity()</code> (如果使用了 <code>Zend_Auth</code>,则是 <code>Zend_Auth::getIdentity()</code>,) 返回的身份(identity)将总是 <emphasis>FOO\alice</emphasis>,不论 Alice 提供了什么格式,如 <emphasis>alice</emphasis>、 <emphasis>alice@foo.net</emphasis>、 <emphasis>FOO\alice</emphasis>、<emphasis>FoO\aLicE</emphasis>、 <emphasis>foo.net\alice</emphasis> 等。见 <code>Zend_Ldap</code> 中的 <emphasis>Account Name Canonicalization</emphasis> 一节有更多的细节。注意当使用多组服务器选项时,建议但不要求所有服务器选项使用相同的 <emphasis role="strong">accountCanonicalForm</emphasis>,这样,用户名对于同一格式总是规范化的(例如,对于 AD 服务器规范化为 <emphasis>EXAMPLE\username</emphasis>,但对于 OpenLDAP 服务器规范化为 <emphasis>username@example.com</emphasis>,对于程序的高水平(high-level)逻辑,这可能很不好用。)
  199. </entry>
  200. </row>
  201. <row>
  202. <entry><emphasis role="strong">accountDomainName</emphasis></entry>
  203. <entry>
  204. 目标 LDAP 服务器的 FQDN 域名是一个授权(authority)(例如 <code>example.com</code>)。该选项用来规范化名字,这样用户提供的用户名可以为绑定按需转换。它也可用来决定是否服务器对用户名是一个授权(例如 <emphasis role="strong">accountDomainName</emphasis> 是 <emphasis>foo.net</emphasis> 并且用户提供了 <emphasis>bob@bar.net</emphasis>,将不查询服务器并导致一个错误)。该选项不是必需的,但如果不提供,那就不支持用户名为基本名(principal name)格式(例如 <emphasis>alice@foo.net</emphasis>)。强烈建议使用该选项,因为许多用例要求生成基本名格式。
  205. </entry>
  206. </row>
  207. <row>
  208. <entry><emphasis role="strong">accountDomainNameShort</emphasis></entry>
  209. <entry>
  210. 目标 LDAP 服务器的 ‘短’ 域名是一个授权(authority)(例如 <emphasis>FOO</emphasis>)。注意按 1:1 来映射 <emphasis role="strong">accountDomainName</emphasis> 和 <emphasis role="strong">accountDomainNameShort</emphasis>。该选项用于为 Windows 网络指定 NetBIOS 名但也可用于非 AD 服务器(例如,当多组服务器选用使用反斜杠风格的 <emphasis role="strong">accountCanonicalForm</emphasis>时为了保持一致性)。该选项不是必需的但如果不使用,就不支持反斜杠格式的用户名(例如 <emphasis>FOO\alice</emphasis>)。
  211. </entry>
  212. </row>
  213. <row>
  214. <entry><emphasis role="strong">accountFilterFormat</emphasis></entry>
  215. <entry>
  216. 用来搜索账户的 LDAP 搜索过滤器。这个字符串是个 <ulink url="http://php.net/printf"><code>printf()</code></ulink> 风格的表达式,必需包含一个 '<code>%s</code>' 来适合用户名。缺省值为 '<code>(&amp;(objectClass=user)(sAMAccountName=%s))</code>',除非 <emphasis role="strong">bindRequiresDn</emphasis> 设置为 <code>true</code>,那样缺省值就是 '<code>(&amp;(objectClass=posixAccount)(uid=%s))</code>'。例如,如果因为某种原因你想对 AD 使用 <code>bindRequiresDn = true</code> ,需要设置 <code>accountFilterFormat = '(&amp;(objectClass=user)(sAMAccountName=%s))</code>'。
  217. </entry>
  218. </row>
  219. </tbody>
  220. </tgroup>
  221. </table>
  222. </para>
  223. <note>
  224. <para>
  225. 如果你设置 <code>useSsl = true</code> 可能发现 LDAP 客户端会产生一个不能校验服务器证书的错误。假定 PHP LDAP 扩展完全链接到 OpenLDAP 客户库,为解决这个问题你可以在 OpenLDAP 客户 <code>ldap.conf</code> 里设置 “<code>TLS_REQCERT never</code>” (并重启 web 服务器)来指明 OpenLDAP 客户端库你信任这个服务器。另外如果涉及到服务器可能被欺骗,你可以输出 LDAP 服务器的根证书并把它放到 web 服务器,这样 OpenLDAP 客户端可以校验服务器的身份。
  226. </para>
  227. </note>
  228. </sect2>
  229. <sect2 id="zend.auth.adapter.ldap.debugging">
  230. <title> 收集调试信息 </title>
  231. <para>
  232. <code>Zend_Auth_Adapter_Ldap</code> 在它的 <code>authenticate()</code> 方法里收集调试信息。这个信息存储在 <code>Zend_Auth_Result</code> 对象里。下面描述由 <code>Zend_Auth_Result::getMessages()</code> 返回的数组:
  233. <table id="zend.auth.adapter.ldap.debugging.table">
  234. <title> 调试信息 (Messages)</title>
  235. <tgroup cols="2">
  236. <thead>
  237. <row>
  238. <entry> 信息(Messages) 数组索引</entry>
  239. <entry> 描述 </entry>
  240. </row>
  241. </thead>
  242. <tbody>
  243. <row>
  244. <entry>Index 0</entry>
  245. <entry>
  246. 显示给用户的用户友好的一般信息(例如无效的证书(credentials))。如果认证成功,这个字符串是空的。
  247. </entry>
  248. </row>
  249. <row>
  250. <entry>Index 1</entry>
  251. <entry>
  252. 更详细的错误信息,不适合显示给用户但作为服务器操错日志。如果认证成功,这个字符串是空的。
  253. </entry>
  254. </row>
  255. <row>
  256. <entry>Indexes 2 and higher</entry>
  257. <entry>
  258. 所有日志信息按顺序从 index 2 开始。
  259. </entry>
  260. </row>
  261. </tbody>
  262. </tgroup>
  263. </table>
  264. 实践上,index 0 显示给用户(例如使用 FlashMessenger 助手), index 1 作为日志,如果收集到调试信息, index 2 和它以后的 index 也作为日志(尽管最终的信息总是从 index 1 的字符串开始)。
  265. </para>
  266. </sect2>
  267. <sect2 id="zend.auth.adapter.ldap.options-common-server-specific">
  268. <title> 特定服务器的通用选项 </title>
  269. <sect3 id="zend.auth.adapter.ldap.options-common-server-specific.active-directory">
  270. <title>Active Directory 的选项 </title>
  271. <para>
  272. 对于 ADS,下列选项值得注意:
  273. <table id="zend.auth.adapter.ldap.options-common-server-specific.active-directory.table">
  274. <title>Active Directory 的选项 </title>
  275. <tgroup cols="2">
  276. <thead>
  277. <row>
  278. <entry> 名字 </entry>
  279. <entry> 另外的注释 </entry>
  280. </row>
  281. </thead>
  282. <tbody>
  283. <row>
  284. <entry><emphasis role="strong">host</emphasis></entry>
  285. <entry>
  286. 适用所有的服务器,该选项必需。
  287. </entry>
  288. </row>
  289. <row>
  290. <entry><emphasis role="strong">useSsl</emphasis></entry>
  291. <entry>
  292. 因为安全的缘故,如果服务器安装了必要的证书,这个应该是 <code>true</code>。
  293. </entry>
  294. </row>
  295. <row>
  296. <entry><emphasis role="strong">baseDn</emphasis></entry>
  297. <entry>
  298. 适用所有的服务器,该选项必需。缺省地 AD 把所有用户账户放在 <emphasis>Users</emphasis> 容器中 (例如 <emphasis>CN=Users,DC=foo,DC=net</emphasis>),但在大型组织里缺省不常见,要询问 AD 管理员你的程序账户的最好的 DN 是什么。
  299. </entry>
  300. </row>
  301. <row>
  302. <entry><emphasis role="strong">accountCanonicalForm</emphasis></entry>
  303. <entry>
  304. 几乎可以确定你想要这个值为 3 来使用反斜杠式的名称(例如 <emphasis>FOO\alice</emphasis>),这对于 Windows 用户来说是最熟悉的。你 <emphasis> 不 </emphasis> 应该使用不合格的格式 2 (例如 <emphasis>alice</emphasis>),因为它可能授权在其它信任域里(例如 <emphasis>BAR\alice</emphasis> 和 <emphasis>FOO\alice</emphasis> 将被当作相同的用户)相同名字的用户访问你的程序。(参见下面的注释)
  305. </entry>
  306. </row>
  307. <row>
  308. <entry><emphasis role="strong">accountDomainName</emphasis></entry>
  309. <entry>
  310. 使用 AD 时这是必需的除非使用 <emphasis role="strong">accountCanonicalForm</emphasis> 2 ,再强调一下,我们不鼓励这样用。
  311. </entry>
  312. </row>
  313. <row>
  314. <entry><emphasis role="strong">accountDomainNameShort</emphasis></entry>
  315. <entry>
  316. AD 服务器是授权的域用户的 NetBIOS 名称。如果使用反斜杠风格 <emphasis role="strong">accountCanonicalForm</emphasis>,这个是必需的。
  317. </entry>
  318. </row>
  319. </tbody>
  320. </tgroup>
  321. </table>
  322. </para>
  323. <note>
  324. <para>
  325. 从技术角度讲,用当前的 <code>Zend_Auth_Adapter_Ldap</code> 实现进行跨域认证是没有危险的,因为服务器域是被显式检查的,但对将来的实现未必是对的,如在运行时发现域名或者如果使用替代的适配器(例如 Kerberos)。一般来说,含糊的账户名是安全问题的来源,所以最好使用合格的账户名称。
  326. </para>
  327. </note>
  328. </sect3>
  329. <sect3 id="zend.auth.adapter.ldap.options-common-server-specific.openldap">
  330. <title>OpenLDAP 的选项 </title>
  331. <para>
  332. 对于 OpenLDAP 或一般的使用典型的 posixAccount 风格的 LDAP 服务器,下面的选项值得注意:
  333. <table id="zend.auth.adapter.ldap.options-common-server-specific.openldap.table">
  334. <title> OpenLDAP 的选项 </title>
  335. <tgroup cols="2">
  336. <thead>
  337. <row>
  338. <entry> 名字 </entry>
  339. <entry> 另外的注释 </entry>
  340. </row>
  341. </thead>
  342. <tbody>
  343. <row>
  344. <entry><emphasis role="strong">host</emphasis></entry>
  345. <entry>
  346. 适用所有的服务器,该选项必需。
  347. </entry>
  348. </row>
  349. <row>
  350. <entry><emphasis role="strong">useSsl</emphasis></entry>
  351. <entry>
  352. 因为安全的缘故,如果服务器安装了必要的证书,这个应该是 <code>true</code>。
  353. </entry>
  354. </row>
  355. <row>
  356. <entry><emphasis role="strong">username</emphasis></entry>
  357. <entry>
  358. 必需并一定是一个 DN,因为当执行绑定时 OpenLDAP 要求 DN 格式的用户名。设法使用无特权的账户。
  359. </entry>
  360. </row>
  361. <row>
  362. <entry><emphasis role="strong">password</emphasis></entry>
  363. <entry>
  364. 对应上述用户名的密码,如果 LDAP 服务器支持匿名绑定,这个也许会忽略。
  365. </entry>
  366. </row>
  367. <row>
  368. <entry><emphasis role="strong">bindRequiresDn</emphasis></entry>
  369. <entry>
  370. 必需并一定是 <code>true</code>,因为当执行绑定时 OpenLDAP 要求 DN 格式的用户名。
  371. </entry>
  372. </row>
  373. <row>
  374. <entry><emphasis role="strong">baseDn</emphasis></entry>
  375. <entry>
  376. 适用所有的服务器,该选项是必需的并指示所有被认证的账户的 DN 的定位。
  377. </entry>
  378. </row>
  379. <row>
  380. <entry><emphasis role="strong">accountCanonicalForm</emphasis></entry>
  381. <entry>
  382. 可选但缺省值是 4 (基本风格名如 <emphasis>alice@foo.net</emphasis>),如果适用反斜杠式的名字(如 <emphasis>FOO\alice</emphasis>)这个也许不是理想的。对于反斜杠式名字值为 3。
  383. </entry>
  384. </row>
  385. <row>
  386. <entry><emphasis role="strong">accountDomainName</emphasis></entry>
  387. <entry>
  388. 必需,除非使用不推荐的 <emphasis role="strong">accountCanonicalForm</emphasis> 2,
  389. </entry>
  390. </row>
  391. <row>
  392. <entry><emphasis role="strong">accountDomainNameShort</emphasis></entry>
  393. <entry>
  394. 如果不使用 AD ,这个值不是必需的。否则,如果使用 <emphasis role="strong">accountCanonicalForm</emphasis> 3 ,该选项必需并是个完全对应 <emphasis role="strong">accountDomainName</emphasis> 的短名 (例如如果 <emphasis role="strong">accountDomainName</emphasis> 是 <emphasis role="strong">foo.net</emphasis>,一个好的 <emphasis role="strong">accountDomainNameShort</emphasis> 值可能是 <emphasis>FOO</emphasis>)。
  395. </entry>
  396. </row>
  397. </tbody>
  398. </tgroup>
  399. </table>
  400. </para>
  401. </sect3>
  402. </sect2>
  403. </sect1>
  404. <!--
  405. vim:se ts=4 sw=4 et:
  406. -->