SlideShare a Scribd company logo
a simpler approach
   ACL stands for Access Control List
   Used for Authorization purpose (eg: who
    access what)
   Zend, CakePHP features ACL as key
    component of their framework
   What about CodeIgniter?
ACL in CodeIgniter
   Using our custom control check
function loadPage($pageID)
{
  if($_SESSION[„userType‟] != “member”)
  {
     die(“you do not have access to this page”);
  }
}
   And the check goes on & on, Hard coded in
    our controller files…..
   What is this hook?
    ◦ a means to tap into and modify the inner workings
      of the framework without hacking the core files
    ◦ Have you heard of wordpress or mediawiki hook?
    ◦ Examples:
      We want to execute a functionality before controllers
       are loaded
   Hooks must be enabled in CodeIgniter Config file
    $config['enable_hooks'] = True;
   Hooks are defined in
    application/config/hooks.php file. Each hook is
    specified as a part of a global array named $hook

$hook[„Hook_Point‟] = array(
                     'class' => 'MyClass',
                     'function' => 'Myfunction',
                     'filename' => 'Myclass.php',
                     'filepath' => 'hooks',
                     'params' => array()
                     );
   pre_system
    Called very early during system execution. Only the
    benchmark and hooks class have been loaded at this
    point. No routing or other processes have happened.
   pre_controller
    Called immediately prior to any of your controllers
    being called. All base classes, routing, and security
    checks have been done.
   post_controller_constructor
    Called immediately after your controller is
    instantiated, but prior to any method calls happening.
   post_controller
    Called immediately after your controller is fully
    executed.
   class The name of the class you wish to invoke. If you
    prefer to use a procedural function instead of a class,
    leave this item blank.
   function The function name you wish to call.
   filename The file name containing your class/function.
   filepath The name of the directory containing your script.
    Note: Your script must be located in a directory INSIDE
    your application folder, so the file path is relative to that
    folder. For example, if your script is located in
    application/hooks, you will simply use hooks as your
    filepath. If your script is located in
    application/hooks/utilities you will use hooks/utilities as
    your filepath. No trailing slash.
   params Any parameters you wish to pass to your script.
    This item is optional.
/* application/config/hooks.php */

$hook['pre_controller'] = array(
                    'class' => 'Accesscheck',
                    'function' => 'index',
                    'filename' => 'accesscheck.php',
                    'filepath' => 'hooks');
class Accesscheck
{
   public function index($params)
   {
        require_once('permissions.php');
        $baseURL = $GLOBALS['CFG']->config['base_url'];
        $routing =& load_class('Router');
        $class = $routing->fetch_class();
        $method = $routing->fetch_method();
if(! empty($doesNotRequireLogin[$class][$method])) { return true; }
else {
           if(! $_SESSION['userType']) {     //checking authentication
                    header("location: {$baseURL}common/login"); exit;
           }
           else {

if(empty($permissions[$_SESSION['userType']][$class][$method])
                 ||
$permissions[$_SESSION['userType']][$class][$method]!=true) {

                     header("location: {$baseURL}common/unauthorized");
exit;
                     } else {
                            return true;
                     }
                 }
        }
            header("location: {$baseURL}common/unauthorized");
<?php
$doesNotRequireLogin = array();
$permissions = array();
$doesNotRequireLogin['common']['index'] = true;
$doesNotRequireLogin['common']['login'] = true;
$doesNotRequireLogin['common']['dologin'] = true;
$doesNotRequireLogin['common']['unauthorized'] = true;
$doesNotRequireLogin['common']['message'] = true;
$doesNotRequireLogin['common']['forgotpassword'] = true;
$permissions[„member‟][„blog'][„post‟] = true;
$permissions[„member‟][„blog'][„view‟] = true;
$permissions[„member‟][„blog'][„save‟] = true;
$permissions[„member‟][„blog'][„rating‟] = true;
$permissions[„guest‟][„blog'][„view‟] = true;
   We have eliminated the process of writing the
    authorization code on each controller
    functions
   We have a better authorized application
   We have a central access point with
    permissions and check.
   We have used Array for better performance
    (you can use XML though)
   This solution is better suited for role based
    access as well as dynamic role option.
   ACL as a Library
    ◦ There are few libraries available from CodeIgniter
      wiki page and other sources which can be used for
      ACL purpose.
M. MIZANUR RAHMAN
          Founder & C.T.O
  Informatix Technologies
[mizan@informatixbd.com]

More Related Content

What's hot (20)

PDF
Achieving compliance With MongoDB Security
Mydbops
 
PDF
Monad Laws Must be Checked
Philip Schwarz
 
PDF
Optimizing MariaDB for maximum performance
MariaDB plc
 
PPTX
Sharding Methods for MongoDB
MongoDB
 
PDF
MySQL Performance schema missing_manual_flossuk
Valeriy Kravchuk
 
PDF
Mongodb - Scaling write performance
Daum DNA
 
PDF
Part 8 pengertian variabel dan cara penulisan variabel pascal
Syaiful Ahdan
 
PDF
Load Testing - How to Stress Your Odoo with Locust
Odoo
 
PDF
M|18 Deep Dive: InnoDB Transactions and Write Paths
MariaDB plc
 
PDF
MySQL Administrator 2021 - 네오클로바
NeoClova
 
PPTX
MariaDB Performance Tuning Crash Course
Severalnines
 
PPTX
MongoDB Schema Design: Practical Applications and Implications
MongoDB
 
PDF
MySQL Day Virtual: Best Practices Tips - Upgrading to MySQL 8.0
Frederic Descamps
 
PDF
PostgreSQL Materialized Views with Active Record
David Roberts
 
PDF
Advanced backup methods (Postgres@CERN)
Anastasia Lubennikova
 
PDF
[29DCF] PostgreSQL에서 DB Lock을 줄이는 5가지 팁
jiminlee81
 
PDF
Continuation Passing Style and Macros in Clojure - Jan 2012
Leonardo Borges
 
PDF
Large Table Partitioning with PostgreSQL and Django
EDB
 
PPTX
My sql failover test using orchestrator
YoungHeon (Roy) Kim
 
PDF
Gerenciamento de Backups PostgreSQL com pgbarman
Juliano Atanazio
 
Achieving compliance With MongoDB Security
Mydbops
 
Monad Laws Must be Checked
Philip Schwarz
 
Optimizing MariaDB for maximum performance
MariaDB plc
 
Sharding Methods for MongoDB
MongoDB
 
MySQL Performance schema missing_manual_flossuk
Valeriy Kravchuk
 
Mongodb - Scaling write performance
Daum DNA
 
Part 8 pengertian variabel dan cara penulisan variabel pascal
Syaiful Ahdan
 
Load Testing - How to Stress Your Odoo with Locust
Odoo
 
M|18 Deep Dive: InnoDB Transactions and Write Paths
MariaDB plc
 
MySQL Administrator 2021 - 네오클로바
NeoClova
 
MariaDB Performance Tuning Crash Course
Severalnines
 
MongoDB Schema Design: Practical Applications and Implications
MongoDB
 
MySQL Day Virtual: Best Practices Tips - Upgrading to MySQL 8.0
Frederic Descamps
 
PostgreSQL Materialized Views with Active Record
David Roberts
 
Advanced backup methods (Postgres@CERN)
Anastasia Lubennikova
 
[29DCF] PostgreSQL에서 DB Lock을 줄이는 5가지 팁
jiminlee81
 
Continuation Passing Style and Macros in Clojure - Jan 2012
Leonardo Borges
 
Large Table Partitioning with PostgreSQL and Django
EDB
 
My sql failover test using orchestrator
YoungHeon (Roy) Kim
 
Gerenciamento de Backups PostgreSQL com pgbarman
Juliano Atanazio
 

Viewers also liked (8)

PDF
PHP & MVC
Chris Weldon
 
PDF
CodeIgniter - PHP MVC Framework by silicongulf.com
Christopher Cubos
 
PPT
The Agile Process - Taming Your Process To Work For You
Nowell Strite
 
PPT
Introduction To CodeIgniter
schwebbie
 
PPT
Embracing Distributed Version Control
Nowell Strite
 
PDF
Djangocon 09 Presentation - Pluggable Applications
Nowell Strite
 
PDF
RESTful API Design & Implementation with CodeIgniter PHP Framework
Bo-Yi Wu
 
PPT
Introduction to Python
Nowell Strite
 
PHP & MVC
Chris Weldon
 
CodeIgniter - PHP MVC Framework by silicongulf.com
Christopher Cubos
 
The Agile Process - Taming Your Process To Work For You
Nowell Strite
 
Introduction To CodeIgniter
schwebbie
 
Embracing Distributed Version Control
Nowell Strite
 
Djangocon 09 Presentation - Pluggable Applications
Nowell Strite
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
Bo-Yi Wu
 
Introduction to Python
Nowell Strite
 
Ad

Similar to ACL in CodeIgniter (20)

PDF
symfony on action - WebTech 207
patter
 
PDF
The State of Lithium
Nate Abele
 
ODP
Codegnitorppt
sreedath c g
 
PPTX
Coding for Scale and Sanity
JimKellerES
 
PDF
Introduction Yii Framework
Tuan Nguyen
 
PDF
User Login in PHP with Session & MySQL.pdf
Be Problem Solver
 
PDF
How to Create Login and Registration API in PHP.pdf
Appweb Coders
 
KEY
CICONF 2012 - Don't Make Me Read Your Mind
ciconf
 
PPTX
My first zf presentation part two
isaaczfoster
 
PDF
Using and reusing CakePHP plugins
Pierre MARTIN
 
PDF
Unit testing after Zend Framework 1.8
Michelangelo van Dam
 
PDF
Web internship Yii Framework
Noveo
 
PDF
Ch ch-changes cake php2
markstory
 
PPTX
Oops in php
Gourishankar R Pujar
 
ODP
CodeIgniter PHP MVC Framework
Bo-Yi Wu
 
PDF
Hebrew, Introduction to Zend Controller And new technique
Nir Tayeb
 
PDF
Building Testable PHP Applications
chartjes
 
ODP
Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)
Wim Godden
 
PDF
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Arc & Codementor
 
PDF
Dealing with Legacy PHP Applications
Clinton Dreisbach
 
symfony on action - WebTech 207
patter
 
The State of Lithium
Nate Abele
 
Codegnitorppt
sreedath c g
 
Coding for Scale and Sanity
JimKellerES
 
Introduction Yii Framework
Tuan Nguyen
 
User Login in PHP with Session & MySQL.pdf
Be Problem Solver
 
How to Create Login and Registration API in PHP.pdf
Appweb Coders
 
CICONF 2012 - Don't Make Me Read Your Mind
ciconf
 
My first zf presentation part two
isaaczfoster
 
Using and reusing CakePHP plugins
Pierre MARTIN
 
Unit testing after Zend Framework 1.8
Michelangelo van Dam
 
Web internship Yii Framework
Noveo
 
Ch ch-changes cake php2
markstory
 
CodeIgniter PHP MVC Framework
Bo-Yi Wu
 
Hebrew, Introduction to Zend Controller And new technique
Nir Tayeb
 
Building Testable PHP Applications
chartjes
 
Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)
Wim Godden
 
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Arc & Codementor
 
Dealing with Legacy PHP Applications
Clinton Dreisbach
 
Ad

ACL in CodeIgniter

  • 2. ACL stands for Access Control List  Used for Authorization purpose (eg: who access what)  Zend, CakePHP features ACL as key component of their framework  What about CodeIgniter?
  • 4. Using our custom control check function loadPage($pageID) { if($_SESSION[„userType‟] != “member”) { die(“you do not have access to this page”); } }  And the check goes on & on, Hard coded in our controller files…..
  • 5. What is this hook? ◦ a means to tap into and modify the inner workings of the framework without hacking the core files ◦ Have you heard of wordpress or mediawiki hook? ◦ Examples:  We want to execute a functionality before controllers are loaded
  • 6. Hooks must be enabled in CodeIgniter Config file $config['enable_hooks'] = True;  Hooks are defined in application/config/hooks.php file. Each hook is specified as a part of a global array named $hook $hook[„Hook_Point‟] = array( 'class' => 'MyClass', 'function' => 'Myfunction', 'filename' => 'Myclass.php', 'filepath' => 'hooks', 'params' => array() );
  • 7. pre_system Called very early during system execution. Only the benchmark and hooks class have been loaded at this point. No routing or other processes have happened.  pre_controller Called immediately prior to any of your controllers being called. All base classes, routing, and security checks have been done.  post_controller_constructor Called immediately after your controller is instantiated, but prior to any method calls happening.  post_controller Called immediately after your controller is fully executed.
  • 8. class The name of the class you wish to invoke. If you prefer to use a procedural function instead of a class, leave this item blank.  function The function name you wish to call.  filename The file name containing your class/function.  filepath The name of the directory containing your script. Note: Your script must be located in a directory INSIDE your application folder, so the file path is relative to that folder. For example, if your script is located in application/hooks, you will simply use hooks as your filepath. If your script is located in application/hooks/utilities you will use hooks/utilities as your filepath. No trailing slash.  params Any parameters you wish to pass to your script. This item is optional.
  • 9. /* application/config/hooks.php */ $hook['pre_controller'] = array( 'class' => 'Accesscheck', 'function' => 'index', 'filename' => 'accesscheck.php', 'filepath' => 'hooks');
  • 10. class Accesscheck { public function index($params) { require_once('permissions.php'); $baseURL = $GLOBALS['CFG']->config['base_url']; $routing =& load_class('Router'); $class = $routing->fetch_class(); $method = $routing->fetch_method();
  • 11. if(! empty($doesNotRequireLogin[$class][$method])) { return true; } else { if(! $_SESSION['userType']) { //checking authentication header("location: {$baseURL}common/login"); exit; } else { if(empty($permissions[$_SESSION['userType']][$class][$method]) || $permissions[$_SESSION['userType']][$class][$method]!=true) { header("location: {$baseURL}common/unauthorized"); exit; } else { return true; } } } header("location: {$baseURL}common/unauthorized");
  • 12. <?php $doesNotRequireLogin = array(); $permissions = array(); $doesNotRequireLogin['common']['index'] = true; $doesNotRequireLogin['common']['login'] = true; $doesNotRequireLogin['common']['dologin'] = true; $doesNotRequireLogin['common']['unauthorized'] = true; $doesNotRequireLogin['common']['message'] = true; $doesNotRequireLogin['common']['forgotpassword'] = true;
  • 13. $permissions[„member‟][„blog'][„post‟] = true; $permissions[„member‟][„blog'][„view‟] = true; $permissions[„member‟][„blog'][„save‟] = true; $permissions[„member‟][„blog'][„rating‟] = true; $permissions[„guest‟][„blog'][„view‟] = true;
  • 14. We have eliminated the process of writing the authorization code on each controller functions  We have a better authorized application  We have a central access point with permissions and check.  We have used Array for better performance (you can use XML though)  This solution is better suited for role based access as well as dynamic role option.
  • 15. ACL as a Library ◦ There are few libraries available from CodeIgniter wiki page and other sources which can be used for ACL purpose.
  • 16. M. MIZANUR RAHMAN Founder & C.T.O Informatix Technologies [[email protected]]