Thursday, November 13, 2008

Acl/Auth vs. obAuth

Just spent the better part of a frustrating week dealing with the over-discussed and under documented Acl/Auth built into CakePHP 1.2. I finally threw up my hands in disgust even after I figured out how the whole system worked. I wanted to have granular control over my actions in my controllers and after I finally figured out that I had to have "all" my actions listed under my aco tree, I still got errors when I tried to log out of the application that my "logout" task was not properly mapped. All that time to figure out how to do this the out-of-the-box, Cake way only to hit yet another wall.

Finally, I passed the point in my project where I can no longer be held up with this and reverted to my old and dear friend obAuth. I had this configured in my 1.1 projects so I had all of this functionality outlined and in about 30 minutes, I had the authentication working with this simple batch of code in my app_controller.

	....<br />	var $components = array('obAuth');<br />	function beforeFilter() {<br />		$this->obAuth->startup($this);<br />		if(isset($this->params['admin'])){<br />			switch($this->params['controller']) {<br />				case 'groups':<br />				case 'pagetypes':<br />				case 'states':<br />				case 'countries':<br />				case 'types':<br />				case 'challenges':<br />					$this->obAuth->lock(array(ADMINISTRATOR)); // This is defined in core.php<br />					break;<br />				default:<br />					$this->obAuth->lock(array(ADMINISTRATOR, WEBMASTER)); // These are  defined in core.php<br />			}<br />			<br />		}<br />	}<br />...<br />


If I have this to do over again, I would probably look into setting the permissions on the controller level with ACL and then using the "controller" or "crud" as the action on $this->Auth->authorize. This is the way most people that have gotten it to work are successful with it. The most helpful site on this is Aran Johnson's site at Aran World. His sample kitchen web site gave me a lot of useful tips on how to work through the Auth part of this and as long as I stayed close to the demo code and didn't stray, I could make it work.

No comments:

Post a Comment