SlideShare a Scribd company logo
Creating fast, dynamic ACLs in Zend Framework Wim Godden Cu.be Solutions
Who am I ? Wim Godden (@wimgtr)
Owner of Cu.be Solutions (http://cu.be)
PHP developer since 1997
Developer of OpenX
Zend Certified Engineer
Zend Framework Certified Engineer
MySQL Certified Developer
Talking about... Authentication -> Zend_Auth Auditing -> Zend_Log Authorization -> Zend_Acl
Authorization Wikipedia : "the function of specifying access rights to resources"
What's a resource ? Object (Article, Invoice, Document, …)
Webpage
Database / table / row
...
Standard ACL Access to  resources  is defined in  privileges
Privileges are grouped together in  roles
2 types of  roles  : Anonymous / Unknown
Registered / Known
Zend_Acl : the good Flexible
Uses standard role / resource principles Recognizable -> easy to get started No link to specific backend
Allow + deny
Proven, tested
Zend_Acl : the bad & ugly Complexity of rules rises quickly
Performance issues
All rules are in-code
-> maintainability becomes an issue
Evolution of a portal $acl =  new  Zend_Acl(); $acl->addRole( new  Zend_Acl_Role( 'guest' )); $acl->addRole( new  Zend_Acl_Role( 'member' ),  'guest' ); $acl->addRole( new  Zend_Acl_Role( 'admin' ),  'member' ); $acl->addResource( new  Zend_Acl_Resource( 'cms' )); $acl->addResource( new  Zend_Acl_Resource( 'report' )); $acl->allow( 'guest' ,  'cms' ,  'view' ); $acl->allow( 'admin' ,  'cms' ,  'edit' ); $acl->deny( 'guest' ,  'report' ); $acl->allow( 'member' ,  'report' );
Evolution of a portal $acl =  new  Zend_Acl(); $acl->addRole( new  Zend_Acl_Role( 'guest' )); $acl->addRole( new  Zend_Acl_Role( 'departmentA' ),  'guest' ); $acl->addRole( new  Zend_Acl_Role( 'departmentB' ),  'guest' ); $acl->addRole( new  Zend_Acl_Role( 'admin' ),  'member' ); $acl->addResource( new  Zend_Acl_Resource( 'cms' )); $acl->addResource( new  Zend_Acl_Resource( 'report' )); $acl->allow( 'guest' ,  'cms' ,  'view' ); $acl->allow( 'admin' ,  'cms' ,  'edit' ); $acl->deny( 'guest' ,  'report' ); $acl->allow( 'departmentA' ,  'report' );
Evolution of a portal $acl =  new  Zend_Acl(); $acl->addRole( new  Zend_Acl_Role( 'guest' )); $acl->addRole( new  Zend_Acl_Role( 'departmentA' ),  'guest' ); $acl->addRole( new  Zend_Acl_Role( 'departmentB' ),  'guest' ); $acl->addRole( new  Zend_Acl_Role( 'departmentC_senior_staff' ),  'guest' ); $acl->addRole( new  Zend_Acl_Role( 'departmentC_marketing' ),  'guest' ); $acl->addRole( new  Zend_Acl_Role( 'admin' ),  'member' ); $acl->addResource( new  Zend_Acl_Resource( 'cms' )); $acl->addResource( new  Zend_Acl_Resource( 'report' )); $acl->addResource( new  Zend_Acl_Resource( 'newsletter' )); $acl->addResource( new  Zend_Acl_Resource( 'photo' )); $acl->addResource( new  Zend_Acl_Resource( 'faq' )); $acl->allow( 'guest' ,  'cms' ,  'view' ); $acl->allow( 'admin' ,  'cms' ,  'edit' ); $acl->deny( 'guest' ,  'report' ); $acl->allow( 'departmentA' ,  'report' ); $acl->deny('departmentC_senior_staff', 'newsletter'); $acl->allow('departmentC_marketing', 'newsletter'); $acl->allow('member', 'photo', 'view'); $acl->allow('departmentC_marketing', 'photo', 'upload'); $acl->allow('admin', 'photo', 'delete'); $acl->allow('guest', 'faq', 'view'); $acl->allow('member', 'faq', 'comment'); $acl->allow('departmentA', 'faq', 'edit'); $acl->allow('departmentC_senior_staff', 'faq', 'edit'); $acl->allow('admin', 'faq', 'edit');
Evolution of a portal $acl =  new  Zend_Acl(); $acl->addRole( new  Zend_Acl_Role( 'guest' )); $acl->addRole( new  Zend_Acl_Role( 'departmentA' ),  'guest' ); $acl->addRole( new  Zend_Acl_Role( 'departmentB' ),  'guest' ); $acl->addRole( new  Zend_Acl_Role( 'departmentC_senior_staff' ),  'guest' ); $acl->addRole( new  Zend_Acl_Role( 'departmentC_marketing' ),  'guest' ); $acl->addRole( new  Zend_Acl_Role( 'cook' ),  'guest' ); $acl->addRole( new  Zend_Acl_Role( 'admin' ),  'member' ); $acl->addResource( new  Zend_Acl_Resource( 'cms' )); $acl->addResource( new  Zend_Acl_Resource( 'report' )); $acl->addResource( new  Zend_Acl_Resource( 'newsletter' )); $acl->addResource( new  Zend_Acl_Resource( 'photo' )); $acl->addResource( new  Zend_Acl_Resource( 'faq' )); $acl->addResource( new  Zend_Acl_Resource( 'invoicing' )); $acl->addResource( new  Zend_Acl_Resource( 'stats' )); $acl->addResource( new  Zend_Acl_Resource( 'lunchmenu' )); $acl->allow( 'guest' ,  'cms' ,  'view' ); $acl->allow( 'admin' ,  'cms' ,  'edit' ); $acl->deny( 'guest' ,  'report' ); $acl->allow( 'departmentA' ,  'report' ); $acl->deny('departmentC_senior_staff', 'newsletter'); $acl->allow('departmentC_marketing', 'newsletter'); $acl->allow('member', 'photo', 'view'); $acl->allow('departmentC_marketing', 'photo', 'upload'); $acl->allow('admin', 'photo', 'delete'); $acl->allow('guest', 'faq', 'view'); $acl->allow('member', 'faq', 'comment'); $acl->allow('departmentA', 'faq', 'edit'); $acl->allow('departmentC_senior_staff', 'faq', 'edit'); $acl->allow('admin', 'faq', 'edit'); $acl->allow('admin', 'photo', 'delete'); $acl->allow('guest', 'faq', 'view'); $acl->allow('member', 'faq', 'comment'); $acl->allow('departmentA', 'faq', 'edit'); $acl->allow('departmentC_senior_staff', 'faq', 'edit'); $acl->allow('admin', 'faq', 'edit'); $acl->allow('cook', 'lunchmenu', 'edit'); $acl->allow('member', 'lunchmenu', 'view'); $acl->allow('accounting', 'invoicing', 'edit'); $acl->allow('admin', 'invoicing', 'edit'); $acl->allow('departmentC_senior_staff', 'invoicing', 'report');
Evolution of a portal $acl =  new  Zend_Acl(); $acl->addRole( new  Zend_Acl_Role( 'guest' )); $acl->addRole( new  Zend_Acl_Role( 'departmentA' ),  'guest' ); $acl->addRole( new  Zend_Acl_Role( 'departmentB' ),  'guest' ); $acl->addRole( new  Zend_Acl_Role( 'departmentC_senior_staff' ),  'guest' ); $acl->addRole( new  Zend_Acl_Role( 'departmentC_marketing' ),  'guest' ); $acl->addRole( new  Zend_Acl_Role( 'cook' ),  'guest' ); $acl->addRole( new  Zend_Acl_Role( 'admin' ),  'member' ); $acl->addResource( new  Zend_Acl_Resource( 'cms' )); $acl->addResource( new  Zend_Acl_Resource( 'report' )); $acl->addResource( new  Zend_Acl_Resource( 'newsletter' )); $acl->addResource( new  Zend_Acl_Resource( 'photo' )); $acl->addResource( new  Zend_Acl_Resource( 'faq' )); $acl->addResource( new  Zend_Acl_Resource( 'invoicing' )); $acl->addResource( new  Zend_Acl_Resource( 'stats' )); $acl->addResource( new  Zend_Acl_Resource( 'lunchmenu' )); $acl->allow( 'guest' ,  'cms' ,  'view' ); $acl->allow( 'admin' ,  'cms' ,  'edit' ); $acl->deny( 'guest' ,  'report' ); $acl->allow( 'departmentA' ,  'report' ); $acl->deny('departmentC_senior_staff', 'newsletter'); $acl->allow('departmentC_marketing', 'newsletter'); $acl->allow('member', 'photo', 'view'); $acl->allow('departmentC_marketing', 'photo', 'upload'); $acl->allow('admin', 'photo', 'delete'); $acl->allow('guest', 'faq', 'view'); $acl->allow('member', 'faq', 'comment'); $acl->allow('departmentA', 'faq', 'edit'); $acl->allow('departmentC_senior_staff', 'faq', 'edit'); $acl->allow('admin', 'faq', 'edit'); $acl->allow('admin', 'photo', 'delete'); $acl->allow('guest', 'faq', 'view'); $acl->allow('member', 'faq', 'comment'); $acl->allow('departmentA', 'faq', 'edit'); $acl->allow('departmentC_senior_staff', 'faq', 'edit'); $acl->allow('admin', 'faq', 'edit'); $acl->allow('cook', 'lunchmenu', 'edit'); $acl->allow('member', 'lunchmenu', 'view'); $acl->allow('accounting', 'invoicing', 'edit'); $acl->allow('admin', 'invoicing', 'edit'); $acl->allow('departmentC_senior_staff', 'invoicing', 'report');
Hard to ... maintain all rules
keep track of the rules
debug the rules
Possible solution : database Extend Zend_Acl to database driven design
Good : no code changes required
Bad : more load on DB
A different approach Not  THE  solution, merely  A  solution
Uses database, but...
Additional caching layer
ZF Conventional Modular Directory Structure
Backend interface for easy management with a twist !

More Related Content

PPS
Implementing access control with zend framework
PDF
Error Reporting in ZF2: form messages, custom error pages, logging
PDF
Zend ACL Basics
KEY
Content Driven Zend_Acl in the Model Layer
ODP
Zend Framework 1.9 Setup & Using Zend_Tool
PPT
Framework
PPT
Zend Framework
PPTX
I Love codeigniter, You?
Implementing access control with zend framework
Error Reporting in ZF2: form messages, custom error pages, logging
Zend ACL Basics
Content Driven Zend_Acl in the Model Layer
Zend Framework 1.9 Setup & Using Zend_Tool
Framework
Zend Framework
I Love codeigniter, You?

What's hot (20)

KEY
PHP security audits
PDF
Seam Glassfish Slidecast
PDF
Moving a high traffic ZF1 Enterprise Application to SF2 - Lessons learned
KEY
PHPSpec BDD for PHP
PPT
P H P Part I I, By Kian
PPT
Php Basic Security
PDF
Solr and symfony in Harmony with SolrJs
PDF
Disregard Inputs, Acquire Zend_Form
ODP
Concern of Web Application Security
PDF
OWASP TOP 10 for PHP Programmers
PPT
SQL Injection in PHP
PPTX
Open Source Search: An Analysis
PDF
Php Security
PPT
PDF
PHPUnit Episode iv.iii: Return of the tests
PDF
OWASP Top 10 at International PHP Conference 2014 in Berlin
PDF
PHPunit and you
PDF
Moving from Django Apps to Services
PDF
Entry-level PHP for WordPress
PPTX
Let's write secure Drupal code! - DrupalCamp Belarus 2019
PHP security audits
Seam Glassfish Slidecast
Moving a high traffic ZF1 Enterprise Application to SF2 - Lessons learned
PHPSpec BDD for PHP
P H P Part I I, By Kian
Php Basic Security
Solr and symfony in Harmony with SolrJs
Disregard Inputs, Acquire Zend_Form
Concern of Web Application Security
OWASP TOP 10 for PHP Programmers
SQL Injection in PHP
Open Source Search: An Analysis
Php Security
PHPUnit Episode iv.iii: Return of the tests
OWASP Top 10 at International PHP Conference 2014 in Berlin
PHPunit and you
Moving from Django Apps to Services
Entry-level PHP for WordPress
Let's write secure Drupal code! - DrupalCamp Belarus 2019
Ad

Similar to Creating fast, dynamic ACLs in Zend Framework (18)

PDF
ACL in CodeIgniter
ODP
Zend Form Tutorial
PPTX
My first zf presentation part two
PDF
Instant ACLs with Zend Framework 2
PDF
Enrich your extensions with Joomla! ACL support
PDF
Joomla Access Control List (ACL) at JoomlaDay London, UK #jduk11
PDF
PDF
php-and-zend-framework-getting-started
PDF
php-and-zend-framework-getting-started
PDF
php-and-zend-framework-getting-started
PDF
php-and-zend-framework-getting-started
DOCX
Zend framework 2.0
PDF
Joomla! ACL - Joomla!Day Germany
KEY
PPS
Authentication with zend framework
PDF
Joomla 1.6 ACL - J and Beyond 2011 #jab11
PPTX
PHP Traits
ACL in CodeIgniter
Zend Form Tutorial
My first zf presentation part two
Instant ACLs with Zend Framework 2
Enrich your extensions with Joomla! ACL support
Joomla Access Control List (ACL) at JoomlaDay London, UK #jduk11
php-and-zend-framework-getting-started
php-and-zend-framework-getting-started
php-and-zend-framework-getting-started
php-and-zend-framework-getting-started
Zend framework 2.0
Joomla! ACL - Joomla!Day Germany
Authentication with zend framework
Joomla 1.6 ACL - J and Beyond 2011 #jab11
PHP Traits
Ad

More from Wim Godden (20)

PDF
Beyond php - it's not (just) about the code
PDF
Bringing bright ideas to life
PDF
The why and how of moving to php 8
PDF
The why and how of moving to php 7
PDF
My app is secure... I think
PDF
My app is secure... I think
PDF
Building interactivity with websockets
PDF
Bringing bright ideas to life
ODP
Your app lives on the network - networking for web developers
ODP
The why and how of moving to php 7.x
ODP
The why and how of moving to php 7.x
ODP
Beyond php - it's not (just) about the code
ODP
My app is secure... I think
ODP
Building interactivity with websockets
ODP
Your app lives on the network - networking for web developers
ODP
My app is secure... I think
ODP
My app is secure... I think
ODP
The promise of asynchronous php
ODP
My app is secure... I think
ODP
My app is secure... I think
Beyond php - it's not (just) about the code
Bringing bright ideas to life
The why and how of moving to php 8
The why and how of moving to php 7
My app is secure... I think
My app is secure... I think
Building interactivity with websockets
Bringing bright ideas to life
Your app lives on the network - networking for web developers
The why and how of moving to php 7.x
The why and how of moving to php 7.x
Beyond php - it's not (just) about the code
My app is secure... I think
Building interactivity with websockets
Your app lives on the network - networking for web developers
My app is secure... I think
My app is secure... I think
The promise of asynchronous php
My app is secure... I think
My app is secure... I think

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
KodekX | Application Modernization Development
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPT
Teaching material agriculture food technology
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Spectral efficient network and resource selection model in 5G networks
Per capita expenditure prediction using model stacking based on satellite ima...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Review of recent advances in non-invasive hemoglobin estimation
Digital-Transformation-Roadmap-for-Companies.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
KodekX | Application Modernization Development
Reach Out and Touch Someone: Haptics and Empathic Computing
Machine learning based COVID-19 study performance prediction
Programs and apps: productivity, graphics, security and other tools
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The AUB Centre for AI in Media Proposal.docx
Empathic Computing: Creating Shared Understanding
Understanding_Digital_Forensics_Presentation.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Teaching material agriculture food technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Profit Center Accounting in SAP S/4HANA, S4F28 Col11

Creating fast, dynamic ACLs in Zend Framework

  • 1. Creating fast, dynamic ACLs in Zend Framework Wim Godden Cu.be Solutions
  • 2. Who am I ? Wim Godden (@wimgtr)
  • 3. Owner of Cu.be Solutions (http://cu.be)
  • 9. Talking about... Authentication -> Zend_Auth Auditing -> Zend_Log Authorization -> Zend_Acl
  • 10. Authorization Wikipedia : "the function of specifying access rights to resources"
  • 11. What's a resource ? Object (Article, Invoice, Document, …)
  • 14. ...
  • 15. Standard ACL Access to resources is defined in privileges
  • 16. Privileges are grouped together in roles
  • 17. 2 types of roles : Anonymous / Unknown
  • 19. Zend_Acl : the good Flexible
  • 20. Uses standard role / resource principles Recognizable -> easy to get started No link to specific backend
  • 23. Zend_Acl : the bad & ugly Complexity of rules rises quickly
  • 25. All rules are in-code
  • 27. Evolution of a portal $acl = new Zend_Acl(); $acl->addRole( new Zend_Acl_Role( 'guest' )); $acl->addRole( new Zend_Acl_Role( 'member' ), 'guest' ); $acl->addRole( new Zend_Acl_Role( 'admin' ), 'member' ); $acl->addResource( new Zend_Acl_Resource( 'cms' )); $acl->addResource( new Zend_Acl_Resource( 'report' )); $acl->allow( 'guest' , 'cms' , 'view' ); $acl->allow( 'admin' , 'cms' , 'edit' ); $acl->deny( 'guest' , 'report' ); $acl->allow( 'member' , 'report' );
  • 28. Evolution of a portal $acl = new Zend_Acl(); $acl->addRole( new Zend_Acl_Role( 'guest' )); $acl->addRole( new Zend_Acl_Role( 'departmentA' ), 'guest' ); $acl->addRole( new Zend_Acl_Role( 'departmentB' ), 'guest' ); $acl->addRole( new Zend_Acl_Role( 'admin' ), 'member' ); $acl->addResource( new Zend_Acl_Resource( 'cms' )); $acl->addResource( new Zend_Acl_Resource( 'report' )); $acl->allow( 'guest' , 'cms' , 'view' ); $acl->allow( 'admin' , 'cms' , 'edit' ); $acl->deny( 'guest' , 'report' ); $acl->allow( 'departmentA' , 'report' );
  • 29. Evolution of a portal $acl = new Zend_Acl(); $acl->addRole( new Zend_Acl_Role( 'guest' )); $acl->addRole( new Zend_Acl_Role( 'departmentA' ), 'guest' ); $acl->addRole( new Zend_Acl_Role( 'departmentB' ), 'guest' ); $acl->addRole( new Zend_Acl_Role( 'departmentC_senior_staff' ), 'guest' ); $acl->addRole( new Zend_Acl_Role( 'departmentC_marketing' ), 'guest' ); $acl->addRole( new Zend_Acl_Role( 'admin' ), 'member' ); $acl->addResource( new Zend_Acl_Resource( 'cms' )); $acl->addResource( new Zend_Acl_Resource( 'report' )); $acl->addResource( new Zend_Acl_Resource( 'newsletter' )); $acl->addResource( new Zend_Acl_Resource( 'photo' )); $acl->addResource( new Zend_Acl_Resource( 'faq' )); $acl->allow( 'guest' , 'cms' , 'view' ); $acl->allow( 'admin' , 'cms' , 'edit' ); $acl->deny( 'guest' , 'report' ); $acl->allow( 'departmentA' , 'report' ); $acl->deny('departmentC_senior_staff', 'newsletter'); $acl->allow('departmentC_marketing', 'newsletter'); $acl->allow('member', 'photo', 'view'); $acl->allow('departmentC_marketing', 'photo', 'upload'); $acl->allow('admin', 'photo', 'delete'); $acl->allow('guest', 'faq', 'view'); $acl->allow('member', 'faq', 'comment'); $acl->allow('departmentA', 'faq', 'edit'); $acl->allow('departmentC_senior_staff', 'faq', 'edit'); $acl->allow('admin', 'faq', 'edit');
  • 30. Evolution of a portal $acl = new Zend_Acl(); $acl->addRole( new Zend_Acl_Role( 'guest' )); $acl->addRole( new Zend_Acl_Role( 'departmentA' ), 'guest' ); $acl->addRole( new Zend_Acl_Role( 'departmentB' ), 'guest' ); $acl->addRole( new Zend_Acl_Role( 'departmentC_senior_staff' ), 'guest' ); $acl->addRole( new Zend_Acl_Role( 'departmentC_marketing' ), 'guest' ); $acl->addRole( new Zend_Acl_Role( 'cook' ), 'guest' ); $acl->addRole( new Zend_Acl_Role( 'admin' ), 'member' ); $acl->addResource( new Zend_Acl_Resource( 'cms' )); $acl->addResource( new Zend_Acl_Resource( 'report' )); $acl->addResource( new Zend_Acl_Resource( 'newsletter' )); $acl->addResource( new Zend_Acl_Resource( 'photo' )); $acl->addResource( new Zend_Acl_Resource( 'faq' )); $acl->addResource( new Zend_Acl_Resource( 'invoicing' )); $acl->addResource( new Zend_Acl_Resource( 'stats' )); $acl->addResource( new Zend_Acl_Resource( 'lunchmenu' )); $acl->allow( 'guest' , 'cms' , 'view' ); $acl->allow( 'admin' , 'cms' , 'edit' ); $acl->deny( 'guest' , 'report' ); $acl->allow( 'departmentA' , 'report' ); $acl->deny('departmentC_senior_staff', 'newsletter'); $acl->allow('departmentC_marketing', 'newsletter'); $acl->allow('member', 'photo', 'view'); $acl->allow('departmentC_marketing', 'photo', 'upload'); $acl->allow('admin', 'photo', 'delete'); $acl->allow('guest', 'faq', 'view'); $acl->allow('member', 'faq', 'comment'); $acl->allow('departmentA', 'faq', 'edit'); $acl->allow('departmentC_senior_staff', 'faq', 'edit'); $acl->allow('admin', 'faq', 'edit'); $acl->allow('admin', 'photo', 'delete'); $acl->allow('guest', 'faq', 'view'); $acl->allow('member', 'faq', 'comment'); $acl->allow('departmentA', 'faq', 'edit'); $acl->allow('departmentC_senior_staff', 'faq', 'edit'); $acl->allow('admin', 'faq', 'edit'); $acl->allow('cook', 'lunchmenu', 'edit'); $acl->allow('member', 'lunchmenu', 'view'); $acl->allow('accounting', 'invoicing', 'edit'); $acl->allow('admin', 'invoicing', 'edit'); $acl->allow('departmentC_senior_staff', 'invoicing', 'report');
  • 31. Evolution of a portal $acl = new Zend_Acl(); $acl->addRole( new Zend_Acl_Role( 'guest' )); $acl->addRole( new Zend_Acl_Role( 'departmentA' ), 'guest' ); $acl->addRole( new Zend_Acl_Role( 'departmentB' ), 'guest' ); $acl->addRole( new Zend_Acl_Role( 'departmentC_senior_staff' ), 'guest' ); $acl->addRole( new Zend_Acl_Role( 'departmentC_marketing' ), 'guest' ); $acl->addRole( new Zend_Acl_Role( 'cook' ), 'guest' ); $acl->addRole( new Zend_Acl_Role( 'admin' ), 'member' ); $acl->addResource( new Zend_Acl_Resource( 'cms' )); $acl->addResource( new Zend_Acl_Resource( 'report' )); $acl->addResource( new Zend_Acl_Resource( 'newsletter' )); $acl->addResource( new Zend_Acl_Resource( 'photo' )); $acl->addResource( new Zend_Acl_Resource( 'faq' )); $acl->addResource( new Zend_Acl_Resource( 'invoicing' )); $acl->addResource( new Zend_Acl_Resource( 'stats' )); $acl->addResource( new Zend_Acl_Resource( 'lunchmenu' )); $acl->allow( 'guest' , 'cms' , 'view' ); $acl->allow( 'admin' , 'cms' , 'edit' ); $acl->deny( 'guest' , 'report' ); $acl->allow( 'departmentA' , 'report' ); $acl->deny('departmentC_senior_staff', 'newsletter'); $acl->allow('departmentC_marketing', 'newsletter'); $acl->allow('member', 'photo', 'view'); $acl->allow('departmentC_marketing', 'photo', 'upload'); $acl->allow('admin', 'photo', 'delete'); $acl->allow('guest', 'faq', 'view'); $acl->allow('member', 'faq', 'comment'); $acl->allow('departmentA', 'faq', 'edit'); $acl->allow('departmentC_senior_staff', 'faq', 'edit'); $acl->allow('admin', 'faq', 'edit'); $acl->allow('admin', 'photo', 'delete'); $acl->allow('guest', 'faq', 'view'); $acl->allow('member', 'faq', 'comment'); $acl->allow('departmentA', 'faq', 'edit'); $acl->allow('departmentC_senior_staff', 'faq', 'edit'); $acl->allow('admin', 'faq', 'edit'); $acl->allow('cook', 'lunchmenu', 'edit'); $acl->allow('member', 'lunchmenu', 'view'); $acl->allow('accounting', 'invoicing', 'edit'); $acl->allow('admin', 'invoicing', 'edit'); $acl->allow('departmentC_senior_staff', 'invoicing', 'report');
  • 32. Hard to ... maintain all rules
  • 33. keep track of the rules
  • 35. Possible solution : database Extend Zend_Acl to database driven design
  • 36. Good : no code changes required
  • 37. Bad : more load on DB
  • 38. A different approach Not THE solution, merely A solution
  • 41. ZF Conventional Modular Directory Structure
  • 42. Backend interface for easy management with a twist !
  • 43. Different resources Zend_ACL : $acl->addResource( new Zend_Acl_Resource( 'cms' )); $acl->allow( 'guest' , 'cms' , 'view' ); $acl->allow( 'admin' , 'cms' , 'edit' ); Access to : Controller : cms
  • 44. Action : view / edit Why not integrate with the request itself ?
  • 46. Zend_Acl as a controller plugin <?php class My_Plugin_Acl extends Zend_Controller_Plugin_Abstract { private $_acl = null; public function __construct(Zend_Acl $acl ) { $this ->_acl = $acl ; } public function preDispatch(Zend_Controller_Request_Abstract $request ) { $role = (Zend_Auth::getInstance()->hasIdentity()) ? 'user' : 'guest' ; //For this example, we will use the controller as the resource: $resource = $request ->getControllerName(); if (! $this ->_acl->isAllowed( $role , $resource , 'view' )) { //If the user has no access we send him elsewhere by changing the request and resetting the dispatch $request ->setModuleName( 'auth' ) ->setControllerName( 'auth' ) ->setActionName( 'login' ) ->setDispatched(false); return false; } } }
  • 47. Initializing the ACL Let's have a look
  • 48. Zend_Acl manual rules <?php class My_Acl extends Zend_Acl { public function __construct() { //Add a new role called &quot;guest&quot; $this ->addRole( new Zend_Acl_Role( 'guest' )); //Add a role called user, which inherits from guest $this ->addRole( new Zend_Acl_Role( 'user' ), 'guest' ); //Add a resource called page $this ->add( new Zend_Acl_Resource( 'page' )); //Add a resource called news, which inherits page $this ->add( new Zend_Acl_Resource( 'news' ), 'page' ); //Finally, we want to allow guests to view pages $this ->allow( 'guest' , 'page' , 'view' ); //and users can comment news $this ->allow( 'user' , 'news' , 'comment' ); } }
  • 49. Our ACL id role_id module controller action 1 2 newsletter send index 2 1 cms article edit 3 3 % % % id name email pw 1 Chris [email_address] ******* 2 Jake [email_address] ******* 3 Jeniffer [email_address] ******* id name 1 webmaster 2 marketeer 3 admin user_id role_id 1 2 2 3 3 1
  • 50. Application_Acl class Application_Acl { public function isAllowed($user = null , $request = null ) { if (is_null($user) === false && $user !== false && $user instanceof User) { $userId = $user-> id ; } else { $userId = 0; } $db = Zend_Db_Table:: getDefaultAdapter (); $stmt = $db->query( ' select module_name, controller_name, action_name from privilege join role on role.id = privilege.role_id join userRole on userRole.role_id = role.role_id where userRole.user_id = ? and ( module_name = &quot;%&quot; or ( module_name = ? and ( controller_name = &quot;%&quot; or ( controller_name = ? and ( action_name = &quot;%&quot; or action_name = ? ) ) ) ) ) ' , array ( $userId, $request->getModuleName(), $request->getControllerName(), $request->getActionName() ) ); $stmt->execute(); $row = $stmt->fetch(); // Returns a row or false if ($row !== false ) { return true ; } else { return false ; } } }
  • 51. To cache or not to cache - Option 1 (no cache) 1 query per ACL request
  • 52. = 1 query per pageview / ajax request
  • 53. 99.99% will be identical
  • 54. -> &quot;Just rely on MySQL query cache !&quot;
  • 56. Even for cached queries, MySQL connections use memory, I/O, CPU, ...
  • 57. Caching - Option 2 (cache the main query) 1 DB query per user for each unique ACL request
  • 58. User with 20 privileges -> 20 possible requests
  • 59. All subsequent pageviews : 1 cache request
  • 60. What's in the cache ? Entry Data acl_user_3_%_%_% 1 acl_user_1_cms_article_edit 1 acl_user_1_admin_destroy_planet 0 Problem : what if we add a privilege to a role ? -> All cached entries for all users should be refreshed (ouch !)
  • 61. Caching - Option 3 - denormalize in cache
  • 62. What's in the cache ? Entry Data acl_user_3 3, 1, 4 acl_user_1 3, 1, 2 acl_role_1 a:3:{i:0;s:45:&quot;a:2:{i:0;s:5:&quot;%_%_%&quot;;}&quot;;i:1;i:1308106740;i:2;s:6:&quot;604800&quot;;} User's roles Privileges listed in a role
  • 63. Caching - Option 3 - denormalize in cache 1 DB query per user at login (retrieve user's roles)
  • 64. User with 20 privileges -> just 1 DB query
  • 65. Per pageview : 1 cache query + 1 cache query per role
  • 66. Good : Less queries on DB
  • 67. Less data in the cache (only roles, not full privileges of each user)
  • 68. Add a privilege to a role -> update the role only Bad : More queries on cache Choice : depends on where your highest load is (but memory is cheap and Memcache is fast !)
  • 69. Caching - let's have a look
  • 70. Managing the roles / privileges Zend_Acl : manual typ(o)ing
  • 72. easy management -> Reflection
  • 73. Reflection ? Used to inspect objects during run-time
  • 75. Can be applied to : Classes
  • 81. Reflection - example <?php class Test { static public function testMe ($reason) { echo 'I have a reason : ' . $reason; } } $reflector = new ReflectionClass( 'Test' ); echo 'Class name : ' . $reflector->getName() . &quot;\n&quot; ; echo &quot;Methods : \n&quot; ; var_dump($reflector->getMethods()); Outputs : Class name : Test Methods : array(1) { [0]=> &object(ReflectionMethod)#2 (2) { [&quot;name&quot;]=> string(6) &quot;testMe&quot; [&quot;class&quot;]=> string(4) &quot;Test&quot; } }
  • 83. Version 1 -> 2 ZF2 compatible Maybe : adding a multiGet() for the roles -> fewer cache queries Resources isAllowed() gets a new parameter
  • 84. can be combined with module/controller/action Negative privileges and negative roles (!)
  • 85. Hide controllers and actions from the interface (docblock)
  • 87. Apply roles to usergroup
  • 88. Setting it up library/Application/Acl.php -> main ACL class
  • 92. LoginController.php -> Login screen (usually placed somewhere else) modules/um/views/scripts/ index
  • 93. role Few lines in application.ini
  • 94. Where to get it Site : http://www.opensource.be/zfacl/ (Oct 25)
  • 95. Code : Github (see site)
  • 98. Contact Web http://techblog.wimgodden.be
  • 102. Please... Rate my talk : http://joind.in/4009