Welcome Guest, Not a member yet? Register   Sign In
Which is best for ACL?
#10

[eluser]Rick Jolly[/eluser]
[quote author="Kemik" date="1189273173"]I had a look at the Zend ACL last night but the documentation isn't the best in the world.
[/quote]
Yep, they miss some important pieces. IMO they document the ACL well, but they don't show complete examples using the session and database user/roles. However, for simple sites all you'd need is the username of the authenticated user from the session. See this line from the previous example:
Code:
$acl->addRole(new Zend_Acl_Role('someUser'), $parents);
'someUser' is assigned an array of roles in $parents.

Quote:How would you store the roles? You coulpdn't have them being added every time a user visits page.
Well using the simplest setup, you'd have the roles/resources defined in one script (probably within a library) and added whenever a user is visits a page that requires authorization. So you could add your custom ACL wrapper library to the constructor of every controller that requires authorization. Then in each controller, you'd only have to do your tests like:
Code:
if ($this->acl->isAllowed($_SESSION['username'], 'someResource'))
{
   // do something
}

Quote:There's no mention of how you'd store them in the database and then pull them. No mention of linking them to a user.
This is where the documentation doesn't go far enough. If you have roles stored in the database you'd want something more than the example above provides.

In my database I'd have a user table and a user_role table. Of course the user table has username and password and that is used for authentication. Once the user is authenticated, I'd load that user's role(s) from the user_role table into the session. Then you'd check the ACL using the user's role from the session. Now, if a user has an array of roles in the session, of course you'd have to iterate over them. This could be automated in a method of your custom ACL library.

If you want to take it a step further and totally build your ACL from the database, there are some examples out there.
Quote:In the documentation they query the roles, but use the role names. Why would you want to do this? I'd want to query with the username to see if they have access. Why did I have to choose such a complicated application Sad
See the example above where a username is treated like a role and it is assigned roles.


Messages In This Thread
Which is best for ACL? - by El Forum - 09-07-2007, 01:45 PM
Which is best for ACL? - by El Forum - 09-07-2007, 03:16 PM
Which is best for ACL? - by El Forum - 09-07-2007, 03:28 PM
Which is best for ACL? - by El Forum - 09-07-2007, 04:23 PM
Which is best for ACL? - by El Forum - 09-07-2007, 04:49 PM
Which is best for ACL? - by El Forum - 09-07-2007, 08:11 PM
Which is best for ACL? - by El Forum - 09-08-2007, 05:56 AM
Which is best for ACL? - by El Forum - 09-08-2007, 06:39 AM
Which is best for ACL? - by El Forum - 09-08-2007, 07:36 AM
Which is best for ACL? - by El Forum - 09-08-2007, 11:27 AM
Which is best for ACL? - by El Forum - 09-08-2007, 01:25 PM
Which is best for ACL? - by El Forum - 09-08-2007, 02:22 PM
Which is best for ACL? - by El Forum - 09-08-2007, 02:42 PM
Which is best for ACL? - by El Forum - 09-08-2007, 02:51 PM
Which is best for ACL? - by El Forum - 09-08-2007, 03:42 PM
Which is best for ACL? - by El Forum - 09-08-2007, 04:04 PM
Which is best for ACL? - by El Forum - 09-08-2007, 04:29 PM
Which is best for ACL? - by El Forum - 09-08-2007, 09:10 PM
Which is best for ACL? - by El Forum - 09-08-2007, 10:33 PM
Which is best for ACL? - by El Forum - 09-09-2007, 05:11 AM
Which is best for ACL? - by El Forum - 09-09-2007, 03:51 PM
Which is best for ACL? - by El Forum - 09-09-2007, 04:41 PM
Which is best for ACL? - by El Forum - 11-13-2007, 02:01 PM
Which is best for ACL? - by El Forum - 11-13-2007, 02:34 PM
Which is best for ACL? - by El Forum - 11-13-2007, 03:15 PM
Which is best for ACL? - by El Forum - 12-01-2007, 03:50 PM
Which is best for ACL? - by El Forum - 12-01-2007, 04:54 PM
Which is best for ACL? - by El Forum - 12-01-2007, 05:39 PM



Theme © iAndrew 2016 - Forum software by © MyBB