Bizrule Of Cdbauthmanager
#1
Posted 29 November 2012 - 08:43 AM
I love Yii but I found very ugly to store PHP code that will be processed with eval(), in the bizrule of auth_item and auth_assignment, to manage the logic of auths.
It would be great to have another solution.
Talking about that here and there, I'm not the only one to have this opinion.
#2
Posted 29 November 2012 - 09:00 AM
Enjoying Yii? Star us at github
Support me so I can work more on Yii: https://www.patreon.com/samdark
#3
Posted 29 November 2012 - 09:11 AM

But I'm not the only one who will prefer using another way to store auths because of that PHP in DB + eval() process.
Maybe a class passed in parameter to checkAccess, with a method containing the logic of the bizrule.
One can also answer that I can inherit a class from CdbAuthManager, from which checkAccess will do what I want. Maybe..
#4
Posted 29 November 2012 - 03:48 PM
$bizRuleName = function () {}; $bizRuleName2 = function () {}; $bizRuleNameN = function () {};
#5
Posted 29 November 2012 - 04:23 PM
Enjoying Yii? Star us at github
Support me so I can work more on Yii: https://www.patreon.com/samdark
#6
Posted 30 November 2012 - 05:28 AM
samdark, on 29 November 2012 - 04:23 PM, said:
I don't

It could look something like that:
// Class variant $bizRule = 'BizRuleClass::SiteIndexAction'; list($class, $method) = explode('::', $bizRule); $result = $class::$method(); // Callback variant $bizRule = 'bizRuleSiteAction'; // Loads callbacks from file (of course they are cached after first load) $callbacks = getBizRuleCallbackArray(); $result = $callbacks[$bizRule]();
File with callbacks can look something like this
return array( 'bizRuleSiteAction' => function () {return;}, 'bizRuleSiteAbout' => function () {return;}, );
Something like that


#7
Posted 30 November 2012 - 11:52 AM
Enjoying Yii? Star us at github
Support me so I can work more on Yii: https://www.patreon.com/samdark
#8
Posted 30 November 2012 - 03:56 PM
Obviously, this flexibility comes at a price: First of, whoever manages roles and assignments needs to know about the application internals. And he needs at least basic development skills. So it's most likely not the best option for average users. If we put that aside and say it's okay, our users will be comfortable with coding their biz-rules (maybe even enjoy the flexibility that approach gives them), we still face security related problems: do you really want your application to execute arbitrary code? If someone manages to inject something into the DB, he can do everything through biz-rules, right? Another thing are app upgrades. The flexible approach of the current design really pins your components API. Since you can't know which components get used in the biz-rules, you can't modify them. At least you had to be very careful with component versioning...
Storing only callbacks as biz-rules prevents customized logic at runtime. With this approach, one always had to code some scripts to make them available in the biz-rule. It might be easier to test such scripts against newer app versions (or even in general), but it is in no way friendlier to end users (those who have no idea about programming and just want to use software). I think the same applied if those callbacks would be raised like events ("onExecuteBizRuleXyz" to which you can subscribe).
Something in between might be a "custom" scripting language which would be allowed in biz-rules. Something that is flexible enough to do most common tasks, but nothing that would be considered dangerous. Something like BBCode does for text formatting, but on source code level. Don't know if there already is something like that. And of course it might be troublesome to learn another language....
Just some thoughts about the topic. Guess it really comes down to what you want to provide. Does anyone know about how other products solve the issue? I only know from joomla, where you don't have the possibility to specify anything like bizrules.
#9
Posted 02 December 2012 - 05:20 PM
jpj, on 29 November 2012 - 09:11 AM, said:
Really, it's one of the ugliest things I've ever seen in my life.
#10
Posted 03 December 2012 - 01:06 PM
Alternatives?
Enjoying Yii? Star us at github
Support me so I can work more on Yii: https://www.patreon.com/samdark
#11
Posted 03 December 2012 - 03:59 PM
#12
Posted 04 December 2012 - 03:58 AM
The thing is that even if we know what we put in the bizrule field of the db, who knows if any application flaw won't allow to inject arbitrary code instead, and it's especially dangerous because it concerns auths assignments.
Even php.net warns about the eval() function, that should be avoided as much as possible (http://fr2.php.net/m...nction.eval.php).
My idea would be something like in Zend (http://framework.zen...l.advanced.html): a class passed as a parameter to the method that checks the rights (allow() for zend, checkAccess() for Yii), containing the logic of the bizrule.
#13
Posted 04 December 2012 - 05:15 AM
#14
Posted 04 December 2012 - 07:33 AM
jpj, on 04 December 2012 - 03:58 AM, said:
+1
#15
Posted 04 December 2012 - 07:47 AM
#16
Posted 04 December 2012 - 12:07 PM
Enjoying Yii? Star us at github
Support me so I can work more on Yii: https://www.patreon.com/samdark
#17
Posted 04 December 2012 - 12:23 PM
Support me on Patreon: https://www.patreon.com/yiiframework
Promover Yii Framework en Español en Patreon: https://www.patreon....yiiframework_es
YiiFramework en Español: http://yiiframework.es/ - Canal de YouTube - Facebook
Follow me: @robregonm.
#18
Posted 04 December 2012 - 01:00 PM
Enjoying Yii? Star us at github
Support me so I can work more on Yii: https://www.patreon.com/samdark
#19
Posted 05 December 2012 - 11:36 AM
Works fine to me.
#20
Posted 18 December 2012 - 02:24 PM