Auth_Controller is now able to display a better message if the user is unauthorized

This message contains:
- the name of the called controller
- the name of the called method of the called controller
- all the possible permissions and related modes needed to acces to this content
This commit is contained in:
Paolo
2018-06-28 16:09:12 +02:00
parent 46e85a2317
commit 8f566e0499
3 changed files with 80 additions and 36 deletions
+38 -31
View File
@@ -144,52 +144,59 @@ class PermissionLib
$permissions = array($requiredPermissions[$calledMethod]);
}
// Loops through the required permissions
for ($pCounter = 0; $pCounter < count($permissions); $pCounter++)
if (!isEmptyArray($permissions))
{
// Checks if the permission is well formatted
if (strpos($permissions[$pCounter], PermissionLib::PERMISSION_SEPARATOR) !== false)
// Loops through the required permissions
for ($pCounter = 0; $pCounter < count($permissions); $pCounter++)
{
// Retrives permission and required access type from the $requiredPermissions array
list($permission, $requiredAccessType) = explode(PermissionLib::PERMISSION_SEPARATOR, $permissions[$pCounter]);
$accessType = null;
// Checks if the required access type is compliant with the HTTP method (GET => r, POST => w)
if ($requestMethod == self::READ_HTTP_METHOD
&& strpos($requiredAccessType, PermissionLib::READ_RIGHT) !== false)
// Checks if the permission is well formatted
if (strpos($permissions[$pCounter], PermissionLib::PERMISSION_SEPARATOR) !== false)
{
$accessType = PermissionLib::SELECT_RIGHT; // S
// Retrives permission and required access type from the $requiredPermissions array
list($permission, $requiredAccessType) = explode(PermissionLib::PERMISSION_SEPARATOR, $permissions[$pCounter]);
$accessType = null;
// Checks if the required access type is compliant with the HTTP method (GET => r, POST => w)
if ($requestMethod == self::READ_HTTP_METHOD
&& strpos($requiredAccessType, PermissionLib::READ_RIGHT) !== false)
{
$accessType = PermissionLib::SELECT_RIGHT; // S
}
elseif ($requestMethod == self::WRITE_HTTP_METHOD
&& strpos($requiredAccessType, PermissionLib::WRITE_RIGHT) !== false)
{
$accessType = PermissionLib::REPLACE_RIGHT.PermissionLib::DELETE_RIGHT; // UID
}
if ($accessType != null) // if compliant
{
// Checks if the user has the same required permissiond with the same required access type
$checkPermissions = $this->isBerechtigt($permission, $accessType);
// If the user has one of the permissionsm than exit the loop
if ($checkPermissions === true) break;
}
}
elseif ($requestMethod == self::WRITE_HTTP_METHOD
&& strpos($requiredAccessType, PermissionLib::WRITE_RIGHT) !== false)
else
{
$accessType = PermissionLib::REPLACE_RIGHT.PermissionLib::DELETE_RIGHT; // UID
}
if ($accessType != null) // if compliant
{
// Checks if the user has the same required permissiond with the same required access type
$checkPermissions = $this->isBerechtigt($permission, $accessType);
// If the user has one of the permissionsm than exit the loop
if ($checkPermissions === true) break;
show_error('The given permission does not use the correct format');
}
}
else
{
show_error('The given permission does not use the correct format');
}
}
else
{
show_error('No permissions are set for this method, an empty array is given');
}
}
else
{
show_error('Your are trying to access to this content with a not valid HTTP method');
show_error('You are trying to access to this content with a not valid HTTP method');
}
}
else
{
show_error('The given permission array does not contain the called method');
show_error('The given permission array does not contain the called method or is not correctly set');
}
}
else