<?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/"
	>

<channel>
	<title>HonkBlog&#124;TechNotes &#187; Auth component</title>
	<atom:link href="http://www.honk.com.au/index.php/category/dev/frameworks/cakephp/auth-component/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.honk.com.au</link>
	<description>Notes, fixes, tips and suggestions from across my technical world</description>
	<lastBuildDate>Mon, 09 Jan 2012 16:54:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>What is the difference between the Auth component and the ACL component in CakePHP?</title>
		<link>http://www.honk.com.au/index.php/2009/10/24/what-is-the-difference-between-the-auth-component-and-the-acl-component-in-cakephp/</link>
		<comments>http://www.honk.com.au/index.php/2009/10/24/what-is-the-difference-between-the-auth-component-and-the-acl-component-in-cakephp/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 12:33:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Auth component]]></category>
		<category><![CDATA[Cake PHP]]></category>

		<guid isPermaLink="false">http://www.honk.com.au/?p=180</guid>
		<description><![CDATA[This is a part of my series. One of the things that I found most confusing about implementing the Auth component and ACL was their precise relationship, how they hung together, what one was and the other wasn&#8217;t or more specifically what one did and the other didn&#8217;t. While conceptually not complicated &#8211; the Auth [...]]]></description>
			<content:encoded><![CDATA[<p><strong>This is a part of my <a href="http://www.honk.com.au/index.php/2009/10/13/guide-to-setting-up-the-cakephp-auth-component/">Guide to setting up the CakePHP auth component</a> series.</strong></p>
<p>One of the things that I found most confusing about implementing the Auth component and ACL was their precise relationship, how they hung together, what one was and the other wasn&#8217;t or more specifically what one did and the other didn&#8217;t.</p>
<p>While conceptually not complicated &#8211; the <em>Auth Component</em> is something that identifies a user whereas the <em>ACL component</em> is something that takes that knowledge and says &#8220;what does this identified user have access to&#8221; &#8211; they seem (at first) so intermeshed in the &#8220;Automagic&#8221; functions of CakePHP that it can be difficult to establish what is causing what to happen.</p>
<p>I found this particularly so when, having not gone through the <a href="http://book.cakephp.org/view/641/Simple-Acl-controlled-Application" target="_blank">Simple-Acl-controlled-Application tutorial</a> kindly provided by the CakePHP team, I dropped the Auth component into my components list and lo and behold I was required to authenticate against actions I had wanted protected.</p>
<p>It wasn&#8217;t until reading this article and doing a bit of experimenting i realised that while it was definitely &#8220;Authenticating&#8221; it was not &#8220;Checking access&#8221; so none of my ACL stuff was kicking in at all.</p>
<p>An example of how the two functions seem intermeshed is the allowedActions function that is specified in the beforeFilter:</p>
<p>$this-&gt;Auth-&gt;allowedActions = array(&#8216;*&#8217;);</p>
<p>This is (as the method path shows) a function of the Auth component, but it relates to Access, in this case the actions of the controller.  This is an important function to understand, this tells the AuthComponent to allow PUBLIC access to all actions, you can of course provide a specific array of actions here as well.  The important thing to understand is that &#8220;public&#8221; is just a default state given to a non authenticated user, it is not a specific group you need to create and assign by default (which is the case in some authentication systems I&#8217;ve seen).</p>
<p>So remember that while a user can be &#8220;authenticated&#8221; that is, they are known to the system they are not necessarily being  checked against their access profile,  $this-&gt;Auth-&gt;allowedActions can confuse matters if you&#8217;re not careful because it can suggest that the authenticated person does or doesn&#8217;t have access to something (because they get redirected to the login page).</p>
<p>When working out what is tripping up a security response, use this handy guide to <a href="http://www.honk.com.au/index.php/2009/10/13/debugging-cakephp-auth-component/">Debugging CakePHP Auth component</a> which can tell you what is being validated against and thus if it is your dodgy ACL setup or just the default settings in the Auth component that are causing any problems.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.honk.com.au/index.php/2009/10/24/what-is-the-difference-between-the-auth-component-and-the-acl-component-in-cakephp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cake PHP Auth Component Frequently Asked Questions (FAQ)</title>
		<link>http://www.honk.com.au/index.php/2009/10/24/cake-php-auth-component-frequently-asked-questions-faq/</link>
		<comments>http://www.honk.com.au/index.php/2009/10/24/cake-php-auth-component-frequently-asked-questions-faq/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 12:26:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Auth component]]></category>
		<category><![CDATA[Cake PHP]]></category>

		<guid isPermaLink="false">http://www.honk.com.au/?p=161</guid>
		<description><![CDATA[This is a part of my series.]]></description>
			<content:encoded><![CDATA[<p><strong>This is a part of my <a href="http://www.honk.com.au/index.php/2009/10/13/guide-to-setting-up-the-cakephp-auth-component/">Guide to setting up the CakePHP auth component</a> series.</strong></p>
<h2><a href="http://www.honk.com.au/index.php/2009/10/24/what-is-the-difference-between-the-auth-component-and-the-acl-component-in-cakephp/">What is the difference between the Auth component and the ACL component in CakePHP?</a></h2>
<h2><a href="http://www.honk.com.au/index.php/2009/10/24/user-password-is-double-hashed-on-edit-when-using-the-cakephp-auth-component/">User password is "double hashed on edit when using the Cakephp Auth component</a></h2>
]]></content:encoded>
			<wfw:commentRss>http://www.honk.com.au/index.php/2009/10/24/cake-php-auth-component-frequently-asked-questions-faq/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>User password is &#8220;double hashed on edit when using the Cakephp Auth component</title>
		<link>http://www.honk.com.au/index.php/2009/10/24/user-password-is-double-hashed-on-edit-when-using-the-cakephp-auth-component/</link>
		<comments>http://www.honk.com.au/index.php/2009/10/24/user-password-is-double-hashed-on-edit-when-using-the-cakephp-auth-component/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 12:25:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Auth component]]></category>
		<category><![CDATA[Cake PHP]]></category>

		<guid isPermaLink="false">http://www.honk.com.au/?p=171</guid>
		<description><![CDATA[This is a part of my series. I found a good basis for a resolution to this issue here . It wasn&#8217;t perfect for me but did a nice job of explaining a problem I had with hashed values. I have provided a modified solution below that meets my requirements more specifically (that is to [...]]]></description>
			<content:encoded><![CDATA[<p><strong>This is a part of my <a href="http://www.honk.com.au/index.php/2009/10/13/guide-to-setting-up-the-cakephp-auth-component/">Guide to setting up the CakePHP auth component</a> series.</strong></p>
<p>I found a good basis for a resolution to this issue <a href="http://dsi.vozibrale.com/articles/view/manually-hashing-password-and-password-validation" target="_blank">here </a>.  It wasn&#8217;t perfect for me but did a nice job of explaining a problem I had with hashed values. I have provided a modified solution below that meets my requirements more specifically (that is to allow password changes only when a password confirm is provided on edit, while requiring a password on add).<br />
A problem I had encountered along the way was due to me not understanding the hash function, I couldn&#8217;t get the two hash values to match, this problem is highlighted in the post &#8220;<a href="http://dsi.vozibrale.com/articles/view/manually-hashing-password-and-password-validation" target="_blank">Manually hashing password and password validation in CakePHP</a>&#8220;:</p>
<blockquote><p><strong>Security::hash($this-&gt;data['User']['passwd'], null, true);</strong><br />
This line makes the password readable by the Auth component, and that in turn removes the need of creating your own. Take a look at the API reference of Security::hash() and you will see that the third parameter is very important, as it tells the hash function to use the &#8220;Security.salt&#8221; value in the hashing process. In any case, if you need to hash something and be compatible with the Cake&#8217;s own Auth and Security, this seems to be the right way.</p></blockquote>
<p>So make sure you include the second and third parameters of the security function whichever solution you implement.</p>
<p>Below is my version of the code, I have essentially reversed the validation process as I wanted it to only execute if a password confirm was provided (that is the validation wouldn&#8217;t be tripped up unless they specifically wanted to change the password, and if the password field itself was blank then nothing should happen ever).</p>
<p>Taken from user.php (the model)</p>
<pre class="brush:php">    function __construct()
    {
        parent::__construct();   

		/*
		 * Validate on the password field not the password confirmation field
		 * This ensures that if we enter blank in both then nothing is triggered
		 * or blank on the confirmation field only then it is rejected using validatePasswdConfirm
		 */
        $this-&gt;validate = array
        (   

            'passwd' =&gt; array
            (
                /* snip other rules */
                'match' =&gt;
                array
                (
                    'rule'          =&gt; 'validatePasswdConfirm',
                    'required'      =&gt; false,
                    'allowEmpty'    =&gt; true,
                    'message'       =&gt; __('Passwords do not match', true)
                )
            ), 

	 /*
	 * On creation when we always want a password, have the form use a normal
	 * password field and have it validated against it's own special "empty" check
	 * that is '' that has been hashed (automagically by cake)
	 */
            'password' =&gt; array
                (
                    'rule'          =&gt; 'validateHashedPassword',
					'required'      =&gt; false,
                    'allowEmpty'    =&gt; false,
                    'message'       =&gt; __('You must submit a password', true)
                )
        );
	}

   function validateHashedPassword($data)
    {
		if ($data['password'] == Security::hash('', null, true))
        {
            return false;
        }   

        return true;
    } 

   function validatePasswdConfirm($data)
    {
		if (isset($this-&gt;data['User']['passwd_confirm'])&amp;&amp;
			$this-&gt;data['User']['passwd'] &lt;&gt; '' &amp;&amp;
			$this-&gt;data['User']['passwd_confirm'] !== $data['passwd']
			)
        {
            return false;
        }   

        return true;
    }   

	function beforeSave() {
	    /*
	     * Ensure that there is a value for the password,
	     * field it should be ignored if they are not
	     * providing a value (i.e. no update should take place)
	     */
		if (isset($this-&gt;data['User']['passwd']) &amp;&amp; $this-&gt;data['User']['passwd'] &lt;&gt; '')
	    {
	        $this-&gt;data['User']['password'] = Security::hash($this-&gt;data['User']['passwd'], null, true);
	        unset($this-&gt;data['User']['passwd']);
	    }   

	    if (isset($this-&gt;data['User']['passwd_confirm']))
	    {
	        unset($this-&gt;data['User']['passwd_confirm']);
	    }   

	    return true;
	}</pre>
<p>Just to be clear too here is my add/edit form (I combine them to save duplication), admin_edit.php:</p>
<pre class="brush:php">
<div class="main-content form">
create('User');?&gt;
<fieldset>
<legend></legend>

	input('id');
		echo $form-&gt;input('email');
		//App::import("Vendor", "dbug2");new dbug2($this-&gt;data);

		if(empty($this-&gt;data['User']['id'])){
			echo $form-&gt;input('password', array('value' =&gt; '','autocomplete'=&gt;'off'));
		}else{
			echo $form-&gt;input('User.passwd', array('label' =&gt; 'New password','value' =&gt; '','autocomplete'=&gt;'off'));
			echo $form-&gt;input('User.passwd_confirm', array('type' =&gt; 'password','label' =&gt; 'Confirm new password','value' =&gt; '','autocomplete'=&gt;'off'));
		};
		echo $form-&gt;input('firstname');
		echo $form-&gt;input('surname');
		echo $form-&gt;input('group_id');
	?&gt;
	</fieldset>

end('Submit');?&gt;</div>
</pre>
<p>Notice too the attribute:</p>
<pre class="brush:php">'autocomplete'=&gt;'off'</pre>
<p>This just prevents the field from being auto populated which I was experiencing while testing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.honk.com.au/index.php/2009/10/24/user-password-is-double-hashed-on-edit-when-using-the-cakephp-auth-component/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Guide to setting up the CakePHP auth component</title>
		<link>http://www.honk.com.au/index.php/2009/10/13/guide-to-setting-up-the-cakephp-auth-component/</link>
		<comments>http://www.honk.com.au/index.php/2009/10/13/guide-to-setting-up-the-cakephp-auth-component/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 08:55:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Auth component]]></category>
		<category><![CDATA[Cake PHP]]></category>

		<guid isPermaLink="false">http://www.honk.com.au/?p=135</guid>
		<description><![CDATA[Introduction If you&#8217;re anything like me by the time you&#8217;ve got to this guide you have probably read about a million interesting but very issue specific pages on setting up elements of the Auth Component in CakePHP.  For such an integral element of the system I found it surprisingly difficult to really understand all of [...]]]></description>
			<content:encoded><![CDATA[<p><span><span style="margin-left: 0px ! important;"><code></code></span></span></p>
<h2>Introduction</h2>
<p>If you&#8217;re anything like me by the time you&#8217;ve got to this guide you have probably read about a million interesting but very issue specific pages on setting up elements of the Auth Component in CakePHP.  For such an integral element of the system I found it surprisingly difficult to really understand all of the elements.  Getting it working was one thing,  but really understanding the &#8220;Automagic&#8221; functions behind the scenes, what happened where and what would happen if I changed something took a lot of research.</p>
<p>So this guide attempts to bring together the results of that research.  It is a combination of  the &#8220;must reads&#8221; , a list of problems and solutions that I encountered when implementing stuff from them, a FAQ section (rather a Q&amp;A of the things I wanted to know along the way) and a general tips section for things that should make your life a bit easier.</p>
<p>The guide will continue to evolve as I discover more but if you have any suggestions or questions please submit a comment below so it is available to all.</p>
<h2>Required reading</h2>
<p>These links are required reading if you want to get to grips with the Auth component AND ACL.  I can&#8217;t stress enough how important it is to have read these and done them line by line before you start looking for answers elsewhere, without these examples the Auth component and ACL will be a little too black box.</p>
<ul>
<li><a href="http://book.cakephp.org/view/465/Understanding-How-ACL-Works" target="_blank">How ACL works</a> (from the CakePHP Book)</li>
<li><a href="http://book.cakephp.org/view/641/Simple-Acl-controlled-Application" target="_blank">A Simple ACL controlled application</a> (from the CakePHP Book tutorials)</li>
</ul>
<h2>Common problems with CakePHP Auth component and their solutions</h2>
<ul>
<li> <a href="http://www.honk.com.au/index.php/2009/10/24/dbaclallow-invalid-node-corecakelibscontrollercomponentsacl-php-line-325/">DbAcl::allow() - Invalid node [CORE\cake\libs\controller\components\acl.php, line 325]</a></li>
</ul>
<h2>CakePHP Auth Component &#8211; FAQ</h2>
<ul>
<li> <a href="http://www.honk.com.au/index.php/2009/10/24/cake-php-auth-component-frequently-asked-questions-faq/">Cake PHP Auth Component Frequently Asked Questions (FAQ)</a></li>
<li><a href="http://www.honk.com.au/index.php/2009/10/24/what-is-the-difference-between-the-auth-component-and-the-acl-component-in-cakephp/">What is the difference between the Auth component and the ACL component in CakePHP?</a></li>
<li> <a href="http://www.honk.com.au/index.php/2009/10/24/user-password-is-double-hashed-on-edit-when-using-the-cakephp-auth-component/">User password is "double hashed on edit when using the Cakephp Auth component</a></li>
</ul>
<h2>Tips and and tools</h2>
<h4>Debuging ACL in CakePHP</h4>
<p>Some handy tricks for seeing what is going on under the hood, this can be surprisingly tricky when things are happening automagically.</p>
<ul>
<li><a href="http://www.honk.com.au/index.php/2009/10/13/debugging-cakephp-auth-component/">Debugging CakePHP Auth component</a></li>
<li><a href="http://www.honk.com.au/index.php/2009/10/13/session-variables-available-when-using-cakephp-auth-component/">Session variables available when using CakePHP auth component</a></li>
</ul>
<h4>Managing ACL in CakePHP</h4>
<p>One of the complicating factors in managing your ACL setup is the derth of good management tools available.  The data required is fiddly and doesn&#8217;t lend itself to hacking around in the database to get things going because in my experience you just make yourself more confused than ever.</p>
<p>Probably the best management tool I found was:<br />
<a href="http://bakery.cakephp.org/articles/view/acl-management-plugin" target="_blank">http://bakery.cakephp.org/articles/view/acl-management-plugin</a></p>
<p>It&#8217;s not perfect, but it&#8217;s a solid tool that will speed up some of your management functions.</p>
<h4>Handy functions that play nicely with the Auth Component</h4>
<p>Keep track of modifications to your records automatically, these mods save time but also reveal some interesting concepts behind the Authcomponent.  Pay close attention to Comment 5 &#8220;Brett H Says&#8221; which explains an issue you&#8217;re likely to encounter using this if you&#8217;ve set up the auth component using the standard configuration.</p>
<ul>
<li><a href="http://blog.loadsys.com/2008/05/02/automagically-setting-user-id-of-record-creator-and-modifier-in-cakephp-12/" target="_blank">Automagically setting user ID of record creator and modifier in CakePHP 1.2</a></li>
</ul>
<h2>Other reading</h2>
<p>Aran Johnson has done an excellent series of examples and tutorials on <a href="http://aranworld.com/article/161/cakephp-acl-tutorial-what-is-it" target="_blank">the CakePHP auth component</a> here.  I found these when I was about half way through writing this guide so there is some duplication of course, but hopefully between the two you will find everything you need.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.honk.com.au/index.php/2009/10/13/guide-to-setting-up-the-cakephp-auth-component/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging CakePHP Auth component</title>
		<link>http://www.honk.com.au/index.php/2009/10/13/debugging-cakephp-auth-component/</link>
		<comments>http://www.honk.com.au/index.php/2009/10/13/debugging-cakephp-auth-component/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 08:54:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Auth component]]></category>

		<guid isPermaLink="false">http://www.honk.com.au/?p=133</guid>
		<description><![CDATA[This is the first in a series of articles on the  CakePHP Auth component, for me one of the more complicated elements of CakePHP (once you get past the most basic configuration) and one that has taken me ages to work out.   Hopefully the information in these guides will go some way to helping [...]]]></description>
			<content:encoded><![CDATA[<p>This is the first in a series of articles on the  CakePHP Auth component, for me one of the more complicated elements of CakePHP (once you get past the most basic configuration) and one that has taken me ages to work out.   Hopefully the information in these guides will go some way to helping you through this process.</p>
<p>Ok, so here are some <strong>tricks for debugging the cakePHP auth component</strong> in no particular order, they are not a <a href="http://www.honk.com.au/index.php/2009/10/13/guide-to-setting-up-the-cakephp-auth-component">guide to setting up the CakePHP auth component</a> per se so take a look at those for more general set up information:</p>
<h2>Debugging the controller and action being requested by the Auth component</h2>
<p>in the beforeFilter() of app_controller.php put:</p>
<pre class="brush:css">$this-&gt;Auth-&gt;authError = sprintf(__('You are not authorized to access that location %s/%s .',true),$this-&gt;name,$this-&gt;action);</pre>
<p>This should be alongside your settings for $this-&gt;Auth-&gt;loginAction and $this-&gt;Auth-&gt;loginRedirect for example &#8211; assuming you have correctly set up your login form to display $session-&gt;flash(&#8216;auth&#8217;); then it will show you what was rejected by the Auth component.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.honk.com.au/index.php/2009/10/13/debugging-cakephp-auth-component/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Session variables available when using CakePHP auth component</title>
		<link>http://www.honk.com.au/index.php/2009/10/13/session-variables-available-when-using-cakephp-auth-component/</link>
		<comments>http://www.honk.com.au/index.php/2009/10/13/session-variables-available-when-using-cakephp-auth-component/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 08:01:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Auth component]]></category>
		<category><![CDATA[Cake PHP]]></category>

		<guid isPermaLink="false">http://www.honk.com.au/?p=130</guid>
		<description><![CDATA[To see which variables are available when using CakePHP auth component simply dump out: $session-&#62;read(&#8216;Auth.User&#8217;) E.g. using the superb dBug tag (if you&#8217;re not using it you should be, I don&#8217;t even bother with other dump functions now): App::import(&#8220;Vendor&#8221;, &#8220;dbug2&#8243;);new dbug2($session-&#62;read(&#8216;Auth.User&#8217;)); As an aside, anyone who is NOT using the  php dBug tag which mimics [...]]]></description>
			<content:encoded><![CDATA[<p>To see which variables are available when using  CakePHP auth component simply dump out:</p>
<p>$session-&gt;read(&#8216;Auth.User&#8217;)</p>
<p>E.g. using the superb <a href="http://dbug.ospinto.com/" target="_blank">dBug </a>tag (if you&#8217;re not using it you should be, I don&#8217;t even bother with other dump functions now):</p>
<p>App::import(&#8220;Vendor&#8221;, &#8220;dbug2&#8243;);new dbug2($session-&gt;read(&#8216;Auth.User&#8217;));</p>
<p>As an aside, anyone who is NOT using the  <a href="http://dbug.ospinto.com/" target="_blank">php dBug tag</a> which mimics the equally excellent CFdump tag in Coldfusion, you should be!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.honk.com.au/index.php/2009/10/13/session-variables-available-when-using-cakephp-auth-component/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (Requested URI is rejected)

Served from: honk.com.au @ 2012-02-12 17:48:56 -->
