Show
Ignore:
Timestamp:
07/21/07 00:59:33 (5 years ago)
Author:
benoitg
Message:
  • At long last, implement #9: Automatic new node creation. When attempting to login from an unknown node, the user (if he has the permissions) will be prompted to create the node, or "steal" en existing one (for hardware swaps).
  • Refactor Node:getSelectNodeUI().
  • Menu.php: Fix small oversight causing menu not to clear.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/wifidog/classes/Security.php

    r1249 r1261  
    7676                $permission = $permissionsCheck[0]; 
    7777                $targetObject = $permissionsCheck[1]; 
    78                 $object_class = get_class($targetObject); 
    79                 if($permission->getTargetObjectClass()!=$object_class) { 
    80                     throw new Exception(sprintf("Tried to check if an object of class %s has a permission of type %s",$object_class, $permission->getTargetObjectClass())); 
    81                 } 
    82                 $table = strtolower($object_class).'_stakeholders'; 
    83                 $object_id = $db->escapeString($targetObject->getId()); 
     78                $objectClass = $permission->getTargetObjectClass(); 
     79                if($targetObject) { 
     80                    if($objectClass!=get_class($targetObject)) { 
     81                        throw new Exception(sprintf("Tried to check if an object of class %s has a permission of type %s",$objectClass, get_class($targetObject))); 
     82                    } 
     83                    $objectId = $db->escapeString($targetObject->getId()); 
     84                    $objectSqlAnd = "\n AND object_id = '$objectId' \n"; 
     85                } 
     86                else { 
     87                    $objectSqlAnd = ''; 
     88                } 
     89                $table = strtolower($objectClass).'_stakeholders'; 
    8490                $permissionIdStr = $db->escapeString($permission->getId()); 
    85  
    86  
    87                 $sqlSelect = "SELECT permission_id FROM $table JOIN role_has_permissions USING (role_id) WHERE object_id = '$object_id' AND user_id='{$user->getId()}' AND permission_id = '$permissionIdStr'"; 
     91                $sqlSelect = "SELECT permission_id FROM $table JOIN role_has_permissions USING (role_id) WHERE user_id='{$user->getId()}' $objectSqlAnd AND permission_id = '$permissionIdStr'"; 
    8892                if($operator == 'OR') { 
    8993                    $first?$sql .= " ($sqlSelect)\n":$sql .= ", ($sqlSelect)\n"; 
     
    122126    /* Check if the current user has the requested permission 
    123127     * @param permission The permission to check 
    124      * @param $targetObject The Object on which the permssion applies (Network, Server, etc.) 
    125      * @param user User object, optional, if unspecified, the current user is used.  Note that there may be no current user (annonymous) 
    126      */ 
    127     public static function hasPermission(Permission $permission, $targetObject, $user=null) 
     128     * @param $targetObject The Object on which the permssion applies (Network, Server, etc.)  If null, the user must have this permission on at least one object 
     129     * @param user User object, optional, if unspecified, the current user is used.  Note that there may be no current user (annonymous) 
     130     */ 
     131    public static function hasPermission(Permission $permission, $targetObject=null, $user=null) 
    128132    { 
    129133        return self::hasPermissionsHelper(array(array($permission, $targetObject)), 'AND', $user); 
    130134    } 
    131      
    132         /* Check if the current user has ANY of the requested permission 
     135 
     136    /* Check if the current user has ANY of the requested permission 
    133137     * @param $permissionsArray An two dimensionnal array of permissions to check 
    134138     * permissionsArray[]=array($permission, $targetObject); 
     
    149153        return self::hasPermissionsHelper($permissionsArray, 'AND', $user); 
    150154    } 
    151      
     155 
    152156    /* require that the user has the current permission, otherwise, throw up an interface to deal with the proplem 
    153157     * @param permission The permission to check 
    154      * @param $targetObject The Object on which the permssion applies (Network, Server, etc.) 
    155      * @param user User object, optional, if unspecified, the current user is used.  Note that there may be no current user (annonymous) 
    156      */ 
    157     public static function requirePermission(Permission $permission, $targetObject) 
     158     * @param $targetObject The Object on which the permission applies (Network, Server, etc.).  If null, the user must have this permission on at least one object 
     159     * @param user User object, optional, if unspecified, the current user is used.  Note that there may be no current user (annonymous) 
     160     */ 
     161    public static function requirePermission(Permission $permission, $targetObject=null) 
    158162    { 
    159163        $hasPermission = self::hasPermission($permission, $targetObject, User::getCurrentUser()); 
     
    177181        return true; 
    178182    } 
    179      
     183 
    180184    /* Require that the user has ALL of the requested permissions 
    181185     * @param $permissionsArray A two dimensionnal array of permissions to check 
     
    191195        return true; 
    192196    } 
    193      
     197 
    194198    private static function handleMissingPermissions(Array $permissionsArray) 
    195199    { 
     
    199203            $targetObject = $permissionsCheck[1]; 
    200204            if(!self::hasPermission($permission, $targetObject)) { 
    201                 $missingPerms .= sprintf(_("%s (%s) on  %s object %s")."<br/>\n", $permission->getId(), $permission->getDescription(), get_class($targetObject), (string)$targetObject); 
     205                $missingPerms .= sprintf(_("%s (%s) on  %s: %s")."<br/>\n", $permission->getId(), $permission->getDescription(), $permission->getTargetObjectClass(), $targetObject?(string)$targetObject:_('Any')); 
    202206            } 
    203207        } 
     
    205209        throw new SecurityException($msg); 
    206210    } 
    207      
     211 
    208212    /* Returns an array of objects for which the user has the specified permission 
    209213     * @param permission The permission to check