<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>TBlog</title>
	<atom:link href="http://memdump.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://memdump.wordpress.com</link>
	<description>Various write-ups on tech stuff ...</description>
	<lastBuildDate>Tue, 09 Sep 2008 16:44:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='memdump.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>TBlog</title>
		<link>http://memdump.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://memdump.wordpress.com/osd.xml" title="TBlog" />
	<atom:link rel='hub' href='http://memdump.wordpress.com/?pushpress=hub'/>
		<item>
		<title>LDAP Data Source now with full CRUD !</title>
		<link>http://memdump.wordpress.com/2008/04/26/ldap-data-source-now-with-full-crud/</link>
		<comments>http://memdump.wordpress.com/2008/04/26/ldap-data-source-now-with-full-crud/#comments</comments>
		<pubDate>Sat, 26 Apr 2008 07:26:43 +0000</pubDate>
		<dc:creator>gservat</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[CRUD]]></category>
		<category><![CDATA[ldap]]></category>

		<guid isPermaLink="false">http://memdump.wordpress.com/?p=3</guid>
		<description><![CDATA[So I was making a site up and had to use LDAP as the backend. CakePHP is my favourite PHP framework and a quick Google search returned a link to a CakePHP bakery article which gave me a great starting point. The class basically allows you to read from LDAP, but that&#8217;s it. It was [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memdump.wordpress.com&amp;blog=3582326&amp;post=3&amp;subd=memdump&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So I was making a site up and had to use LDAP as the backend. CakePHP is my favourite PHP framework and a quick Google search returned a link to a <a title="bakery article" href="http://bakery.cakephp.org/articles/view/ldap-datasource-for-cakephp">CakePHP bakery article</a> which gave me a great starting point. The class basically allows you to read from LDAP, but that&#8217;s it. It was good enough to play with, but I quickly got to a point where I really needed to write to LDAP.</p>
<p>I started investigating how I could get a list of attribute types and object classes from LDAP (without parsing the schema <strong>files</strong> or something hacky like that). I thought I could look into the <a href="http://phpldapadmin.sourceforge.net">phpldapadmin</a> project to see how they did it. I&#8217;m glad I did! It was just what I was looking for. They saved me a bit of code!</p>
<p>Credits go out to the original author of the class, <span class="author">euphrate aka &#8220;euphrate_ylb&#8221;, and to the phpldapadmin guys for some of the code in the class.<br />
</span></p>
<p>Anyway, enough rambling. Onto the good stuff:</p>
<ul>
<li><a href="http://www.servat.com.ar/ldap_source.phps">Download</a> the LDAP data source class and save it as <strong>/path/to/cakephp/app/models/datasources/ldap_source.php</strong>.</li>
</ul>
<ul>
<li>You&#8217;ll need a model. Mine is in <strong>/path/to/cakephp/app/models/ldap_user.php</strong>. The most important parts are:</li>
</ul>
<p><pre class="brush: php;">
var $useDbConfig = 'ldap';
var $primaryKey = 'uid';
</pre></p>
<p>Primary Key is an important one (specially when updating &amp; deleting records). In my LDAP tree, I <em><strong>know </strong></em>for a fact that no 2 users will have the same uid, so I used this field. Feel free to choose another unique field (if, for example, you have an Employee ID field and it is unique).</p>
<p><pre class="brush: php;">
var $defaultObjectClass = 'inetOrgPerson';
</pre></p>
<p>The above variable is used to further strict searching when updating/deleting records to an object class too. If you don&#8217;t set the above variable, when you update/delete a user it will search for the $primaryKey field in the entire tree. By restricting to an object class of my liking I ensure I&#8217;m not going to get any unwanted matches.</p>
<p><strong><em>Special note when CREATING records</em></strong></p>
<p>Since there isn&#8217;t any easy way to automagically determine what Distinguished Name (DN) a new record will take, I made it so that one of the fields that you have to submit as part of $this-&gt;data is &#8216;_DN_&#8217;. For example, in my beforeSave() function of my ldap_user.php model, I have the following:</p>
<p><pre class="brush: php;">
function beforeSave() {
        $this-&gt;data[$this-&gt;name]['_DN_'] = 'cn=' . $user[$this-&gt;name]['uid'] . ',ou=Some Department,dc=example,dc=com';
}
</pre></p>
<p>When deleting or updating a user, remember to set the $this-&gt;Model-&gt;id field to be the value that you want to match on (based on $primaryKey). In my case, if I set $this-&gt;Model-&gt;id = &#8216;foo&#8217;, it will search LDAP for <code>(&amp;(objectclass=inetOrgPerson)(uid=foo))</code> and based on that match, it will update or delete (depending on what action I&#8217;m taking).</p>
<p>It&#8217;s now 4AM so there&#8217;s a good chance most of what I wrote doesn&#8217;t make sense. If you don&#8217;t know your way around LDAP, this probably didn&#8217;t make a whole lot of sense. Feel free to leave a comment and I&#8217;ll try and help out (when I get the chance to!)</p>
<p>I must say it feels good to finally contribute back to a project that has saved me sooo many hours of work. CakePHP is truly an <strong>EXCELLENT </strong>project that has saved me so many hours of work and brought back the pleasure of coding up a site :) I have been reading lots and lots of CakePHP code lately and the more I read it, the more I like it. It has been well thought out.</p>
<p>That&#8217;s it for now. If you have any feedback, suggestions, better ways of doing stuff .. please feel free to leave comments!</p>
<p>- Gonzalo (znoG on irc.freenode.net:#cakephp)</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/memdump.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/memdump.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/memdump.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/memdump.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/memdump.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/memdump.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/memdump.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/memdump.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/memdump.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/memdump.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/memdump.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/memdump.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/memdump.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/memdump.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/memdump.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/memdump.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memdump.wordpress.com&amp;blog=3582326&amp;post=3&amp;subd=memdump&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://memdump.wordpress.com/2008/04/26/ldap-data-source-now-with-full-crud/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dbba4dd4ada62b3c8f842e3c0abf39b9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gservat</media:title>
		</media:content>
	</item>
	</channel>
</rss>
