Changeset 1261 for trunk/wifidog-auth/wifidog/classes/Security.php
- Timestamp:
- 07/21/07 00:59:33 (5 years ago)
- Files:
-
- 1 modified
-
trunk/wifidog-auth/wifidog/classes/Security.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog-auth/wifidog/classes/Security.php
r1249 r1261 76 76 $permission = $permissionsCheck[0]; 77 77 $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'; 84 90 $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'"; 88 92 if($operator == 'OR') { 89 93 $first?$sql .= " ($sqlSelect)\n":$sql .= ", ($sqlSelect)\n"; … … 122 126 /* Check if the current user has the requested permission 123 127 * @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) 128 132 { 129 133 return self::hasPermissionsHelper(array(array($permission, $targetObject)), 'AND', $user); 130 134 } 131 132 /* Check if the current user has ANY of the requested permission135 136 /* Check if the current user has ANY of the requested permission 133 137 * @param $permissionsArray An two dimensionnal array of permissions to check 134 138 * permissionsArray[]=array($permission, $targetObject); … … 149 153 return self::hasPermissionsHelper($permissionsArray, 'AND', $user); 150 154 } 151 155 152 156 /* require that the user has the current permission, otherwise, throw up an interface to deal with the proplem 153 157 * @param permission The permission to check 154 * @param $targetObject The Object on which the perm ssion 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) 158 162 { 159 163 $hasPermission = self::hasPermission($permission, $targetObject, User::getCurrentUser()); … … 177 181 return true; 178 182 } 179 183 180 184 /* Require that the user has ALL of the requested permissions 181 185 * @param $permissionsArray A two dimensionnal array of permissions to check … … 191 195 return true; 192 196 } 193 197 194 198 private static function handleMissingPermissions(Array $permissionsArray) 195 199 { … … 199 203 $targetObject = $permissionsCheck[1]; 200 204 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')); 202 206 } 203 207 } … … 205 209 throw new SecurityException($msg); 206 210 } 207 211 208 212 /* Returns an array of objects for which the user has the specified permission 209 213 * @param permission The permission to check
