Changeset 17943

Show
Ignore:
Timestamp:
10/06/08 10:02:59 (2 months ago)
Author:
bergie
Message:

Support sending object instance instead of class name for class-based privilege checking, fixes #326

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/midcom.core/midcom/services/auth.php

    r17900 r17943  
    879879        { 
    880880            debug_push_class(__CLASS__, __FUNCTION__); 
    881             debug_add("Querying privilege {$privilege} for user {$user->id} to class {$class}", MIDCOM_LOG_DEBUG); 
     881             
     882            if (is_object($class)) 
     883            { 
     884                $classname = get_class($class); 
     885            } 
     886            else 
     887            { 
     888                $classname = $class; 
     889            } 
     890             
     891            debug_add("Querying privilege {$privilege} for user {$user->id} to class {$classname}", MIDCOM_LOG_DEBUG); 
    882892            debug_pop(); 
    883893        } 
     
    901911        if ($class !== null) 
    902912        { 
    903             if (!class_exists($class)) 
    904             { 
    905                 if (   is_null($component) 
    906                     || !$_MIDCOM->componentloader->load_graceful($component)) 
     913            if (!is_object($class)) 
     914            { 
     915                if (!class_exists($class)) 
    907916                { 
    908                     debug_push_class(__CLASS__, __FUNCTION__); 
    909                     debug_add("can_user_do check to undefined class '{$class}'.", MIDCOM_LOG_ERROR); 
    910                     debug_pop(); 
    911                     return false; 
     917                    if (   is_null($component) 
     918                        || !$_MIDCOM->componentloader->load_graceful($component)) 
     919                    { 
     920                        debug_push_class(__CLASS__, __FUNCTION__); 
     921                        debug_add("can_user_do check to undefined class '{$class}'.", MIDCOM_LOG_ERROR); 
     922                        debug_pop(); 
     923                        return false; 
     924                    } 
    912925                } 
    913             } 
    914             $tmp_object = new $class(); 
     926                 
     927                $tmp_object = new $class(); 
     928            } 
     929            else 
     930            { 
     931                $tmp_object = $class; 
     932            } 
    915933            $this->_load_class_magic_privileges($tmp_object); 
    916934        } 
  • trunk/midcom/midcom.core/midcom/services/toolbars.php

    r17753 r17943  
    9191        parent::__construct(); 
    9292         
     93        // FIXME: initialize() should be called by the callee, not here in constructor 
    9394        $this->initialize(); 
    9495    } 
     
    118119 
    119120        if (   !$GLOBALS['midcom_config']['toolbars_enable_centralized'] 
    120             || !$_MIDCOM->auth->can_user_do('midcom:centralized_toolbar', null, 'midcom_services_toolbars')) 
     121            || !$_MIDCOM->auth->can_user_do('midcom:centralized_toolbar', null, $this)) 
    121122        { 
    122123            $still_initializing = false; 
     
    124125        } 
    125126 
    126         if ($_MIDCOM->auth->can_user_do('midcom:ajax', null, 'midcom_services_toolbars')) 
     127        if ($_MIDCOM->auth->can_user_do('midcom:ajax', null, $this)) 
    127128        { 
    128129            $_MIDCOM->enable_jquery();