{"id":40,"date":"2009-06-13T15:08:52","date_gmt":"2009-06-13T22:08:52","guid":{"rendered":"http:\/\/www.analogrithems.com\/rant\/?p=40"},"modified":"2011-08-25T19:49:37","modified_gmt":"2011-08-26T02:49:37","slug":"ldapauth-component-for-cakephp","status":"publish","type":"post","link":"https:\/\/www.analogrithems.com\/rant\/ldapauth-component-for-cakephp\/","title":{"rendered":"LdapAuth component for CakePHP"},"content":{"rendered":"<p>So I was looking for a way to authenticate against LDAP with cake but I&#8217;ve found that it doesn&#8217;t support it by default.  I found one that checks the auth against ldap then creates a local mysql account.  This also didn&#8217;t use a actual ldap data sourc e either, it just handeled it&#8217;s own ldap connection.  After I read through the standard cakphp auth component I saw that it wouldn&#8217;t be that hard to write an LDAP based auth component.<\/p>\n<p>First you need to download this file <a href=\"http:\/\/www.analogrithems.com\/rant\/wp-content\/uploads\/2009\/06\/ldap_auth.phps\">ldap_auth.php<\/a> to your <strong>&#8216;app\/controllers\/components\/&#8217;<\/strong> directory.<\/p>\n<p>Then just like the original auth component you add that component to a model.  I followed the usual auth example and created a model called Users.php like so<\/p>\n<pre lang=\"php\">\r\n<?php \r\nclass User extends AppModel {\r\n\tvar $name = 'User';\r\n\tvar $useDbConfig = 'ldap';\r\n\tvar $primaryKey = 'uid';\r\n\tvar $useTable = 'ou=people';\r\n}\r\n?>\r\n\r\n<\/pre>\n<p>If some of these options are odd looking please have a look at my <a href=\"http:\/\/www.analogrithems.com\/rant\/?p=3\">ldap data source <\/a> post.  <\/p>\n<p>Next you are going to need your controller.  Here is the one I used  It defines the required functions like login, logout &#038; authorize. <\/p>\n<pre lang=\"php\">\r\n<?php\r\nclass UsersController extends AppController {\r\n\r\n\tvar $name = 'Users';    \r\n        var $components = array('RequestHandler', 'LdapAuth');\r\n        var $helpers = array('Form','Html','Javascript', 'Ajax');\r\n\r\n\tfunction login() {\r\n\t}\r\n\r\n\tfunction logout() {\r\n\t\t$this->redirect($this->LdapAuth->logout());\r\n\t}\r\n\r\n        function isAuthorized() {\r\n                return true;\r\n        }\r\n\r\n}\r\n?>\r\n<\/pre>\n<p>7<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So I was looking for a way to authenticate against LDAP with cake but I&#8217;ve found that it doesn&#8217;t support it by default. I found one that checks the auth against ldap then creates a local mysql account. This also didn&#8217;t use a actual ldap data sourc e either, it just handeled it&#8217;s own ldap [&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":[170,5,168],"class_list":["post-40","post","type-post","status-publish","format-standard","hentry","category-cakephp","category-featured","category-ldap","tag-cakephp","tag-centralized-authentication","tag-ldap"],"_links":{"self":[{"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/posts\/40","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=40"}],"version-history":[{"count":15,"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":45,"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/posts\/40\/revisions\/45"}],"wp:attachment":[{"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.analogrithems.com\/rant\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}