Zend_Ldap-Introduction.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- EN-Revision: 16828 -->
  3. <!-- Reviewed: no -->
  4. <sect1 id="zend.ldap.introduction">
  5. <title>Einführung</title>
  6. <para>
  7. <classname>Zend_Ldap</classname> ist eine Klasse, mit der <acronym>LDAP</acronym>
  8. Operationen, wie das Durchsuchen, das Bearbeiten oder die Bindung an Einträge im
  9. <acronym>LDAP</acronym> Verzeichnis, durchgeführt werden können.
  10. </para>
  11. <sect2 id="zend.ldap.introduction.theory-of-operations">
  12. <title>Theorie der Verwendung</title>
  13. <para>
  14. Diese Komponente besteht aus der Hauptklasse <classname>Zend_Ldap</classname> welche
  15. konzeptionell eine Bindung an einen einzelnen <acronym>LDAP</acronym> Server
  16. repräsentiert und die Ausführung von Operationen an diesem <acronym>LDAP</acronym>
  17. Server erlaubt, wie zum Beispiel OpenLDAP oder ActiveDirectory (AD) Server. Die
  18. Parameter für das Binden können explizit oder in der Form eines Options Arrays
  19. angegeben werden. <classname>Zend_Ldap_Node</classname> bietet ein Objektorientiertes
  20. Interface für einen einzelnen <acronym>LDAP</acronym> Node und kann verwendet werden
  21. um eine Basis für ein Active-Record artiges Interface für ein <acronym>LDAP</acronym>
  22. basiertes Domain-Modell zu bieten.
  23. </para>
  24. <para>
  25. Die Komponente bietet verschiedene Helfer Klassen um Operationen auf
  26. <acronym>LDAP</acronym> Einträgen (<classname>Zend_Ldap_Attribute</classname>)
  27. durchzuführen, wie das Setzen und Empfangen von Attributen (Datumswerte, Passwörter,
  28. Boolsche Werte, ...), um <acronym>LDAP</acronym> Filter Strings
  29. (<classname>Zend_Ldap_Filter</classname>) zu Erstellen und zu Ändern, und um
  30. <acronym>LDAP</acronym> Distinguished Names (DN) (<classname>Zend_Ldap_Dn</classname>)
  31. zu manipulieren.
  32. </para>
  33. <para>
  34. Zusätzlich abstrahiert die Komponente das Suchen im <acronym>LDAP</acronym> Schema
  35. für OpenLDAP und ActiveDirectory Server <classname>Zend_Ldap_Node_Schema</classname>
  36. und das empfangen von Server Informationen für OpenLDAP-, ActiveDirectory- und Novell
  37. eDirectory Server (<classname>Zend_Ldap_Node_RootDse</classname>).
  38. </para>
  39. <para>
  40. Die Verwendung der <classname>Zend_Ldap</classname> Klasse hängt vom Typ des
  41. <acronym>LDAP</acronym> Servers ab und wird am besten mit einigen einfachen Beispielen
  42. gezeigt.
  43. </para>
  44. <para>
  45. Wenn man OpenLDAP Verwendet sieht ein einfaches Beispiel wie folgt aus
  46. (es ist zu beachten das die <emphasis>bindRequiresDn</emphasis> Option wichtig ist wenn
  47. man <emphasis>nicht</emphasis> AD verwendet):
  48. </para>
  49. <programlisting language="php"><![CDATA[
  50. $options = array(
  51. 'host' => 's0.foo.net',
  52. 'username' => 'CN=user1,DC=foo,DC=net',
  53. 'password' => 'pass1',
  54. 'bindRequiresDn' => true,
  55. 'accountDomainName' => 'foo.net',
  56. 'baseDn' => 'OU=Sales,DC=foo,DC=net',
  57. );
  58. $ldap = new Zend_Ldap($options);
  59. $acctname = $ldap->getCanonicalAccountName('abaker',
  60. Zend_Ldap::ACCTNAME_FORM_DN);
  61. echo "$acctname\n";
  62. ]]></programlisting>
  63. <para>
  64. Wenn man Microsoft AD verwendet ist ein einfaches Beispiel:
  65. </para>
  66. <programlisting language="php"><![CDATA[
  67. $options = array(
  68. 'host' => 'dc1.w.net',
  69. 'useStartTls' => true,
  70. 'username' => 'user1@w.net',
  71. 'password' => 'pass1',
  72. 'accountDomainName' => 'w.net',
  73. 'accountDomainNameShort' => 'W',
  74. 'baseDn' => 'CN=Users,DC=w,DC=net',
  75. );
  76. $ldap = new Zend_Ldap($options);
  77. $acctname = $ldap->getCanonicalAccountName('bcarter',
  78. Zend_Ldap::ACCTNAME_FORM_DN);
  79. echo "$acctname\n";
  80. ]]></programlisting>
  81. <para>
  82. Es ist zu beachten das die <methodname>getCanonicalAccountName()</methodname> Methode
  83. verwendet wird um den DN Account zu empfangen da jenes das einige ist was das meiste
  84. in diesem kleinen Code zeigt der aktuell in dieser Klasse vorhanden ist.
  85. </para>
  86. <sect3 id="zend.ldap.introduction.theory-of-operations.automatic-username-canonicalization">
  87. <title>Automatische Kanonisierung des Benutzernamens beim Binden</title>
  88. <para>
  89. Wenn <code>bind()</code> mit einem nicht-DN Benutzernamen aufgerufen wird
  90. aber <code>bindRequiresDN</code> <constant>TRUE</constant> ist und kein
  91. Benutzername in DN-Form als Option angegeben wurde, dann wird die Server-Bindung
  92. fehlschlagen. Wenn allerdings ein Benutzername in DN-Form im Optionen-Array
  93. übergeben wurde, wird <classname>Zend_Ldap</classname> sich zuerst mit diesem
  94. Benutzernamen an den Server binden, den Account DN für den Benutzernamen empfangen
  95. der bei <code>bind()</code> angegeben wurde und dann mit diesem zum DN verbinden.
  96. </para>
  97. <para>
  98. Dieses Verhalten ist kritisch für <link
  99. linkend="zend.auth.adapter.ldap"><classname>Zend_Auth_Adapter_Ldap</classname></link>,
  100. welches den vom Benutzer angegebenen Benutzernamen direkt an
  101. <methodname>bind()</methodname> übergibt.
  102. </para>
  103. <para>
  104. Das folgende Beispiel zeigt wie der nicht-DN Benutzername
  105. '<emphasis>abaker</emphasis>' mit <methodname>bind()</methodname> verwendet werden
  106. kann:
  107. </para>
  108. <programlisting language="php"><![CDATA[
  109. $options = array(
  110. 'host' => 's0.foo.net',
  111. 'username' => 'CN=user1,DC=foo,DC=net',
  112. 'password' => 'pass1',
  113. 'bindRequiresDn' => true,
  114. 'accountDomainName' => 'foo.net',
  115. 'baseDn' => 'OU=Sales,DC=foo,DC=net',
  116. );
  117. $ldap = new Zend_Ldap($options);
  118. $ldap->bind('abaker', 'moonbike55');
  119. $acctname = $ldap->getCanonicalAccountName('abaker',
  120. Zend_Ldap::ACCTNAME_FORM_DN);
  121. echo "$acctname\n";
  122. ]]></programlisting>
  123. <para>
  124. Der Aufruf von <methodname>bind()</methodname> in diesem Beispiel sieht das der
  125. Benutzer '<emphasis>abaker</emphasis>' nicht in DN Form ist, findet das
  126. <emphasis>bindRequiresDn</emphasis> <constant>TRUE</constant> ist, verwendet
  127. '<command>CN=user1,DC=foo,DC=net</command>' und '<emphasis>pass1</emphasis>' um zu
  128. Binden, empfängt den DN für '<emphasis>abaker</emphasis>', entbindet und Bindet
  129. dann nochmals mit dem neu erkannten
  130. '<command>CN=Alice Baker,OU=Sales,DC=foo,DC=net</command>'.
  131. </para>
  132. </sect3>
  133. <sect3 id="zend.ldap.introduction.theory-of-operations.account-name-canonicalization">
  134. <title>Kanonisierung des Account Namens</title>
  135. <para>
  136. Die Optionen <emphasis>accountDomainName</emphasis> und
  137. <emphasis>accountDomainNameShort</emphasis> werden für zwei Zwecke verwendet:
  138. (1) bieten Sie multi-Domain Authentifizierung und Failover Möglichkeiten, und
  139. (2) werden Sie auch verwendet um Benutzernamen zu kanonisieren. Speziell Namen
  140. werden in die Form kanonisiert die in der <emphasis>accountCanonicalForm</emphasis>
  141. Option spezifiziert ist. Diese Option kann einen der folgenden Werte enthalten:
  142. </para>
  143. <table id="zend.ldap.using.theory-of-operation.account-name-canonicalization.table">
  144. <title>Optionen für accountCanonicalForm</title>
  145. <tgroup cols="3">
  146. <thead>
  147. <row>
  148. <entry>Name</entry>
  149. <entry>Wert</entry>
  150. <entry>Beispiel</entry>
  151. </row>
  152. </thead>
  153. <tbody>
  154. <row>
  155. <entry>
  156. <constant>ACCTNAME_FORM_DN</constant>
  157. </entry>
  158. <entry>1</entry>
  159. <entry>CN=Alice Baker,CN=Users,DC=example,DC=com</entry>
  160. </row>
  161. <row>
  162. <entry>
  163. <constant>ACCTNAME_FORM_USERNAME</constant>
  164. </entry>
  165. <entry>2</entry>
  166. <entry>abaker</entry>
  167. </row>
  168. <row>
  169. <entry>
  170. <constant>ACCTNAME_FORM_BACKSLASH</constant>
  171. </entry>
  172. <entry>3</entry>
  173. <entry>EXAMPLE\abaker</entry>
  174. </row>
  175. <row>
  176. <entry>
  177. <constant>ACCTNAME_FORM_PRINCIPAL</constant>
  178. </entry>
  179. <entry>4</entry>
  180. <entry><filename>abaker@example.com</filename></entry>
  181. </row>
  182. </tbody>
  183. </tgroup>
  184. </table>
  185. <para>
  186. Die Standardmäßige Kanonisierung hängt davon ab welche Optionen für Account Domain
  187. Namen angegeben wurden. Wenn <emphasis>accountDomainNameShort</emphasis> angegeben
  188. wurde, ist der Standardwert von <emphasis>accountCanonicalForm</emphasis>
  189. <constant>ACCTNAME_FORM_BACKSLASH</constant>. Andernfall, wenn
  190. <emphasis>accountDomainName</emphasis> angegeben wurde, ist der Standardwert
  191. <constant>ACCTNAME_FORM_PRINCIPAL</constant>.
  192. </para>
  193. <para>
  194. Die Kanonisierung des Account Namens stellt sicher das der String der zur
  195. Identifikation des Accounts verwendet wird konsistent ist, unabhängig davon was an
  196. <methodname>bind()</methodname> übergeben wurde. Wenn der Benutzer, zum Beispiel,
  197. den Account Namen <filename>abaker@example.com</filename> oder nur
  198. <emphasis>abaker</emphasis> angibt, und <emphasis>accountCanonicalForm</emphasis>
  199. auf 3 gesetzt ist, wird der resultierende kanonisierte Name
  200. <emphasis>EXAMPLE\abaker</emphasis> sein.
  201. </para>
  202. </sect3>
  203. <sect3 id="zend.ldap.introduction.theory-of-operations.multi-domain-failover">
  204. <title>Multi-domain Authentication and Failover</title>
  205. <para>
  206. The <classname>Zend_Ldap</classname> component by itself makes no attempt
  207. to authenticate with multiple servers. However, <classname>Zend_Ldap</classname>
  208. is specifically designed to handle this scenario gracefully. The
  209. required technique is to simply iterate over an array of arrays of serve
  210. options and attempt to bind with each server. As described above
  211. <methodname>bind()</methodname> will automatically canonicalize each name, so
  212. it does not matter if the user passes <filename>abaker@foo.net</filename> or
  213. <emphasis>W\bcarter</emphasis> or <emphasis>cdavis</emphasis> - the
  214. <methodname>bind()</methodname> method will only succeed if the credentials were
  215. successfully used in the bind.
  216. </para>
  217. <para>
  218. Consider the following example that illustrates the technique required to
  219. implement multi-domain authentication and failover:
  220. </para>
  221. <programlisting language="php"><![CDATA[
  222. $acctname = 'W\\user2';
  223. $password = 'pass2';
  224. $multiOptions = array(
  225. 'server1' => array(
  226. 'host' => 's0.foo.net',
  227. 'username' => 'CN=user1,DC=foo,DC=net',
  228. 'password' => 'pass1',
  229. 'bindRequiresDn' => true,
  230. 'accountDomainName' => 'foo.net',
  231. 'accountDomainNameShort' => 'FOO',
  232. 'accountCanonicalForm' => 4, // ACCT_FORM_PRINCIPAL
  233. 'baseDn' => 'OU=Sales,DC=foo,DC=net',
  234. ),
  235. 'server2' => array(
  236. 'host' => 'dc1.w.net',
  237. 'useSsl' => true,
  238. 'username' => 'user1@w.net',
  239. 'password' => 'pass1',
  240. 'accountDomainName' => 'w.net',
  241. 'accountDomainNameShort' => 'W',
  242. 'accountCanonicalForm' => 4, // ACCT_FORM_PRINCIPAL
  243. 'baseDn' => 'CN=Users,DC=w,DC=net',
  244. ),
  245. );
  246. $ldap = new Zend_Ldap();
  247. foreach ($multiOptions as $name => $options) {
  248. echo "Trying to bind using server options for '$name'\n";
  249. $ldap->setOptions($options);
  250. try {
  251. $ldap->bind($acctname, $password);
  252. $acctname = $ldap->getCanonicalAccountName($acctname);
  253. echo "SUCCESS: authenticated $acctname\n";
  254. return;
  255. } catch (Zend_Ldap_Exception $zle) {
  256. echo ' ' . $zle->getMessage() . "\n";
  257. if ($zle->getCode() === Zend_Ldap_Exception::LDAP_X_DOMAIN_MISMATCH) {
  258. continue;
  259. }
  260. }
  261. }
  262. ]]></programlisting>
  263. <para>
  264. If the bind fails for any reason, the next set of server options is tried.
  265. </para>
  266. <para>
  267. The <methodname>getCanonicalAccountName()</methodname> call gets the canonical
  268. account name that the application would presumably use to associate data with such
  269. as preferences. The <emphasis>accountCanonicalForm = 4</emphasis> in all server
  270. options ensures that the canonical form is consistent regardless of which
  271. server was ultimately used.
  272. </para>
  273. <para>
  274. The special <constant>LDAP_X_DOMAIN_MISMATCH</constant> exception occurs when an
  275. account name with a domain component was supplied (e.g.,
  276. <filename>abaker@foo.net</filename> or <emphasis>FOO\abaker</emphasis> and not just
  277. <emphasis>abaker</emphasis>) but the domain component did not match either domain
  278. in the currently selected server options. This exception indicates
  279. that the server is not an authority for the account. In this
  280. case, the bind will not be performed, thereby eliminating unnecessary
  281. communication with the server. Note that the <emphasis>continue</emphasis>
  282. instruction has no effect in this example, but in practice for error handling and
  283. debugging purposes, you will probably want to check for
  284. <constant>LDAP_X_DOMAIN_MISMATCH</constant> as well as
  285. <constant>LDAP_NO_SUCH_OBJECT</constant> and
  286. <constant>LDAP_INVALID_CREDENTIALS</constant>.
  287. </para>
  288. <para>
  289. The above code is very similar to code used within <link
  290. linkend="zend.auth.adapter.ldap"><classname>Zend_Auth_Adapter_Ldap</classname></link>.
  291. In fact, we recommend that you simply use that authentication adapter for
  292. multi-domain + failover <acronym>LDAP</acronym> based authentication
  293. (or copy the code).
  294. </para>
  295. </sect3>
  296. </sect2>
  297. </sect1>