{"id":699,"date":"2017-09-20T20:53:56","date_gmt":"2017-09-20T12:53:56","guid":{"rendered":"http:\/\/www.xiaobo.li\/?p=699"},"modified":"2019-04-04T23:27:19","modified_gmt":"2019-04-04T15:27:19","slug":"ldap-%e5%bf%ab%e9%80%9f%e5%85%a5%e9%97%a8","status":"publish","type":"post","link":"https:\/\/www.xiaobo.li\/notes\/archives\/699","title":{"rendered":"LDAP"},"content":{"rendered":"<h3>1. LDAP\u7b80\u4ecb<\/h3>\n<p>LDAP\uff08\u8f7b\u91cf\u7ea7\u76ee\u5f55\u8bbf\u95ee\u534f\u8bae\uff0cLightweight Directory Access Protocol)\u662f\u5b9e\u73b0\u63d0\u4f9b\u88ab\u79f0\u4e3a\u76ee\u5f55\u670d\u52a1\u7684\u4fe1\u606f\u670d\u52a1\u3002\u76ee\u5f55\u670d\u52a1\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u6570\u636e\u5e93\u7cfb\u7edf\uff0c\u5176\u4e13\u95e8\u9488\u5bf9\u8bfb\u53d6\uff0c\u6d4f\u89c8\u548c\u641c\u7d22\u64cd\u4f5c\u8fdb\u884c\u4e86\u7279\u5b9a\u7684\u4f18\u5316\u3002\u76ee\u5f55\u4e00\u822c\u7528\u6765\u5305\u542b\u63cf\u8ff0\u6027\u7684\uff0c\u57fa\u4e8e\u5c5e\u6027\u7684\u4fe1\u606f\u5e76\u652f\u6301\u7cbe\u7ec6\u590d\u6742\u7684\u8fc7\u6ee4\u80fd\u529b\u3002\u76ee\u5f55\u4e00\u822c\u4e0d\u652f\u6301\u901a\u7528\u6570\u636e\u5e93\u9488\u5bf9\u5927\u91cf\u66f4\u65b0\u64cd\u4f5c\u64cd\u4f5c\u9700\u8981\u7684\u590d\u6742\u7684\u4e8b\u52a1\u7ba1\u7406\u6216\u56de\u5377\u7b56\u7565\u3002\u800c\u76ee\u5f55\u670d\u52a1\u7684\u66f4\u65b0\u5219\u4e00\u822c\u90fd\u975e\u5e38\u7b80\u5355\u3002\u8fd9\u79cd\u76ee\u5f55\u53ef\u4ee5\u5b58\u50a8\u5305\u62ec\u4e2a\u4eba\u4fe1\u606f\u3001web\u94fe\u7ed3\u3001jpeg\u56fe\u50cf\u7b49\u5404\u79cd\u4fe1\u606f\u3002\u4e3a\u4e86\u8bbf\u95ee\u5b58\u50a8\u5728\u76ee\u5f55\u4e2d\u7684\u4fe1\u606f\uff0c\u5c31\u9700\u8981\u4f7f\u7528\u8fd0\u884c\u5728TCP\/IP \u4e4b\u4e0a\u7684\u8bbf\u95ee\u534f\u8bae\u2014LDAP\u3002<\/p>\n<p>LDAP\u76ee\u5f55\u4e2d\u7684\u4fe1\u606f\u662f\u662f\u6309\u7167\u6811\u578b\u7ed3\u6784\u7ec4\u7ec7\uff0c\u5177\u4f53\u4fe1\u606f\u5b58\u50a8\u5728\u6761\u76ee(entry)\u7684\u6570\u636e\u7ed3\u6784\u4e2d\u3002\u6761\u76ee\u76f8\u5f53\u4e8e\u5173\u7cfb\u6570\u636e\u5e93\u4e2d\u8868\u7684\u8bb0\u5f55\uff1b\u6761\u76ee\u662f\u5177\u6709\u533a\u522b\u540dDN \uff08Distinguished Name\uff09\u7684\u5c5e\u6027\uff08Attribute\uff09\uff0cDN\u662f\u7528\u6765\u5f15\u7528\u6761\u76ee\u7684\uff0cDN\u76f8\u5f53\u4e8e\u5173\u7cfb\u6570\u636e\u5e93\u8868\u4e2d\u7684\u5173\u952e\u5b57\uff08Primary Key\uff09\u3002\u5c5e\u6027\u7531\u7c7b\u578b\uff08Type\uff09\u548c\u4e00\u4e2a\u6216\u591a\u4e2a\u503c\uff08Values\uff09\u7ec4\u6210\uff0c\u76f8\u5f53\u4e8e\u5173\u7cfb\u6570\u636e\u5e93\u4e2d\u7684\u5b57\u6bb5\uff08Field\uff09\u7531\u5b57\u6bb5\u540d\u548c\u6570\u636e\u7c7b\u578b\u7ec4\u6210\uff0c\u53ea\u662f\u4e3a\u4e86\u65b9\u4fbf\u68c0\u7d22\u7684\u9700\u8981\uff0cLDAP\u4e2d\u7684Type\u53ef\u4ee5\u6709\u591a\u4e2aValue\uff0c\u800c\u4e0d\u662f\u5173\u7cfb\u6570\u636e\u5e93\u4e2d\u4e3a\u964d\u4f4e\u6570\u636e\u7684\u5197\u4f59\u6027\u8981\u6c42\u5b9e\u73b0\u7684\u5404\u4e2a\u57df\u5fc5\u987b\u662f\u4e0d\u76f8\u5173\u7684\u3002LDAP\u4e2d\u6761\u76ee\u7684\u7ec4\u7ec7\u4e00\u822c\u6309\u7167\u5730\u7406\u4f4d\u7f6e\u548c\u7ec4\u7ec7\u5173\u7cfb\u8fdb\u884c\u7ec4\u7ec7\uff0c\u975e\u5e38\u7684\u76f4\u89c2\u3002LDAP\u628a\u6570\u636e\u5b58\u653e\u5728\u6587\u4ef6\u4e2d\uff0c\u4e3a\u63d0\u9ad8\u6548\u7387\u53ef\u4ee5\u4f7f\u7528\u57fa\u4e8e\u7d22\u5f15\u7684\u6587\u4ef6\u6570\u636e\u5e93\uff0c\u800c\u4e0d\u662f\u5173\u7cfb\u6570\u636e\u5e93\u3002\u7c7b\u578b\u7684\u4e00\u4e2a\u4f8b\u5b50\u5c31\u662fmail\uff0c\u5176\u503c\u5c06\u662f\u4e00\u4e2a\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u3002<\/p>\n<p>LDAP\u7684\u4fe1\u606f\u662f\u4ee5\u6811\u578b\u7ed3\u6784\u5b58\u50a8\u7684\uff0c\u5728\u6811\u6839\u4e00\u822c\u5b9a\u4e49\u56fd\u5bb6(c=CN)\u6216\u57df\u540d(dc=com)\uff0c\u5728\u5176\u4e0b\u5219\u5f80\u5f80\u5b9a\u4e49\u4e00\u4e2a\u6216\u591a\u4e2a\u7ec4\u7ec7 (organization)(o=Acme)\u6216\u7ec4\u7ec7\u5355\u5143(organizational units) (ou=People)\u3002\u4e00\u4e2a\u7ec4\u7ec7\u5355\u5143\u53ef\u80fd\u5305\u542b\u8bf8\u5982\u6240\u6709\u96c7\u5458\u3001\u5927\u697c\u5185\u7684\u6240\u6709\u6253\u5370\u673a\u7b49\u4fe1\u606f\u3002\u6b64\u5916\uff0cLDAP\u652f\u6301\u5bf9\u6761\u76ee\u80fd\u591f\u548c\u5fc5\u987b\u652f\u6301\u54ea\u4e9b\u5c5e\u6027\u8fdb\u884c\u63a7\u5236\uff0c\u8fd9\u662f\u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u79f0\u4e3a\u5bf9\u8c61\u7c7b\u522b(objectClass)\u7684\u5c5e\u6027\u6765\u5b9e\u73b0\u7684\u3002\u8be5\u5c5e\u6027\u7684\u503c\u51b3\u5b9a\u4e86\u8be5\u6761\u76ee\u5fc5\u987b\u9075\u5faa\u7684\u4e00\u4e9b\u89c4\u5219\uff0c\u5176\u89c4\u5b9a\u4e86\u8be5\u6761\u76ee\u80fd\u591f\u53ca\u81f3\u5c11\u5e94\u8be5\u5305\u542b\u54ea\u4e9b\u5c5e\u6027\u3002\u4f8b\u5982\uff1ainetorgPerson\u5bf9\u8c61\u7c7b\u9700\u8981\u652f\u6301sn(surname)\u548ccn(common name)\u5c5e\u6027\uff0c\u4f46\u4e5f\u53ef\u4ee5\u5305\u542b\u53ef\u9009\u7684\u5982\u90ae\u4ef6\uff0c\u7535\u8bdd\u53f7\u7801\u7b49\u5c5e\u6027\u3002<\/p>\n<h3>2. LDAP\u7b80\u79f0\u5bf9\u5e94<\/h3>\n<p>o\u2013 organization\uff08\u7ec4\u7ec7-\u516c\u53f8\uff09<br \/>\nou \u2013 organization unit\uff08\u7ec4\u7ec7\u5355\u5143-\u90e8\u95e8\uff09<br \/>\nc - countryName\uff08\u56fd\u5bb6\uff09<br \/>\ndc - domainComponent\uff08\u57df\u540d\uff09<br \/>\nsn \u2013 suer name\uff08\u771f\u5b9e\u540d\u79f0\uff09<br \/>\ncn - common name\uff08\u5e38\u7528\u540d\u79f0\uff09<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1654 size-full\" src=\"https:\/\/www.xiaobo.li\/notes\/wp-content\/uploads\/2019\/04\/1111.png\" alt=\"\" width=\"471\" height=\"126\" srcset=\"https:\/\/www.xiaobo.li\/notes\/wp-content\/uploads\/2019\/04\/1111.png 471w, https:\/\/www.xiaobo.li\/notes\/wp-content\/uploads\/2019\/04\/1111-300x80.png 300w\" sizes=\"auto, (max-width: 471px) 100vw, 471px\" \/><\/p>\n<h3>3. \u76ee\u5f55\u8bbe\u8ba1<\/h3>\n<p>\u8bbe\u8ba1\u76ee\u5f55\u7ed3\u6784\u662fLDAP\u6700\u91cd\u8981\u7684\u65b9\u9762\u4e4b\u4e00\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u901a\u8fc7\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\u6765\u8bf4\u660e\u5982\u4f55\u8bbe\u8ba1\u5408\u7406\u7684\u76ee\u5f55\u7ed3\u6784\u3002\u8be5\u4f8b\u5b50\u5c06\u901a\u8fc7Netscape\u5730\u5740\u8584\u6765\u8bbf\u6587\u3002\u5047\u8bbe\u6709\u4e00\u4e2a\u4f4d\u4e8e\u7f8e\u56fdUS(c=US)\u800c\u4e14\u8de8\u8d8a\u591a\u4e2a\u5dde\u7684\u540d\u4e3aAcme(o=Acme)\u7684\u516c\u53f8\u3002Acme\u5e0c\u671b\u4e3a\u6240\u6709\u7684\u96c7\u5458\u5b9e\u73b0\u4e00\u4e2a\u5c0f\u578b\u7684\u5730\u5740\u8584\u670d\u52a1\u5668\u3002<\/p>\n<p>\u6211\u4eec\u4ece\u4e00\u4e2a\u7b80\u5355\u7684\u7ec4\u7ec7DN\u5f00\u59cb\uff1a<\/p>\n<p>dn: o=Acme, c=US<\/p>\n<p>Acme\u6240\u6709\u7684\u7ec4\u7ec7\u5206\u7c7b\u548c\u5c5e\u6027\u5c06\u5b58\u50a8\u5728\u8be5DN\u4e4b\u4e0b\uff0c\u8fd9\u4e2aDN\u5728\u8be5\u5b58\u50a8\u5728\u8be5\u670d\u52a1\u5668\u7684\u76ee\u5f55\u662f\u552f\u4e00\u7684\u3002Acme\u5e0c\u671b\u5c06\u5176\u96c7\u5458\u7684\u4fe1\u606f\u5206\u4e3a\u4e24\u7c7b\uff1a\u7ba1\u7406\u8005(ou= Managers)\u548c\u666e\u901a\u96c7\u5458(ou=Employees),\u8fd9\u79cd\u5206\u7c7b\u4ea7\u751f\u7684\u76f8\u5bf9\u533a\u522b\u540d(RDN,relative distinguished names\u3002\u8868\u793a\u76f8\u5bf9\u4e8e\u9876\u70b9DN)\u5c31shi \uff1a<\/p>\n<p>dn: ou=Managers, o=Acme, c=US<br \/>\ndn: ou=Employees, o=Acme, c=US<\/p>\n<p>\u5728\u4e0b\u9762\u6211\u4eec\u5c06\u4f1a\u770b\u5230\u5206\u5c42\u7ed3\u6784\u7684\u7ec4\u6210\uff1a\u9876\u70b9\u662fUS\u7684Acme\uff0c\u4e0b\u9762\u662f\u7ba1\u7406\u8005\u7ec4\u7ec7\u5355\u5143\u548c\u96c7\u5458\u7ec4\u7ec7\u5355\u5143\u3002\u56e0\u6b64\u5305\u62ecManagers\u548cEmployees\u7684DN\u7ec4\u6210\u4e3a\uff1a<\/p>\n<p>dn: cn=Jason H. Smith, ou=Managers, o=Acme, c=US<br \/>\ndn: cn=Ray D. Jones, ou=Employees, o=Acme, c=US<br \/>\ndn: cn=Eric S. Woods, ou=Employees, o=Acme, c=US<\/p>\n<p>\u4e3a\u4e86\u5f15\u7528Jason H. Smith\u7684\u901a\u7528\u540d(common name )\u6761\u76ee\uff0cLDAP\u5c06\u91c7<br \/>\n\u7528cn=Jason H. Smith\u7684RDN\u3002<br \/>\n\u7136\u540e\u5c06\u524d\u9762\u7684\u7236\u6761\u76ee\u7ed3\u5408\u5728\u4e00\u8d77\u5c31\u5f62\u6210\u5982\u4e0b\u7684\u6811\u578b\u7ed3\u6784\uff1a<\/p>\n<p>cn=Jason H. Smith<br \/>\n+ ou=Managers<br \/>\n+ o=Acme<br \/>\n+ c=US<br \/>\n-&gt; dn: cn=Jason H. Smith,ou=Managers,o=Acme,c=US<\/p>\n<p>\u73b0\u5728\u5df2\u7ecf\u5b9a\u4e49\u597d\u4e86\u76ee\u5f55\u7ed3\u6784\uff0c\u4e0b\u4e00\u6b65\u5c31\u9700\u8981\u5bfc\u5165\u76ee\u5f55\u4fe1\u606f\u6570\u636e\u3002\u76ee\u5f55\u4fe1\u606f\u6570\u636e\u5c06\u88ab\u5b58\u653e\u5728LDIF\u6587\u4ef6\u4e2d\uff0c\u5176\u662f\u5bfc\u5165\u76ee\u5f55\u4fe1\u606f\u6570\u636e\u7684\u9ed8\u8ba4\u5b58\u653e\u6587\u4ef6\u3002\u7528\u6237\u53ef\u4ee5\u65b9\u4fbf\u7684\u7f16\u5199Perl\u811a\u672c\u6765\u4ece\u4f8b\u5982\/etc\/passwd\u3001NIS\u7b49\u7cfb\u7edf\u6587\u4ef6\u4e2d\u81ea\u52a8\u521b\u5efaLDIF\u6587\u4ef6\u3002<\/p>\n<p>\u4e0b\u9762\u7684\u5b9e\u4f8b\u4fdd\u5b58\u76ee\u5f55\u4fe1\u606f\u6570\u636e\u4e3atestdate.ldif\u6587\u4ef6\uff0c\u8be5\u6587\u4ef6\u7684\u683c\u5f0f\u8bf4\u660e\u5c06\u53ef\u4ee5\u5728man ldif\u4e2d\u5f97\u5230\u3002<\/p>\n<p>\u5728\u6dfb\u52a0\u4efb\u4f55\u7ec4\u7ec7\u5355\u5143\u4ee5\u524d\uff0c\u5fc5\u987b\u9996\u5148\u5b9a\u4e49Acme DN\uff1a<\/p>\n<p>dn: o=Acme, c=US,<br \/>\nobjectClass: organization<\/p>\n<p>\u8fd9\u91cco\u5c5e\u6027\u662f\u5fc5\u987b\u7684<\/p>\n<p>o: Acme<\/p>\n<p>\u4e0b\u9762\u662f\u7ba1\u7406\u7ec4\u5355\u5143\u7684DN\uff0c\u5728\u6dfb\u52a0\u4efb\u4f55\u7ba1\u7406\u8005\u4fe1\u606f\u4ee5\u524d\uff0c\u5fc5\u987b\u5148\u5b9a\u4e49\u8be5\u6761\u76ee\u3002<\/p>\n<p>dn: ou=Managers, o=Acme, c=US<br \/>\nobjectClass: organizationalUnit<\/p>\n<p>\u8fd9\u91ccou\u5c5e\u6027\u662f\u5fc5\u987b\u7684\u3002<\/p>\n<p>ou: Managers<\/p>\n<p>\u7b2c\u4e00\u4e2a\u7ba1\u7406\u8005DN\uff1a<\/p>\n<p>dn: cn=Jason H. Smith, ou=Managers, o=Acme, c=US<br \/>\nobjectClass: inetOrgPerson<\/p>\n<p>cn\u548csn\u90fd\u662f\u5fc5\u987b\u7684\u5c5e\u6027\uff1a<\/p>\n<p>cn: Jason H. Smith<br \/>\nsn: Smith<\/p>\n<p>\u4f46\u662f\u8fd8\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e9b\u53ef\u9009\u7684\u5c5e\u6027\uff1a<\/p>\n<p>telephoneNumber: 111-222-9999<br \/>\nmail: headhauncho@acme.com<br \/>\nlocalityName: Houston<\/p>\n<p>\u53ef\u4ee5\u5b9a\u4e49\u53e6\u5916\u4e00\u4e2a\u7ec4\u7ec7\u5355\u5143\uff1a<\/p>\n<p>dn: ou=Employees, o=Acme, c=US<br \/>\nobjectClass: organizationalUnit<br \/>\nou: Employees<\/p>\n<p>\u5e76\u6dfb\u52a0\u96c7\u5458\u4fe1\u606f\u5982\u4e0b\uff1a<\/p>\n<p>dn: cn=Ray D. Jones, ou=Employees, o=Acme, c=US<br \/>\nobjectClass: inetOrgPerson<br \/>\ncn: Ray D. Jones<br \/>\nsn: Jones<br \/>\ntelephoneNumber: 444-555-6767<br \/>\nmail: jonesrd@acme.com<br \/>\nlocalityName: Houston<br \/>\ndn: cn=Eric S. Woods, ou=Employees, o=Acme, c=US<br \/>\nobjectClass: inetOrgPerson<br \/>\ncn: Eric S. Woods<br \/>\nsn: Woods<br \/>\ntelephoneNumber: 444-555-6768<br \/>\nmail: woodses@acme.com<br \/>\nlocalityName: Houston<\/p>\n<h3>4. \u914d\u7f6eOpenLDAP<\/h3>\n<p>\u672c\u6587\u5b9e\u8df5\u4e86\u5728 Windows \u4e0b\u5b89\u88c5\u914d openldap\uff0c\u5e76\u6dfb\u52a0\u4e00\u4e2a\u6761\u76ee\uff0cLdapBrowser \u6d4f\u89c8\uff0c\u53ca Java \u7a0b\u5e8f\u8fde\u63a5 openldap \u7684\u5168\u8fc7\u7a0b\u3002<\/p>\n<p>1. \u4e0b\u8f7d\u5b89\u88c5 <b>openldap<\/b> for windows\uff0c\u5f53\u524d\u7248\u672c2.2.29\u4e0b\u8f7d\u5730\u5740\uff1ahttp:\/\/download.bergmans.us\/openldap\/openldap-2.2.29\/openldap-2.2.29-db-4.3.29-openssl-0.9.8a-win32_Setup.exe<\/p>\n<p>\u76f8\u5173\u94fe\u63a5\uff1ahttp:\/\/lucas.bergmans.us\/hacks\/openldap\/<br \/>\n\u5b89\u88c5\u5f88\u7b80\u5355\uff0c\u4e00\u8def next \u5373\u53ef\uff0c\u5047\u8bbe\u6211\u4eec\u5b89\u88c5\u5728 c:\\openldap<\/p>\n<p>2. \u914d\u7f6e openldap\uff0c\u7f16\u8f91 sldap.conf \u6587\u4ef6<\/p>\n<p>1) \u6253\u5f00 c:\\openldap\\sldap.conf\uff0c\u627e\u5230<br \/>\ninclude\u00a0 C:\/openldap\/etc\/schema\/core.schema\uff0c\u5728\u5b83\u540e\u9762\u6dfb\u52a0<br \/>\ninclude\u00a0 C:\/openldap\/etc\/schema\/cosine.schema<br \/>\ninclude\u00a0 C:\/openldap\/etc\/schema\/inetorgperson.schema<\/p>\n<p>\u63a5\u4e0b\u6765\u7684\u4f8b\u5b50\u53ea\u9700\u8981\u7528\u5230\u4ee5\u4e0a\u4e09\u4e2a schema\uff0c\u5f53\u7136\uff0c\u5982\u679c\u4f60\u89c9\u5f97\u9700\u8981\u7684\u8bdd\uff0c\u4f60\u53ef\u4ee5\u628a\u5176\u4ed6\u7684 schema \u5168\u90e8\u6dfb\u52a0\u8fdb\u6765<br \/>\ninclude\u00a0 C:\/openldap\/etc\/schema\/corba.schema<br \/>\ninclude\u00a0 C:\/openldap\/etc\/schema\/dyngroup.schema<br \/>\ninclude\u00a0 C:\/openldap\/etc\/schema\/java.schema<br \/>\ninclude\u00a0 C:\/openldap\/etc\/schema\/misc.schema<br \/>\ninclude\u00a0 C:\/openldap\/etc\/schema\/nis.schema<br \/>\ninclude\u00a0 C:\/openldap\/etc\/schema\/openldap.schema<\/p>\n<p>2) \u8fd8\u662f\u5728 sldap.conf \u6587\u4ef6\u4e2d\uff0c\u627e\u5230<\/p>\n<p>suffix\u00a0 \"dc=my-domain,dc=com\"<br \/>\nrootdn\u00a0 \"cn=Manager,dc=my-domain,dc=com\"<\/p>\n<p>\u628a\u8fd9\u4e24\u884c\u6539\u4e3a<br \/>\nsuffix \"o=teemlink,c=cn\"<br \/>\nrootdn \"cn=Manager,o=teemlink,dc=cn\"<\/p>\n<p>suffix \u5c31\u662f\u770b\u81ea\u5df1\u5982\u4f55\u5b9a\u4e49\u4e86\uff0c\u540e\u9762\u6b65\u9aa4\u7684 ldif \u6587\u4ef6\u5c31\u5fc5\u987b\u4e0e\u5b83\u5b9a\u4e49\u4e86\u3002\u8fd8\u8981\u6ce8\u610f\u5230\u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\u4e2d\u6709\u4e00\u4e2a rootpw\u00a0 secret\uff0c\u8fd9\u4e2a secret \u662f cn=Manager \u7684\u5bc6\u7801\uff0c\u4ee5\u540e\u4f1a\u7528\u5230\uff0c\u4e0d\u8fc7\u8fd9\u91cc\u662f\u660e\u6587\u5bc6\u7801\uff0c\u4f60\u53ef\u4ee5\u7528\u547d\u4ee4\uff1a slappasswd -h {MD5} -s secret \u7b97\u51fa\u52a0\u5bc6\u7684\u5bc6\u7801 {MD5}Xr4ilOzQ4PCOq3aQ0qbuaQ== \u53d6\u4ee3\u914d\u7f6e\u4e2d\u7684 secret\u3002<\/p>\n<p>3. \u542f\u52a8 openldap<\/p>\n<p>CMD \u8fdb\u5165\u5230 c:\\openldap \u4e0b\uff0c\u8fd0\u884c\u547d\u4ee4 sldapd -d 1<br \/>\n\u7528\u53ef\u4ee5\u770b\u5230\u63a7\u5236\u53f0\u4e0b\u6253\u5370\u4e00\u7247\u4fe1\u606f\uff0copenldap \u9ed8\u8ba4\u662f\u7528\u7684 Berkeley DB \u6570\u636e\u5e93\u5b58\u50a8\u76ee\u5f55\u6570\u636e\u7684\u3002<\/p>\n<p>4. \u5efa\u7acb\u6761\u76ee,\u7f16\u8f91\u5bfc\u5165 ldif \u6587\u4ef6<\/p>\n<p>1) \u65b0\u5efa\u4e00\u4e2a ldif(LDAP Data Interchanged Format) \u6587\u4ef6(\u7eaf\u6587\u672c\u683c\u5f0f)\uff0c\u4f8b\u5982 test.ldif\uff0c\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<p>dn: o=teemlink<br \/>\nobjectclass: top<br \/>\nobjectclass: organization<br \/>\no: develop<\/p>\n<p>2) \u6267\u884c\u547d\u4ee4\uff1aldapadd -l test.ldif<\/p>\n<p>5. \u4f7f\u7528LDAP Browser\u8fdb\u884c\u8bbf\u95ee<br \/>\n5.1\u5b89\u88c5LDAP Browser2.6\u8f6f\u4ef6\uff0c\u8fdb\u884c\u5982\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-702 size-full\" src=\"https:\/\/www.xiaobo.li\/notes\/wp-content\/uploads\/2017\/09\/3.jpg\" alt=\"\" width=\"370\" height=\"428\" srcset=\"https:\/\/www.xiaobo.li\/notes\/wp-content\/uploads\/2017\/09\/3.jpg 370w, https:\/\/www.xiaobo.li\/notes\/wp-content\/uploads\/2017\/09\/3-259x300.jpg 259w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-701 size-full\" src=\"https:\/\/www.xiaobo.li\/notes\/wp-content\/uploads\/2017\/09\/2.jpg\" alt=\"\" width=\"360\" height=\"369\" srcset=\"https:\/\/www.xiaobo.li\/notes\/wp-content\/uploads\/2017\/09\/2.jpg 360w, https:\/\/www.xiaobo.li\/notes\/wp-content\/uploads\/2017\/09\/2-293x300.jpg 293w\" sizes=\"auto, (max-width: 360px) 100vw, 360px\" \/><\/p>\n<p>5.2\u663e\u793a\u6548\u679c<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-700 size-full\" src=\"https:\/\/www.xiaobo.li\/notes\/wp-content\/uploads\/2017\/09\/1.jpg\" alt=\"\" width=\"626\" height=\"262\" srcset=\"https:\/\/www.xiaobo.li\/notes\/wp-content\/uploads\/2017\/09\/1.jpg 626w, https:\/\/www.xiaobo.li\/notes\/wp-content\/uploads\/2017\/09\/1-300x126.jpg 300w\" sizes=\"auto, (max-width: 626px) 100vw, 626px\" \/><\/p>\n<h1>5. Java\u64cd\u4f5cLDAP<\/h1>\n<p>5.1 \u7528JNDI\u8fdb\u8bbf\u95ee<\/p>\n<pre class=\"brush:java; toolbar: true; auto-links: true;\">package cn.myapps.test;\n\nimport java.util.Hashtable;\nimport javax.naming.Context;\nimport javax.naming.NamingException;\nimport javax.naming.directory.Attributes;\nimport javax.naming.directory.DirContext;\nimport javax.naming.directory.InitialDirContext;\n\npublic class LdapTest {\n    public void JNDILookup() {\n        String root = \"o=teemlink,c=cn\";\n        Hashtable env = new Hashtable();\n        env.put(Context.INITIAL_CONTEXT_FACTORY, \"com.sun.jndi.ldap.LdapCtxFactory\");\n        env.put(Context.PROVIDER_URL, \"ldap:\/\/192.168.0.30\/\" + root);\n        env.put(Context.SECURITY_AUTHENTICATION, \"simple\");\n        env.put(Context.SECURITY_PRINCIPAL, \"cn=Nicholas,ou=\u4ea7\u54c1,o=teemlink,c=cn\");\n        env.put(Context.SECURITY_CREDENTIALS, \"123456\");\n        DirContext ctx = null;\n\n        try {\n            ctx = new InitialDirContext(env);\n            Attributes attrs = ctx.getAttributes(\"cn=Nicholas,ou=\u4ea7\u54c1\");\n            System.out.println(\"Last Name: \" + attrs.get(\"sn\").get());\n            System.out.println(\"\u8ba4\u8bc1\u6210\u529f\");\n        } catch (javax.naming.AuthenticationException e) {\n            e.printStackTrace();\n            System.out.println(\"\u8ba4\u8bc1\u5931\u8d25\");\n        } catch (Exception e) {\n            System.out.println(\"\u8ba4\u8bc1\u51fa\u9519\uff1a\");\n            e.printStackTrace();\n        }\n        if (ctx != null) {\n            try {\n                ctx.close();\n            } catch (NamingException e) {\n                \/\/ ignore\n            }\n        }\n    }\n\n    public static void main(String[] args) {\n        LdapTest LDAPTest = new LdapTest();\n        LDAPTest.JNDILookup();\n    }\n}<\/pre>\n<h2>5.2 \u7528JLDAP\u8fdb\u8bbf\u95ee<\/h2>\n<p>\u8bbf\u95ee\u5730\u5740\uff1a<a href=\"http:\/\/www.openldap.org\/jldap\/\">http:\/\/www.openldap.org\/jldap\/<\/a> \u5e76\u4e0b\u8f7d\u76f8\u5173lib<\/p>\n<pre class=\"brush:java; toolbar: true; auto-links: true;\">import com.novell.ldap.*;\n\nimport java.io.UnsupportedEncodingException;\n\npublic class List\n\n{\n\n    public static void main(String[] args)\n\n    {\n        int ldapPort = LDAPConnection.DEFAULT_PORT;\n        int searchScope = LDAPConnection.SCOPE_ONE;\n        int ldapVersion = LDAPConnection.LDAP_V3;\n        boolean attributeOnly = false;\n        String attrs[] = null;\n        String ldapHost = \"192.168.0.30\";\n        String loginDN = \"cn=Manager,o=teemlink,c=cn\";\n        String password = \"secret\";\n        String searchBase = \"ou=develop,o=teemlink,c=cn\";\n        String searchFilter = \"objectClass=*\";\n\n        LDAPConnection lc = new LDAPConnection();\n        try {\n            \/\/ connect to the server\n            lc.connect(ldapHost, ldapPort);\n\n            \/\/ bind to the server\n            lc.bind(ldapVersion, loginDN, password.getBytes(\"UTF8\"));\n\n            LDAPSearchResults searchResults =\n\n            lc.search(searchBase, \/\/ container to search\n                    searchScope, \/\/ search scope\n                    searchFilter, \/\/ search filter\n                    attrs, \/\/ \"1.1\" returns entry name only\n                    attributeOnly); \/\/ no attributes are returned\n\n            \/\/ print out all the objects\n            while (searchResults.hasMore()) {\n                LDAPEntry nextEntry = null;\n                try {\n                    nextEntry = searchResults.next();\n                    System.out.println(\"\\n\" + nextEntry.getDN());\n                    System.out.println(nextEntry.getAttributeSet());\n                } catch (LDAPException e) {\n                    System.out.println(\"Error: \" + e.toString());\n                    \/\/ Exception is thrown, go for next entry\n                    continue;\n                }\n            }\n\n            \/\/ disconnect with the server\n            lc.disconnect();\n\n        } catch (LDAPException e) {\n            System.out.println(\"Error: \" + e.toString());\n        } catch (UnsupportedEncodingException e) {\n            System.out.println(\"Error: \" + e.toString());\n        }\n        System.exit(0);\n    }\n}<\/pre>\n<h2>5.3 \u7528JDBC-LDAP\u8fdb\u8bbf\u95ee<\/h2>\n<p>\u8bbf\u95ee\u5730\u5740\uff1a<a href=\"http:\/\/www.openldap.org\/jdbcldap\/\">http:\/\/www.openldap.org\/jdbcldap\/<\/a> \u5e76\u4e0b\u8f7d\u76f8\u5173lib<\/p>\n<pre class=\"brush:java; toolbar: true; auto-links: true;\">package jdbcldap;\n\nimport java.sql.Connection;\nimport java.sql.DriverManager;\nimport java.sql.ResultSet;\nimport java.sql.Statement;\n\npublic class JdbcLdap {\n\n    \/**\n     * @param args\n     * @throws Exception \n     *\/\n    public static void main(String[] args) throws Exception {\n        Class.forName(\"com.octetstring.jdbcLdap.sql.JdbcLdapDriver\");\n        String ldapConnectString = \"jdbc:ldap:\/\/192.168.0.30\/o=teemlink,c=cn?SEARCH_SCOPE:=subTreeScope\";\n        Connection con = DriverManager.getConnection(ldapConnectString, \"cn=Manager,o=teemlink,c=cn\", \"secret\");\n\n        String sql = \"SELECT * FROM ou=develop,o=teemlink,c=cn\";\n\n        Statement sat = con.createStatement();\n        ResultSet rs = sta.executeQuery(sql);\n        while (rs.next()) {\n            System.out.println(rs.getString(1));\n        }\n\n        if (con != null)\n            con.close();\n    }\n}<\/pre>\n<p>\u539f\u521b\u4eba\u5458\uff1aNicholas<\/p>\n<p style=\"text-align: left;\">\u6765\u6e90\uff1ahttp:\/\/www.cnblogs.com\/obpm\/archive\/2010\/08\/28\/1811065.html<\/p>\n<p>Links\uff1a<br \/>\nhttps:\/\/segmentfault.com\/a\/1190000002607140<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. LDAP\u7b80\u4ecb LDAP\uff08\u8f7b\u91cf\u7ea7\u76ee\u5f55\u8bbf\u95ee\u534f\u8bae\uff0cLightweight Dir &hellip; <a href=\"https:\/\/www.xiaobo.li\/notes\/archives\/699\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[283],"tags":[156],"class_list":["post-699","post","type-post","status-publish","format-standard","hentry","category-technologys","tag-ldap"],"_links":{"self":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts\/699","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/comments?post=699"}],"version-history":[{"count":0,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts\/699\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/media?parent=699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/categories?post=699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/tags?post=699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}