{"id":305,"date":"2011-08-26T21:49:22","date_gmt":"2011-08-27T04:49:22","guid":{"rendered":"http:\/\/www.analogrithems.com\/rant\/?p=305"},"modified":"2011-10-03T16:35:52","modified_gmt":"2011-10-03T23:35:52","slug":"ldap-authentication-in-cakephp","status":"publish","type":"post","link":"https:\/\/www.analogrithems.com\/rant\/ldap-authentication-in-cakephp\/","title":{"rendered":"Ldap authentication in CakePHP"},"content":{"rendered":"<p>It&#8217;s been over a year since I wrote the first version of the CakePHP LdapAuth &amp; Ldap Datasource. What I&#8217;ve learned over the last year is that a simple component &amp; datasource is not enough and it should really be a full plugin. So I started working on Idbroker. The new plugin offers the following<\/p>\n<p>* A ldap Datasource that bad been tested with Iplanet, Netscape Directory Server, OpenLDAP &amp; Active Directory<\/p>\n<p>* A revised Ldap Auth component that works with CakePHP 1.3<\/p>\n<p>* A simple application (Which is still in development) that uses both and will give great examples of how to use.<\/p>\n<p>Using this plugin you can get Ldap authentication in CakePHP.<\/p>\n<p>To get started place a copy of the plugin in your plugins directory. Simplest way is to clone it from github<\/p>\n<p>git clone https:\/\/github.com\/analogrithems\/idbroker<\/p>\n<h1>Auth LDAP<\/h1>\n<p>To make use of the LDAPAuth,<\/p>\n<p>1) Add the following to either the controller you want to add LDAPAuth to or to app_controller to give all our controllers LDAPAuth<\/p>\n<p>[php]<br \/>\nvar $components = array( &#8216;Idbroker.LDAPAcl&#8217;=&gt;array(&#8216;groupType&#8217;=&gt;&#8217;group&#8217;), &#8216;Idbroker.LDAPAuth&#8217;);<br \/>\n[\/php]<\/p>\n<p>For the groupType, this really has to do with how your LDAP group objectClass is. For active directory your groupType will be &#8216;group&#8217; for most other LDAP v# implementations it will be either posixGroup (If the group stores membership info as memberUid=jdoe) or groupOfNames( if your group stores membership info as uniquemember=cn=jdoe,ou=people,dc=example,dc=com). If not set, it defaults to groupOfNames. If you are using Active Directory, set this to &#8216;group&#8217;<\/p>\n<p>2) Add the LDAP settings to your \/APP\/config\/database.php<br \/>\nNow we need to get the LDAP settings plugged into the database.php file. This hasn&#8217;t changed much since the last version.<\/p>\n<p>[php]<br \/>\n&lt;?php<br \/>\nclass DATABASE_CONFIG {<br \/>\n\tvar $ldap = array (<br \/>\n\t\t\t&#8216;datasource&#8217; =&gt; &#8216;Idbroker.Ldap&#8217;,<br \/>\n\t\t\t&#8216;host&#8217; =&gt; &#8216;ldap.example.com&#8217;,<br \/>\n\t\t\t&#8216;port&#8217; =&gt; 389,<br \/>\n\t\t\t&#8216;basedn&#8217; =&gt; &#8216;DC=example,DC=com&#8217;,<br \/>\n\t\t\t&#8216;login&#8217; =&gt; &#8216;CN=authservice,CN=Users,DC=example,DC=com&#8217;,     \/\/For Proxy Userdn Active Directory and sometimes iPlanet require this<br \/>\n\t\t\t&#8216;password&#8217; =&gt; &#8216;superSecretPassword&#8217;,  \/\/For Proxy UserDN password<br \/>\n\t\t\t&#8216;database&#8217; =&gt; &#8221;,<br \/>\n\t\t\t&#8216;tls&#8217;      =&gt; false, \/\/If you are using TLS encryption set to true.<br \/>\n\t\t\t&#8216;type&#8217; =&gt; &#8216;ActiveDirectory&#8217;, \/\/Available types are &#8216;OpenLDAP&#8217;, &#8216;ActiveDirectory&#8217;, &#8216;Netscape&#8217;<br \/>\n\t\t\t&#8216;version&#8217; =&gt; 3<br \/>\n\t);<br \/>\n}<br \/>\n?&gt;<br \/>\n[\/php]<\/p>\n<p>3) The last step is to setup the LDAP settings. Create a file called \/APP\/config\/ldap.php with the following. See comments for explanation of vars<\/p>\n<p>[php]<br \/>\n&lt;?php<br \/>\n\/**<br \/>\n * LDAP Settings<br \/>\n *<br \/>\n *\/<br \/>\n\t$config[&#8216;LDAP&#8217;][&#8216;Db&#8217;][&#8216;Config&#8217;] = &#8216;ldap&#8217;; \/\/What ever the config was called in the database.php file, defaults to ldap if not specified<br \/>\n\t$config[&#8216;LDAP&#8217;][&#8216;User&#8217;][&#8216;Identifier&#8217;] = &#8216;samAccountName&#8217;; \/\/The LDAP attribute that holds the username, defaults to uid, use samaccountname for AD<br \/>\n\t$config[&#8216;LDAP&#8217;][&#8216;LdapAuth&#8217;][&#8216;Model&#8217;] = &#8216;Idbroker.LdapAuth&#8217;; \/\/The model to use for the LDAPAuth Component, Should probably just set it to &#8216;Idbroker.LdapAuth for must users<br \/>\n\t$config[&#8216;LDAP&#8217;][&#8216;LdapACL&#8217;][&#8216;Model&#8217;] = &#8216;Idbroker.LdapAcl&#8217;;  \/\/The model to use for the developing LDAPAcl don&#8217;t change unless you know what your doing<br \/>\n\t$config[&#8216;LDAP&#8217;][&#8216;LdapACL&#8217;][&#8216;groupType&#8217;] = &#8216;group&#8217;; \/\/group type refers to the group objectclass your ldap server uses.  can also be overwriten in the components array<br \/>\n?&gt;<br \/>\n[\/php]<\/p>\n<p>add the following to the bottom of \/APP\/config\/core.php<\/p>\n<p>[php]<br \/>\n\/\/Ldap Config<br \/>\nConfigure::load(&#8216;ldap&#8217;);<br \/>\n[\/php]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s been over a year since I wrote the first version of the CakePHP LdapAuth &amp; Ldap Datasource. What I&#8217;ve learned over the last year is that a simple component &amp; datasource is not enough and it should really be a full plugin. So I started working on Idbroker. The new plugin offers the following [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,44,3],"tags":[],"class_list":["post-305","post","type-post","status-publish","format-standard","hentry","category-cakephp","category-featured","category-ldap"],"_links":{"self":[{"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/posts\/305","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/comments?post=305"}],"version-history":[{"count":16,"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/posts\/305\/revisions"}],"predecessor-version":[{"id":309,"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/posts\/305\/revisions\/309"}],"wp:attachment":[{"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/media?parent=305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/categories?post=305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/tags?post=305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}