TYPO3中fe_users的细粒度文件访问控制和文件夹访问权限

问题描述 投票:0回答:0

我在 TYPO3 中面临文件访问控制的挑战,我希望能从社区得到一些指导或建议。

问题: 我需要在 TYPO3 中实现一个文件访问控制系统,用户可以根据他们的个人权限访问特定文件夹。我正在使用

sr_feuser_register
扩展来创建前端用户帐户,并且我已将其修改为自动为每个新用户创建一个文件夹(请参见下面的代码)。现在,我想授予每个用户只读取他们各自文件夹的权限。

到目前为止我尝试了什么: 我探索了 TYPO3 中的内置用户组功能,但它只允许我在组级别分配访问权限,而不是在单个文件夹级别。 我已经研究了可用的 TYPO3 扩展,例如

secure_downloads
fal_securedownload
等,但它们似乎都没有提供我需要的确切功能。

期望的解决方案: 我正在寻找在 TYPO3 中实现细粒度文件访问控制的建议、指导或替代方法。具体来说,我想授予每个用户对自己文件夹的读取权限,同时限制对其他用户文件夹的访问权限。目标是将文件上传到 fileadmin 位置,然后前端用户可以通过他们的登录凭据访问该位置。 我目前正在使用 TYPO3 v11.5.22 版本,没有作曲家模式和

sr_feuser_register
扩展来管理用户注册。理想情况下,我想集成一个与这些组件无缝协作的解决方案。

如果它们提供所需的功能,我愿意接受任何自定义解决方案或使用第三方扩展。

对于此事的任何帮助或见解将不胜感激。提前谢谢你!

这是我添加到

CreateActionController.php
扩展的
sr_feuser_register
中的代码,用于在
fileadmin
中创建自定义文件夹:

<?php
namespace SJBR\SrFeuserRegister\Controller;

//....classes

/**
 * Create action controller
 */
class CreateActionController extends AbstractActionController
{
    /**
     * Processes the create request
     *
     * @param array $dataArray: array of form input fields
     * @param string $cmd: the command
     * @param string $cmdKey: the command key
     * @return string the template with substituted markers
     */
    public function doProcessing(array $finalDataArray, $cmd, $cmdKey) {
        

        //......


        // Set the time zone
        date_default_timezone_set('Europe/Berlin'); // Replace 'Europe/Berlin' with your desired time zone

        // Get the current date
        $currentDate = date('ymd');

        // Prepare the folder name
        $firstName = $finalDataArray['first_name'];
        $lastName = $finalDataArray['last_name'];

        // Convert special characters to ASCII equivalents
        $firstName = iconv('UTF-8', 'ASCII//TRANSLIT', $firstName);
        $lastName = iconv('UTF-8', 'ASCII//TRANSLIT', $lastName);

        // Replace umlaut characters with their ASCII equivalents
        $firstName = str_replace(['ä', 'ö', 'ü', 'ß'], ['ae', 'oe', 'ue', 'ss'], $firstName);
        $lastName = str_replace(['ä', 'ö', 'ü', 'ß'], ['ae', 'oe', 'ue', 'ss'], $lastName);

        // Remove non-alphanumeric characters
        $firstName = preg_replace('/[^a-zA-Z0-9]/', '', $firstName);
        $lastName = preg_replace('/[^a-zA-Z0-9]/', '', $lastName);

        // Check if the first name and last name are not empty
        if (!empty($firstName) && !empty($lastName)) {
            // Construct the folder name
            $folderName = $currentDate . '_' . strtolower($lastName) . '_' . strtolower($firstName);

            // Create the folder path
            $folderPath = 'fileadmin/data/' . $folderName;

            // Attempt to create the folder
            if (mkdir($folderPath, 0755)) {
                // Folder created successfully
                // Set folder permissions
                chmod($folderPath, 0755); // Adjust the permissions as needed

                // Get the FE user UID
                $feUserUid = $GLOBALS['TSFE']->fe_user->user['uid'];

                // Set folder access rights for the FE user
                $feUserUid = $GLOBALS['TSFE']->fe_user->user['uid'];

                // Get the FE user group ID
                $groupId = $GLOBALS['TSFE']->fe_user->user['usergroup'];

                // Get the TYPO3 database connection
                $databaseConnection = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)->getConnectionForTable('sys_file_metadata');

                // Clear any existing folder permissions for the patient's folder
                $databaseConnection->exec_DELETEquery(
                    'sys_file_metadata',
                    $databaseConnection->quoteIdentifier('table_local') . ' = 1 AND ' .
                    $databaseConnection->quoteIdentifier('identifier') . ' = ' . $databaseConnection->quote($folderName)
                );

                // Grant folder permissions to the FE user group for the patient's folder
                $databaseConnection->insert(
                    'sys_file_metadata',
                    [
                        'uid' => $groupId,
                        'table_local' => 1,
                        'identifier' => $folderName,
                        'permissions' => 31, // Set desired folder permissions (e.g., 31 for full access)
                        'modified' => time()
                    ]
                );
            }
        }



        //......
    }
}
typo3 file-permissions access-control typo3-extensions sr-feuser-registration
© www.soinside.com 2019 - 2024. All rights reserved.