@@ -34,7 +34,7 @@ |
||
| 34 | 34 | * @package OC\AppFramework\Middleware\Security\Exceptions |
| 35 | 35 | */ |
| 36 | 36 | class CrossSiteRequestForgeryException extends SecurityException { |
| 37 | - public function __construct() { |
|
| 38 | - parent::__construct('CSRF check failed', Http::STATUS_PRECONDITION_FAILED); |
|
| 39 | - } |
|
| 37 | + public function __construct() { |
|
| 38 | + parent::__construct('CSRF check failed', Http::STATUS_PRECONDITION_FAILED); |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | * @package OC\AppFramework\Middleware\Security\Exceptions |
| 35 | 35 | */ |
| 36 | 36 | class AppNotEnabledException extends SecurityException { |
| 37 | - public function __construct() { |
|
| 38 | - parent::__construct('App is not enabled', Http::STATUS_PRECONDITION_FAILED); |
|
| 39 | - } |
|
| 37 | + public function __construct() { |
|
| 38 | + parent::__construct('App is not enabled', Http::STATUS_PRECONDITION_FAILED); |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | * @package OC\AppFramework\Middleware\Security\Exceptions |
| 35 | 35 | */ |
| 36 | 36 | class NotLoggedInException extends SecurityException { |
| 37 | - public function __construct() { |
|
| 38 | - parent::__construct('Current user is not logged in', Http::STATUS_UNAUTHORIZED); |
|
| 39 | - } |
|
| 37 | + public function __construct() { |
|
| 38 | + parent::__construct('Current user is not logged in', Http::STATUS_UNAUTHORIZED); |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | } |
| 34 | 34 | if ($table !== null) { |
| 35 | 35 | $suffix = '_SEQ'; |
| 36 | - $table = '"' . $table . $suffix . '"'; |
|
| 36 | + $table = '"'.$table.$suffix.'"'; |
|
| 37 | 37 | } |
| 38 | 38 | return $this->conn->realLastInsertId($table); |
| 39 | 39 | } |
@@ -8,24 +8,24 @@ |
||
| 8 | 8 | namespace OC\DB; |
| 9 | 9 | |
| 10 | 10 | class AdapterOCI8 extends Adapter { |
| 11 | - public function lastInsertId($table, bool $allowRetry = true): int { |
|
| 12 | - if (is_null($table)) { |
|
| 13 | - throw new \InvalidArgumentException('Oracle requires a table name to be passed into lastInsertId()'); |
|
| 14 | - } |
|
| 15 | - if ($table !== null) { |
|
| 16 | - $suffix = '_SEQ'; |
|
| 17 | - $table = '"' . $table . $suffix . '"'; |
|
| 18 | - } |
|
| 19 | - return $this->conn->realLastInsertId($table); |
|
| 20 | - } |
|
| 11 | + public function lastInsertId($table, bool $allowRetry = true): int { |
|
| 12 | + if (is_null($table)) { |
|
| 13 | + throw new \InvalidArgumentException('Oracle requires a table name to be passed into lastInsertId()'); |
|
| 14 | + } |
|
| 15 | + if ($table !== null) { |
|
| 16 | + $suffix = '_SEQ'; |
|
| 17 | + $table = '"' . $table . $suffix . '"'; |
|
| 18 | + } |
|
| 19 | + return $this->conn->realLastInsertId($table); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - public const UNIX_TIMESTAMP_REPLACEMENT = "(cast(sys_extract_utc(systimestamp) as date) - date'1970-01-01') * 86400"; |
|
| 22 | + public const UNIX_TIMESTAMP_REPLACEMENT = "(cast(sys_extract_utc(systimestamp) as date) - date'1970-01-01') * 86400"; |
|
| 23 | 23 | |
| 24 | - public function fixupStatement($statement) { |
|
| 25 | - $statement = preg_replace('/`(\w+)` ILIKE \?/', 'REGEXP_LIKE(`$1`, \'^\' || REPLACE(?, \'%\', \'.*\') || \'$\', \'i\')', $statement); |
|
| 26 | - $statement = str_replace('`', '"', $statement); |
|
| 27 | - $statement = str_ireplace('NOW()', 'CURRENT_TIMESTAMP', $statement); |
|
| 28 | - $statement = str_ireplace('UNIX_TIMESTAMP()', self::UNIX_TIMESTAMP_REPLACEMENT, $statement); |
|
| 29 | - return $statement; |
|
| 30 | - } |
|
| 24 | + public function fixupStatement($statement) { |
|
| 25 | + $statement = preg_replace('/`(\w+)` ILIKE \?/', 'REGEXP_LIKE(`$1`, \'^\' || REPLACE(?, \'%\', \'.*\') || \'$\', \'i\')', $statement); |
|
| 26 | + $statement = str_replace('`', '"', $statement); |
|
| 27 | + $statement = str_ireplace('NOW()', 'CURRENT_TIMESTAMP', $statement); |
|
| 28 | + $statement = str_ireplace('UNIX_TIMESTAMP()', self::UNIX_TIMESTAMP_REPLACEMENT, $statement); |
|
| 29 | + return $statement; |
|
| 30 | + } |
|
| 31 | 31 | } |
@@ -28,41 +28,41 @@ |
||
| 28 | 28 | use OCP\Preview\IProvider; |
| 29 | 29 | |
| 30 | 30 | abstract class Provider implements IProvider { |
| 31 | - private $options; |
|
| 31 | + private $options; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Constructor |
|
| 35 | - * |
|
| 36 | - * @param array $options |
|
| 37 | - */ |
|
| 38 | - public function __construct(array $options = []) { |
|
| 39 | - $this->options = $options; |
|
| 40 | - } |
|
| 33 | + /** |
|
| 34 | + * Constructor |
|
| 35 | + * |
|
| 36 | + * @param array $options |
|
| 37 | + */ |
|
| 38 | + public function __construct(array $options = []) { |
|
| 39 | + $this->options = $options; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @return string Regex with the mimetypes that are supported by this provider |
|
| 44 | - */ |
|
| 45 | - abstract public function getMimeType(); |
|
| 42 | + /** |
|
| 43 | + * @return string Regex with the mimetypes that are supported by this provider |
|
| 44 | + */ |
|
| 45 | + abstract public function getMimeType(); |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Check if a preview can be generated for $path |
|
| 49 | - * |
|
| 50 | - * @param \OCP\Files\FileInfo $file |
|
| 51 | - * @return bool |
|
| 52 | - */ |
|
| 53 | - public function isAvailable(\OCP\Files\FileInfo $file) { |
|
| 54 | - return true; |
|
| 55 | - } |
|
| 47 | + /** |
|
| 48 | + * Check if a preview can be generated for $path |
|
| 49 | + * |
|
| 50 | + * @param \OCP\Files\FileInfo $file |
|
| 51 | + * @return bool |
|
| 52 | + */ |
|
| 53 | + public function isAvailable(\OCP\Files\FileInfo $file) { |
|
| 54 | + return true; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Generates thumbnail which fits in $maxX and $maxY and keeps the aspect ratio, for file at path $path |
|
| 59 | - * |
|
| 60 | - * @param string $path Path of file |
|
| 61 | - * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 62 | - * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 63 | - * @param bool $scalingup Disable/Enable upscaling of previews |
|
| 64 | - * @param \OC\Files\View $fileview fileview object of user folder |
|
| 65 | - * @return bool|\OCP\IImage false if no preview was generated |
|
| 66 | - */ |
|
| 67 | - abstract public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview); |
|
| 57 | + /** |
|
| 58 | + * Generates thumbnail which fits in $maxX and $maxY and keeps the aspect ratio, for file at path $path |
|
| 59 | + * |
|
| 60 | + * @param string $path Path of file |
|
| 61 | + * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 62 | + * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 63 | + * @param bool $scalingup Disable/Enable upscaling of previews |
|
| 64 | + * @param \OC\Files\View $fileview fileview object of user folder |
|
| 65 | + * @return bool|\OCP\IImage false if no preview was generated |
|
| 66 | + */ |
|
| 67 | + abstract public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview); |
|
| 68 | 68 | } |
@@ -32,7 +32,7 @@ |
||
| 32 | 32 | * @param string $name |
| 33 | 33 | */ |
| 34 | 34 | public function __construct($id, $name) { |
| 35 | - parent::__construct('Id "' . $id . '" already used by encryption module "' . $name . '"'); |
|
| 35 | + parent::__construct('Id "'.$id.'" already used by encryption module "'.$name.'"'); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | } |
@@ -25,11 +25,11 @@ |
||
| 25 | 25 | use OCP\Encryption\Exceptions\GenericEncryptionException; |
| 26 | 26 | |
| 27 | 27 | class ModuleAlreadyExistsException extends GenericEncryptionException { |
| 28 | - /** |
|
| 29 | - * @param string $id |
|
| 30 | - * @param string $name |
|
| 31 | - */ |
|
| 32 | - public function __construct($id, $name) { |
|
| 33 | - parent::__construct('Id "' . $id . '" already used by encryption module "' . $name . '"'); |
|
| 34 | - } |
|
| 28 | + /** |
|
| 29 | + * @param string $id |
|
| 30 | + * @param string $name |
|
| 31 | + */ |
|
| 32 | + public function __construct($id, $name) { |
|
| 33 | + parent::__construct('Id "' . $id . '" already used by encryption module "' . $name . '"'); |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -274,7 +274,7 @@ |
||
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | // check if key storage is mounted correctly |
| 277 | - if ($this->rootView->file_exists($rootDir . '/' . Storage::KEY_STORAGE_MARKER)) { |
|
| 277 | + if ($this->rootView->file_exists($rootDir.'/'.Storage::KEY_STORAGE_MARKER)) { |
|
| 278 | 278 | return true; |
| 279 | 279 | } |
| 280 | 280 | |
@@ -21,210 +21,210 @@ |
||
| 21 | 21 | use Psr\Log\LoggerInterface; |
| 22 | 22 | |
| 23 | 23 | class Manager implements IManager { |
| 24 | - protected array $encryptionModules; |
|
| 25 | - |
|
| 26 | - public function __construct( |
|
| 27 | - protected IConfig $config, |
|
| 28 | - protected LoggerInterface $logger, |
|
| 29 | - protected IL10N $l, |
|
| 30 | - protected View $rootView, |
|
| 31 | - protected Util $util, |
|
| 32 | - protected ArrayCache $arrayCache, |
|
| 33 | - ) { |
|
| 34 | - $this->encryptionModules = []; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Check if encryption is enabled |
|
| 39 | - * |
|
| 40 | - * @return bool true if enabled, false if not |
|
| 41 | - */ |
|
| 42 | - public function isEnabled() { |
|
| 43 | - $installed = $this->config->getSystemValueBool('installed', false); |
|
| 44 | - if (!$installed) { |
|
| 45 | - return false; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - $enabled = $this->config->getAppValue('core', 'encryption_enabled', 'no'); |
|
| 49 | - return $enabled === 'yes'; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * check if new encryption is ready |
|
| 54 | - * |
|
| 55 | - * @return bool |
|
| 56 | - * @throws ServiceUnavailableException |
|
| 57 | - */ |
|
| 58 | - public function isReady() { |
|
| 59 | - if ($this->isKeyStorageReady() === false) { |
|
| 60 | - throw new ServiceUnavailableException('Key Storage is not ready'); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - return true; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @param string $user |
|
| 68 | - */ |
|
| 69 | - public function isReadyForUser($user) { |
|
| 70 | - if (!$this->isReady()) { |
|
| 71 | - return false; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - foreach ($this->getEncryptionModules() as $module) { |
|
| 75 | - /** @var IEncryptionModule $m */ |
|
| 76 | - $m = call_user_func($module['callback']); |
|
| 77 | - if (!$m->isReadyForUser($user)) { |
|
| 78 | - return false; |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - return true; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Registers an callback function which must return an encryption module instance |
|
| 87 | - * |
|
| 88 | - * @param string $id |
|
| 89 | - * @param string $displayName |
|
| 90 | - * @param callable $callback |
|
| 91 | - * @throws Exceptions\ModuleAlreadyExistsException |
|
| 92 | - */ |
|
| 93 | - public function registerEncryptionModule($id, $displayName, callable $callback) { |
|
| 94 | - if (isset($this->encryptionModules[$id])) { |
|
| 95 | - throw new Exceptions\ModuleAlreadyExistsException($id, $displayName); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - $this->encryptionModules[$id] = [ |
|
| 99 | - 'id' => $id, |
|
| 100 | - 'displayName' => $displayName, |
|
| 101 | - 'callback' => $callback, |
|
| 102 | - ]; |
|
| 103 | - |
|
| 104 | - $defaultEncryptionModuleId = $this->getDefaultEncryptionModuleId(); |
|
| 105 | - |
|
| 106 | - if (empty($defaultEncryptionModuleId)) { |
|
| 107 | - $this->setDefaultEncryptionModule($id); |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Unregisters an encryption module |
|
| 113 | - * |
|
| 114 | - * @param string $moduleId |
|
| 115 | - */ |
|
| 116 | - public function unregisterEncryptionModule($moduleId) { |
|
| 117 | - unset($this->encryptionModules[$moduleId]); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * get a list of all encryption modules |
|
| 122 | - * |
|
| 123 | - * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]] |
|
| 124 | - */ |
|
| 125 | - public function getEncryptionModules() { |
|
| 126 | - return $this->encryptionModules; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * get a specific encryption module |
|
| 131 | - * |
|
| 132 | - * @param string $moduleId |
|
| 133 | - * @return IEncryptionModule |
|
| 134 | - * @throws Exceptions\ModuleDoesNotExistsException |
|
| 135 | - */ |
|
| 136 | - public function getEncryptionModule($moduleId = '') { |
|
| 137 | - if (empty($moduleId)) { |
|
| 138 | - return $this->getDefaultEncryptionModule(); |
|
| 139 | - } |
|
| 140 | - if (isset($this->encryptionModules[$moduleId])) { |
|
| 141 | - return call_user_func($this->encryptionModules[$moduleId]['callback']); |
|
| 142 | - } |
|
| 143 | - $message = "Module with ID: $moduleId does not exist."; |
|
| 144 | - $hint = $this->l->t('Module with ID: %s does not exist. Please enable it in your apps settings or contact your administrator.', [$moduleId]); |
|
| 145 | - throw new Exceptions\ModuleDoesNotExistsException($message, $hint); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * get default encryption module |
|
| 150 | - * |
|
| 151 | - * @return \OCP\Encryption\IEncryptionModule |
|
| 152 | - * @throws Exceptions\ModuleDoesNotExistsException |
|
| 153 | - */ |
|
| 154 | - protected function getDefaultEncryptionModule() { |
|
| 155 | - $defaultModuleId = $this->getDefaultEncryptionModuleId(); |
|
| 156 | - if (empty($defaultModuleId)) { |
|
| 157 | - $message = 'No default encryption module defined'; |
|
| 158 | - throw new Exceptions\ModuleDoesNotExistsException($message); |
|
| 159 | - } |
|
| 160 | - if (isset($this->encryptionModules[$defaultModuleId])) { |
|
| 161 | - return call_user_func($this->encryptionModules[$defaultModuleId]['callback']); |
|
| 162 | - } |
|
| 163 | - $message = 'Default encryption module not loaded'; |
|
| 164 | - throw new Exceptions\ModuleDoesNotExistsException($message); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * set default encryption module Id |
|
| 169 | - * |
|
| 170 | - * @param string $moduleId |
|
| 171 | - * @return bool |
|
| 172 | - */ |
|
| 173 | - public function setDefaultEncryptionModule($moduleId) { |
|
| 174 | - try { |
|
| 175 | - $this->getEncryptionModule($moduleId); |
|
| 176 | - } catch (\Exception $e) { |
|
| 177 | - return false; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - $this->config->setAppValue('core', 'default_encryption_module', $moduleId); |
|
| 181 | - return true; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * get default encryption module Id |
|
| 186 | - * |
|
| 187 | - * @return string |
|
| 188 | - */ |
|
| 189 | - public function getDefaultEncryptionModuleId() { |
|
| 190 | - return $this->config->getAppValue('core', 'default_encryption_module'); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Add storage wrapper |
|
| 195 | - */ |
|
| 196 | - public function setupStorage() { |
|
| 197 | - // If encryption is disabled and there are no loaded modules it makes no sense to load the wrapper |
|
| 198 | - if (!empty($this->encryptionModules) || $this->isEnabled()) { |
|
| 199 | - $encryptionWrapper = new EncryptionWrapper($this->arrayCache, $this, $this->logger); |
|
| 200 | - Filesystem::addStorageWrapper('oc_encryption', [$encryptionWrapper, 'wrapStorage'], 2); |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - public function forceWrapStorage(IMountPoint $mountPoint, IStorage $storage) { |
|
| 205 | - $encryptionWrapper = new EncryptionWrapper($this->arrayCache, $this, $this->logger); |
|
| 206 | - return $encryptionWrapper->wrapStorage($mountPoint->getMountPoint(), $storage, $mountPoint, true); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * check if key storage is ready |
|
| 212 | - * |
|
| 213 | - * @return bool |
|
| 214 | - */ |
|
| 215 | - protected function isKeyStorageReady() { |
|
| 216 | - $rootDir = $this->util->getKeyStorageRoot(); |
|
| 217 | - |
|
| 218 | - // the default root is always valid |
|
| 219 | - if ($rootDir === '') { |
|
| 220 | - return true; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - // check if key storage is mounted correctly |
|
| 224 | - if ($this->rootView->file_exists($rootDir . '/' . Storage::KEY_STORAGE_MARKER)) { |
|
| 225 | - return true; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - return false; |
|
| 229 | - } |
|
| 24 | + protected array $encryptionModules; |
|
| 25 | + |
|
| 26 | + public function __construct( |
|
| 27 | + protected IConfig $config, |
|
| 28 | + protected LoggerInterface $logger, |
|
| 29 | + protected IL10N $l, |
|
| 30 | + protected View $rootView, |
|
| 31 | + protected Util $util, |
|
| 32 | + protected ArrayCache $arrayCache, |
|
| 33 | + ) { |
|
| 34 | + $this->encryptionModules = []; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Check if encryption is enabled |
|
| 39 | + * |
|
| 40 | + * @return bool true if enabled, false if not |
|
| 41 | + */ |
|
| 42 | + public function isEnabled() { |
|
| 43 | + $installed = $this->config->getSystemValueBool('installed', false); |
|
| 44 | + if (!$installed) { |
|
| 45 | + return false; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + $enabled = $this->config->getAppValue('core', 'encryption_enabled', 'no'); |
|
| 49 | + return $enabled === 'yes'; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * check if new encryption is ready |
|
| 54 | + * |
|
| 55 | + * @return bool |
|
| 56 | + * @throws ServiceUnavailableException |
|
| 57 | + */ |
|
| 58 | + public function isReady() { |
|
| 59 | + if ($this->isKeyStorageReady() === false) { |
|
| 60 | + throw new ServiceUnavailableException('Key Storage is not ready'); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + return true; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @param string $user |
|
| 68 | + */ |
|
| 69 | + public function isReadyForUser($user) { |
|
| 70 | + if (!$this->isReady()) { |
|
| 71 | + return false; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + foreach ($this->getEncryptionModules() as $module) { |
|
| 75 | + /** @var IEncryptionModule $m */ |
|
| 76 | + $m = call_user_func($module['callback']); |
|
| 77 | + if (!$m->isReadyForUser($user)) { |
|
| 78 | + return false; |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + return true; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Registers an callback function which must return an encryption module instance |
|
| 87 | + * |
|
| 88 | + * @param string $id |
|
| 89 | + * @param string $displayName |
|
| 90 | + * @param callable $callback |
|
| 91 | + * @throws Exceptions\ModuleAlreadyExistsException |
|
| 92 | + */ |
|
| 93 | + public function registerEncryptionModule($id, $displayName, callable $callback) { |
|
| 94 | + if (isset($this->encryptionModules[$id])) { |
|
| 95 | + throw new Exceptions\ModuleAlreadyExistsException($id, $displayName); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + $this->encryptionModules[$id] = [ |
|
| 99 | + 'id' => $id, |
|
| 100 | + 'displayName' => $displayName, |
|
| 101 | + 'callback' => $callback, |
|
| 102 | + ]; |
|
| 103 | + |
|
| 104 | + $defaultEncryptionModuleId = $this->getDefaultEncryptionModuleId(); |
|
| 105 | + |
|
| 106 | + if (empty($defaultEncryptionModuleId)) { |
|
| 107 | + $this->setDefaultEncryptionModule($id); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Unregisters an encryption module |
|
| 113 | + * |
|
| 114 | + * @param string $moduleId |
|
| 115 | + */ |
|
| 116 | + public function unregisterEncryptionModule($moduleId) { |
|
| 117 | + unset($this->encryptionModules[$moduleId]); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * get a list of all encryption modules |
|
| 122 | + * |
|
| 123 | + * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]] |
|
| 124 | + */ |
|
| 125 | + public function getEncryptionModules() { |
|
| 126 | + return $this->encryptionModules; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * get a specific encryption module |
|
| 131 | + * |
|
| 132 | + * @param string $moduleId |
|
| 133 | + * @return IEncryptionModule |
|
| 134 | + * @throws Exceptions\ModuleDoesNotExistsException |
|
| 135 | + */ |
|
| 136 | + public function getEncryptionModule($moduleId = '') { |
|
| 137 | + if (empty($moduleId)) { |
|
| 138 | + return $this->getDefaultEncryptionModule(); |
|
| 139 | + } |
|
| 140 | + if (isset($this->encryptionModules[$moduleId])) { |
|
| 141 | + return call_user_func($this->encryptionModules[$moduleId]['callback']); |
|
| 142 | + } |
|
| 143 | + $message = "Module with ID: $moduleId does not exist."; |
|
| 144 | + $hint = $this->l->t('Module with ID: %s does not exist. Please enable it in your apps settings or contact your administrator.', [$moduleId]); |
|
| 145 | + throw new Exceptions\ModuleDoesNotExistsException($message, $hint); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * get default encryption module |
|
| 150 | + * |
|
| 151 | + * @return \OCP\Encryption\IEncryptionModule |
|
| 152 | + * @throws Exceptions\ModuleDoesNotExistsException |
|
| 153 | + */ |
|
| 154 | + protected function getDefaultEncryptionModule() { |
|
| 155 | + $defaultModuleId = $this->getDefaultEncryptionModuleId(); |
|
| 156 | + if (empty($defaultModuleId)) { |
|
| 157 | + $message = 'No default encryption module defined'; |
|
| 158 | + throw new Exceptions\ModuleDoesNotExistsException($message); |
|
| 159 | + } |
|
| 160 | + if (isset($this->encryptionModules[$defaultModuleId])) { |
|
| 161 | + return call_user_func($this->encryptionModules[$defaultModuleId]['callback']); |
|
| 162 | + } |
|
| 163 | + $message = 'Default encryption module not loaded'; |
|
| 164 | + throw new Exceptions\ModuleDoesNotExistsException($message); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * set default encryption module Id |
|
| 169 | + * |
|
| 170 | + * @param string $moduleId |
|
| 171 | + * @return bool |
|
| 172 | + */ |
|
| 173 | + public function setDefaultEncryptionModule($moduleId) { |
|
| 174 | + try { |
|
| 175 | + $this->getEncryptionModule($moduleId); |
|
| 176 | + } catch (\Exception $e) { |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + $this->config->setAppValue('core', 'default_encryption_module', $moduleId); |
|
| 181 | + return true; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * get default encryption module Id |
|
| 186 | + * |
|
| 187 | + * @return string |
|
| 188 | + */ |
|
| 189 | + public function getDefaultEncryptionModuleId() { |
|
| 190 | + return $this->config->getAppValue('core', 'default_encryption_module'); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Add storage wrapper |
|
| 195 | + */ |
|
| 196 | + public function setupStorage() { |
|
| 197 | + // If encryption is disabled and there are no loaded modules it makes no sense to load the wrapper |
|
| 198 | + if (!empty($this->encryptionModules) || $this->isEnabled()) { |
|
| 199 | + $encryptionWrapper = new EncryptionWrapper($this->arrayCache, $this, $this->logger); |
|
| 200 | + Filesystem::addStorageWrapper('oc_encryption', [$encryptionWrapper, 'wrapStorage'], 2); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + public function forceWrapStorage(IMountPoint $mountPoint, IStorage $storage) { |
|
| 205 | + $encryptionWrapper = new EncryptionWrapper($this->arrayCache, $this, $this->logger); |
|
| 206 | + return $encryptionWrapper->wrapStorage($mountPoint->getMountPoint(), $storage, $mountPoint, true); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * check if key storage is ready |
|
| 212 | + * |
|
| 213 | + * @return bool |
|
| 214 | + */ |
|
| 215 | + protected function isKeyStorageReady() { |
|
| 216 | + $rootDir = $this->util->getKeyStorageRoot(); |
|
| 217 | + |
|
| 218 | + // the default root is always valid |
|
| 219 | + if ($rootDir === '') { |
|
| 220 | + return true; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + // check if key storage is mounted correctly |
|
| 224 | + if ($this->rootView->file_exists($rootDir . '/' . Storage::KEY_STORAGE_MARKER)) { |
|
| 225 | + return true; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + return false; |
|
| 229 | + } |
|
| 230 | 230 | } |
@@ -26,8 +26,8 @@ |
||
| 26 | 26 | $server = \OC::$server; |
| 27 | 27 | |
| 28 | 28 | $controller = new \OC\OCS\Provider( |
| 29 | - 'ocs_provider', |
|
| 30 | - $server->getRequest(), |
|
| 31 | - $server->getAppManager() |
|
| 29 | + 'ocs_provider', |
|
| 30 | + $server->getRequest(), |
|
| 31 | + $server->getAppManager() |
|
| 32 | 32 | ); |
| 33 | 33 | echo $controller->buildProviderList()->render(); |
@@ -5,7 +5,7 @@ |
||
| 5 | 5 | * SPDX-License-Identifier: AGPL-3.0-only |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -require_once __DIR__ . '/../lib/base.php'; |
|
| 8 | +require_once __DIR__.'/../lib/base.php'; |
|
| 9 | 9 | |
| 10 | 10 | header('Content-Type: application/json'); |
| 11 | 11 | |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | if ($provider === null) { |
| 217 | - throw new ProviderException('No provider with id .' . $id . ' found.'); |
|
| 217 | + throw new ProviderException('No provider with id .'.$id.' found.'); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | return $provider; |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | |
| 242 | 242 | |
| 243 | 243 | if ($provider === null) { |
| 244 | - throw new ProviderException('No share provider for share type ' . $shareType); |
|
| 244 | + throw new ProviderException('No share provider for share type '.$shareType); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | return $provider; |
@@ -38,338 +38,338 @@ |
||
| 38 | 38 | * @package OC\Share20 |
| 39 | 39 | */ |
| 40 | 40 | class ProviderFactory implements IProviderFactory { |
| 41 | - /** @var DefaultShareProvider */ |
|
| 42 | - private $defaultProvider = null; |
|
| 43 | - /** @var FederatedShareProvider */ |
|
| 44 | - private $federatedProvider = null; |
|
| 45 | - /** @var ShareByMailProvider */ |
|
| 46 | - private $shareByMailProvider; |
|
| 47 | - /** @var \OCA\Circles\ShareByCircleProvider */ |
|
| 48 | - private $shareByCircleProvider = null; |
|
| 49 | - /** @var bool */ |
|
| 50 | - private $circlesAreNotAvailable = false; |
|
| 51 | - /** @var \OCA\Talk\Share\RoomShareProvider */ |
|
| 52 | - private $roomShareProvider = null; |
|
| 53 | - |
|
| 54 | - private $registeredShareProviders = []; |
|
| 55 | - |
|
| 56 | - private $shareProviders = []; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * IProviderFactory constructor. |
|
| 60 | - * |
|
| 61 | - * @param IServerContainer $serverContainer |
|
| 62 | - */ |
|
| 63 | - public function __construct( |
|
| 64 | - private IServerContainer $serverContainer, |
|
| 65 | - ) { |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public function registerProvider(string $shareProviderClass): void { |
|
| 69 | - $this->registeredShareProviders[] = $shareProviderClass; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Create the default share provider. |
|
| 74 | - * |
|
| 75 | - * @return DefaultShareProvider |
|
| 76 | - */ |
|
| 77 | - protected function defaultShareProvider() { |
|
| 78 | - if ($this->defaultProvider === null) { |
|
| 79 | - $this->defaultProvider = new DefaultShareProvider( |
|
| 80 | - $this->serverContainer->getDatabaseConnection(), |
|
| 81 | - $this->serverContainer->getUserManager(), |
|
| 82 | - $this->serverContainer->getGroupManager(), |
|
| 83 | - $this->serverContainer->get(IRootFolder::class), |
|
| 84 | - $this->serverContainer->get(IMailer::class), |
|
| 85 | - $this->serverContainer->get(Defaults::class), |
|
| 86 | - $this->serverContainer->get(IFactory::class), |
|
| 87 | - $this->serverContainer->getURLGenerator(), |
|
| 88 | - $this->serverContainer->get(ITimeFactory::class), |
|
| 89 | - $this->serverContainer->get(LoggerInterface::class), |
|
| 90 | - $this->serverContainer->get(IManager::class), |
|
| 91 | - ); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return $this->defaultProvider; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Create the federated share provider |
|
| 99 | - * |
|
| 100 | - * @return FederatedShareProvider |
|
| 101 | - */ |
|
| 102 | - protected function federatedShareProvider() { |
|
| 103 | - if ($this->federatedProvider === null) { |
|
| 104 | - /* |
|
| 41 | + /** @var DefaultShareProvider */ |
|
| 42 | + private $defaultProvider = null; |
|
| 43 | + /** @var FederatedShareProvider */ |
|
| 44 | + private $federatedProvider = null; |
|
| 45 | + /** @var ShareByMailProvider */ |
|
| 46 | + private $shareByMailProvider; |
|
| 47 | + /** @var \OCA\Circles\ShareByCircleProvider */ |
|
| 48 | + private $shareByCircleProvider = null; |
|
| 49 | + /** @var bool */ |
|
| 50 | + private $circlesAreNotAvailable = false; |
|
| 51 | + /** @var \OCA\Talk\Share\RoomShareProvider */ |
|
| 52 | + private $roomShareProvider = null; |
|
| 53 | + |
|
| 54 | + private $registeredShareProviders = []; |
|
| 55 | + |
|
| 56 | + private $shareProviders = []; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * IProviderFactory constructor. |
|
| 60 | + * |
|
| 61 | + * @param IServerContainer $serverContainer |
|
| 62 | + */ |
|
| 63 | + public function __construct( |
|
| 64 | + private IServerContainer $serverContainer, |
|
| 65 | + ) { |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public function registerProvider(string $shareProviderClass): void { |
|
| 69 | + $this->registeredShareProviders[] = $shareProviderClass; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Create the default share provider. |
|
| 74 | + * |
|
| 75 | + * @return DefaultShareProvider |
|
| 76 | + */ |
|
| 77 | + protected function defaultShareProvider() { |
|
| 78 | + if ($this->defaultProvider === null) { |
|
| 79 | + $this->defaultProvider = new DefaultShareProvider( |
|
| 80 | + $this->serverContainer->getDatabaseConnection(), |
|
| 81 | + $this->serverContainer->getUserManager(), |
|
| 82 | + $this->serverContainer->getGroupManager(), |
|
| 83 | + $this->serverContainer->get(IRootFolder::class), |
|
| 84 | + $this->serverContainer->get(IMailer::class), |
|
| 85 | + $this->serverContainer->get(Defaults::class), |
|
| 86 | + $this->serverContainer->get(IFactory::class), |
|
| 87 | + $this->serverContainer->getURLGenerator(), |
|
| 88 | + $this->serverContainer->get(ITimeFactory::class), |
|
| 89 | + $this->serverContainer->get(LoggerInterface::class), |
|
| 90 | + $this->serverContainer->get(IManager::class), |
|
| 91 | + ); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return $this->defaultProvider; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Create the federated share provider |
|
| 99 | + * |
|
| 100 | + * @return FederatedShareProvider |
|
| 101 | + */ |
|
| 102 | + protected function federatedShareProvider() { |
|
| 103 | + if ($this->federatedProvider === null) { |
|
| 104 | + /* |
|
| 105 | 105 | * Check if the app is enabled |
| 106 | 106 | */ |
| 107 | - $appManager = $this->serverContainer->getAppManager(); |
|
| 108 | - if (!$appManager->isEnabledForUser('federatedfilesharing')) { |
|
| 109 | - return null; |
|
| 110 | - } |
|
| 107 | + $appManager = $this->serverContainer->getAppManager(); |
|
| 108 | + if (!$appManager->isEnabledForUser('federatedfilesharing')) { |
|
| 109 | + return null; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /* |
|
| 112 | + /* |
|
| 113 | 113 | * TODO: add factory to federated sharing app |
| 114 | 114 | */ |
| 115 | - $l = $this->serverContainer->getL10N('federatedfilesharing'); |
|
| 116 | - $addressHandler = new AddressHandler( |
|
| 117 | - $this->serverContainer->getURLGenerator(), |
|
| 118 | - $l, |
|
| 119 | - $this->serverContainer->getCloudIdManager() |
|
| 120 | - ); |
|
| 121 | - $notifications = new Notifications( |
|
| 122 | - $addressHandler, |
|
| 123 | - $this->serverContainer->get(IClientService::class), |
|
| 124 | - $this->serverContainer->get(\OCP\OCS\IDiscoveryService::class), |
|
| 125 | - $this->serverContainer->getJobList(), |
|
| 126 | - \OC::$server->getCloudFederationProviderManager(), |
|
| 127 | - \OC::$server->get(ICloudFederationFactory::class), |
|
| 128 | - $this->serverContainer->get(IEventDispatcher::class), |
|
| 129 | - $this->serverContainer->get(LoggerInterface::class), |
|
| 130 | - ); |
|
| 131 | - $tokenHandler = new TokenHandler( |
|
| 132 | - $this->serverContainer->get(ISecureRandom::class) |
|
| 133 | - ); |
|
| 134 | - |
|
| 135 | - $this->federatedProvider = new FederatedShareProvider( |
|
| 136 | - $this->serverContainer->getDatabaseConnection(), |
|
| 137 | - $addressHandler, |
|
| 138 | - $notifications, |
|
| 139 | - $tokenHandler, |
|
| 140 | - $l, |
|
| 141 | - $this->serverContainer->get(IRootFolder::class), |
|
| 142 | - $this->serverContainer->getConfig(), |
|
| 143 | - $this->serverContainer->getUserManager(), |
|
| 144 | - $this->serverContainer->getCloudIdManager(), |
|
| 145 | - $this->serverContainer->getGlobalScaleConfig(), |
|
| 146 | - $this->serverContainer->getCloudFederationProviderManager(), |
|
| 147 | - $this->serverContainer->get(LoggerInterface::class), |
|
| 148 | - ); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - return $this->federatedProvider; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Create the federated share provider |
|
| 156 | - * |
|
| 157 | - * @return ShareByMailProvider |
|
| 158 | - */ |
|
| 159 | - protected function getShareByMailProvider() { |
|
| 160 | - if ($this->shareByMailProvider === null) { |
|
| 161 | - /* |
|
| 115 | + $l = $this->serverContainer->getL10N('federatedfilesharing'); |
|
| 116 | + $addressHandler = new AddressHandler( |
|
| 117 | + $this->serverContainer->getURLGenerator(), |
|
| 118 | + $l, |
|
| 119 | + $this->serverContainer->getCloudIdManager() |
|
| 120 | + ); |
|
| 121 | + $notifications = new Notifications( |
|
| 122 | + $addressHandler, |
|
| 123 | + $this->serverContainer->get(IClientService::class), |
|
| 124 | + $this->serverContainer->get(\OCP\OCS\IDiscoveryService::class), |
|
| 125 | + $this->serverContainer->getJobList(), |
|
| 126 | + \OC::$server->getCloudFederationProviderManager(), |
|
| 127 | + \OC::$server->get(ICloudFederationFactory::class), |
|
| 128 | + $this->serverContainer->get(IEventDispatcher::class), |
|
| 129 | + $this->serverContainer->get(LoggerInterface::class), |
|
| 130 | + ); |
|
| 131 | + $tokenHandler = new TokenHandler( |
|
| 132 | + $this->serverContainer->get(ISecureRandom::class) |
|
| 133 | + ); |
|
| 134 | + |
|
| 135 | + $this->federatedProvider = new FederatedShareProvider( |
|
| 136 | + $this->serverContainer->getDatabaseConnection(), |
|
| 137 | + $addressHandler, |
|
| 138 | + $notifications, |
|
| 139 | + $tokenHandler, |
|
| 140 | + $l, |
|
| 141 | + $this->serverContainer->get(IRootFolder::class), |
|
| 142 | + $this->serverContainer->getConfig(), |
|
| 143 | + $this->serverContainer->getUserManager(), |
|
| 144 | + $this->serverContainer->getCloudIdManager(), |
|
| 145 | + $this->serverContainer->getGlobalScaleConfig(), |
|
| 146 | + $this->serverContainer->getCloudFederationProviderManager(), |
|
| 147 | + $this->serverContainer->get(LoggerInterface::class), |
|
| 148 | + ); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + return $this->federatedProvider; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Create the federated share provider |
|
| 156 | + * |
|
| 157 | + * @return ShareByMailProvider |
|
| 158 | + */ |
|
| 159 | + protected function getShareByMailProvider() { |
|
| 160 | + if ($this->shareByMailProvider === null) { |
|
| 161 | + /* |
|
| 162 | 162 | * Check if the app is enabled |
| 163 | 163 | */ |
| 164 | - $appManager = $this->serverContainer->getAppManager(); |
|
| 165 | - if (!$appManager->isEnabledForUser('sharebymail')) { |
|
| 166 | - return null; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - $settingsManager = new SettingsManager($this->serverContainer->getConfig()); |
|
| 170 | - |
|
| 171 | - $this->shareByMailProvider = new ShareByMailProvider( |
|
| 172 | - $this->serverContainer->getConfig(), |
|
| 173 | - $this->serverContainer->getDatabaseConnection(), |
|
| 174 | - $this->serverContainer->get(ISecureRandom::class), |
|
| 175 | - $this->serverContainer->getUserManager(), |
|
| 176 | - $this->serverContainer->get(IRootFolder::class), |
|
| 177 | - $this->serverContainer->getL10N('sharebymail'), |
|
| 178 | - $this->serverContainer->get(LoggerInterface::class), |
|
| 179 | - $this->serverContainer->get(IMailer::class), |
|
| 180 | - $this->serverContainer->getURLGenerator(), |
|
| 181 | - $this->serverContainer->getActivityManager(), |
|
| 182 | - $settingsManager, |
|
| 183 | - $this->serverContainer->get(Defaults::class), |
|
| 184 | - $this->serverContainer->get(IHasher::class), |
|
| 185 | - $this->serverContainer->get(IEventDispatcher::class), |
|
| 186 | - $this->serverContainer->get(IManager::class) |
|
| 187 | - ); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - return $this->shareByMailProvider; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Create the circle share provider |
|
| 196 | - * |
|
| 197 | - * @return FederatedShareProvider |
|
| 198 | - * |
|
| 199 | - * @suppress PhanUndeclaredClassMethod |
|
| 200 | - */ |
|
| 201 | - protected function getShareByCircleProvider() { |
|
| 202 | - if ($this->circlesAreNotAvailable) { |
|
| 203 | - return null; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if (!$this->serverContainer->getAppManager()->isEnabledForUser('circles') || |
|
| 207 | - !class_exists('\OCA\Circles\ShareByCircleProvider') |
|
| 208 | - ) { |
|
| 209 | - $this->circlesAreNotAvailable = true; |
|
| 210 | - return null; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - if ($this->shareByCircleProvider === null) { |
|
| 214 | - $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider( |
|
| 215 | - $this->serverContainer->getDatabaseConnection(), |
|
| 216 | - $this->serverContainer->get(ISecureRandom::class), |
|
| 217 | - $this->serverContainer->getUserManager(), |
|
| 218 | - $this->serverContainer->get(IRootFolder::class), |
|
| 219 | - $this->serverContainer->getL10N('circles'), |
|
| 220 | - $this->serverContainer->get(LoggerInterface::class), |
|
| 221 | - $this->serverContainer->getURLGenerator() |
|
| 222 | - ); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - return $this->shareByCircleProvider; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Create the room share provider |
|
| 230 | - * |
|
| 231 | - * @return RoomShareProvider |
|
| 232 | - */ |
|
| 233 | - protected function getRoomShareProvider() { |
|
| 234 | - if ($this->roomShareProvider === null) { |
|
| 235 | - /* |
|
| 164 | + $appManager = $this->serverContainer->getAppManager(); |
|
| 165 | + if (!$appManager->isEnabledForUser('sharebymail')) { |
|
| 166 | + return null; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + $settingsManager = new SettingsManager($this->serverContainer->getConfig()); |
|
| 170 | + |
|
| 171 | + $this->shareByMailProvider = new ShareByMailProvider( |
|
| 172 | + $this->serverContainer->getConfig(), |
|
| 173 | + $this->serverContainer->getDatabaseConnection(), |
|
| 174 | + $this->serverContainer->get(ISecureRandom::class), |
|
| 175 | + $this->serverContainer->getUserManager(), |
|
| 176 | + $this->serverContainer->get(IRootFolder::class), |
|
| 177 | + $this->serverContainer->getL10N('sharebymail'), |
|
| 178 | + $this->serverContainer->get(LoggerInterface::class), |
|
| 179 | + $this->serverContainer->get(IMailer::class), |
|
| 180 | + $this->serverContainer->getURLGenerator(), |
|
| 181 | + $this->serverContainer->getActivityManager(), |
|
| 182 | + $settingsManager, |
|
| 183 | + $this->serverContainer->get(Defaults::class), |
|
| 184 | + $this->serverContainer->get(IHasher::class), |
|
| 185 | + $this->serverContainer->get(IEventDispatcher::class), |
|
| 186 | + $this->serverContainer->get(IManager::class) |
|
| 187 | + ); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + return $this->shareByMailProvider; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Create the circle share provider |
|
| 196 | + * |
|
| 197 | + * @return FederatedShareProvider |
|
| 198 | + * |
|
| 199 | + * @suppress PhanUndeclaredClassMethod |
|
| 200 | + */ |
|
| 201 | + protected function getShareByCircleProvider() { |
|
| 202 | + if ($this->circlesAreNotAvailable) { |
|
| 203 | + return null; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if (!$this->serverContainer->getAppManager()->isEnabledForUser('circles') || |
|
| 207 | + !class_exists('\OCA\Circles\ShareByCircleProvider') |
|
| 208 | + ) { |
|
| 209 | + $this->circlesAreNotAvailable = true; |
|
| 210 | + return null; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + if ($this->shareByCircleProvider === null) { |
|
| 214 | + $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider( |
|
| 215 | + $this->serverContainer->getDatabaseConnection(), |
|
| 216 | + $this->serverContainer->get(ISecureRandom::class), |
|
| 217 | + $this->serverContainer->getUserManager(), |
|
| 218 | + $this->serverContainer->get(IRootFolder::class), |
|
| 219 | + $this->serverContainer->getL10N('circles'), |
|
| 220 | + $this->serverContainer->get(LoggerInterface::class), |
|
| 221 | + $this->serverContainer->getURLGenerator() |
|
| 222 | + ); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + return $this->shareByCircleProvider; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Create the room share provider |
|
| 230 | + * |
|
| 231 | + * @return RoomShareProvider |
|
| 232 | + */ |
|
| 233 | + protected function getRoomShareProvider() { |
|
| 234 | + if ($this->roomShareProvider === null) { |
|
| 235 | + /* |
|
| 236 | 236 | * Check if the app is enabled |
| 237 | 237 | */ |
| 238 | - $appManager = $this->serverContainer->getAppManager(); |
|
| 239 | - if (!$appManager->isEnabledForUser('spreed')) { |
|
| 240 | - return null; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - try { |
|
| 244 | - /** |
|
| 245 | - * @psalm-suppress UndefinedClass |
|
| 246 | - */ |
|
| 247 | - $this->roomShareProvider = $this->serverContainer->get(RoomShareProvider::class); |
|
| 248 | - } catch (\Throwable $e) { |
|
| 249 | - $this->serverContainer->get(LoggerInterface::class)->error( |
|
| 250 | - $e->getMessage(), |
|
| 251 | - ['exception' => $e] |
|
| 252 | - ); |
|
| 253 | - return null; |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - return $this->roomShareProvider; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * @inheritdoc |
|
| 262 | - */ |
|
| 263 | - public function getProvider($id) { |
|
| 264 | - $provider = null; |
|
| 265 | - if (isset($this->shareProviders[$id])) { |
|
| 266 | - return $this->shareProviders[$id]; |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - if ($id === 'ocinternal') { |
|
| 270 | - $provider = $this->defaultShareProvider(); |
|
| 271 | - } elseif ($id === 'ocFederatedSharing') { |
|
| 272 | - $provider = $this->federatedShareProvider(); |
|
| 273 | - } elseif ($id === 'ocMailShare') { |
|
| 274 | - $provider = $this->getShareByMailProvider(); |
|
| 275 | - } elseif ($id === 'ocCircleShare') { |
|
| 276 | - $provider = $this->getShareByCircleProvider(); |
|
| 277 | - } elseif ($id === 'ocRoomShare') { |
|
| 278 | - $provider = $this->getRoomShareProvider(); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - foreach ($this->registeredShareProviders as $shareProvider) { |
|
| 282 | - try { |
|
| 283 | - /** @var IShareProvider $instance */ |
|
| 284 | - $instance = $this->serverContainer->get($shareProvider); |
|
| 285 | - $this->shareProviders[$instance->identifier()] = $instance; |
|
| 286 | - } catch (\Throwable $e) { |
|
| 287 | - $this->serverContainer->get(LoggerInterface::class)->error( |
|
| 288 | - $e->getMessage(), |
|
| 289 | - ['exception' => $e] |
|
| 290 | - ); |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - if (isset($this->shareProviders[$id])) { |
|
| 295 | - $provider = $this->shareProviders[$id]; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - if ($provider === null) { |
|
| 299 | - throw new ProviderException('No provider with id .' . $id . ' found.'); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - return $provider; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * @inheritdoc |
|
| 307 | - */ |
|
| 308 | - public function getProviderForType($shareType) { |
|
| 309 | - $provider = null; |
|
| 310 | - |
|
| 311 | - if ($shareType === IShare::TYPE_USER || |
|
| 312 | - $shareType === IShare::TYPE_GROUP || |
|
| 313 | - $shareType === IShare::TYPE_LINK |
|
| 314 | - ) { |
|
| 315 | - $provider = $this->defaultShareProvider(); |
|
| 316 | - } elseif ($shareType === IShare::TYPE_REMOTE || $shareType === IShare::TYPE_REMOTE_GROUP) { |
|
| 317 | - $provider = $this->federatedShareProvider(); |
|
| 318 | - } elseif ($shareType === IShare::TYPE_EMAIL) { |
|
| 319 | - $provider = $this->getShareByMailProvider(); |
|
| 320 | - } elseif ($shareType === IShare::TYPE_CIRCLE) { |
|
| 321 | - $provider = $this->getShareByCircleProvider(); |
|
| 322 | - } elseif ($shareType === IShare::TYPE_ROOM) { |
|
| 323 | - $provider = $this->getRoomShareProvider(); |
|
| 324 | - } elseif ($shareType === IShare::TYPE_DECK) { |
|
| 325 | - $provider = $this->getProvider('deck'); |
|
| 326 | - } elseif ($shareType === IShare::TYPE_SCIENCEMESH) { |
|
| 327 | - $provider = $this->getProvider('sciencemesh'); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - |
|
| 331 | - if ($provider === null) { |
|
| 332 | - throw new ProviderException('No share provider for share type ' . $shareType); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - return $provider; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - public function getAllProviders() { |
|
| 339 | - $shares = [$this->defaultShareProvider(), $this->federatedShareProvider()]; |
|
| 340 | - $shareByMail = $this->getShareByMailProvider(); |
|
| 341 | - if ($shareByMail !== null) { |
|
| 342 | - $shares[] = $shareByMail; |
|
| 343 | - } |
|
| 344 | - $shareByCircle = $this->getShareByCircleProvider(); |
|
| 345 | - if ($shareByCircle !== null) { |
|
| 346 | - $shares[] = $shareByCircle; |
|
| 347 | - } |
|
| 348 | - $roomShare = $this->getRoomShareProvider(); |
|
| 349 | - if ($roomShare !== null) { |
|
| 350 | - $shares[] = $roomShare; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - foreach ($this->registeredShareProviders as $shareProvider) { |
|
| 354 | - try { |
|
| 355 | - /** @var IShareProvider $instance */ |
|
| 356 | - $instance = $this->serverContainer->get($shareProvider); |
|
| 357 | - } catch (\Throwable $e) { |
|
| 358 | - $this->serverContainer->get(LoggerInterface::class)->error( |
|
| 359 | - $e->getMessage(), |
|
| 360 | - ['exception' => $e] |
|
| 361 | - ); |
|
| 362 | - continue; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - if (!isset($this->shareProviders[$instance->identifier()])) { |
|
| 366 | - $this->shareProviders[$instance->identifier()] = $instance; |
|
| 367 | - } |
|
| 368 | - $shares[] = $this->shareProviders[$instance->identifier()]; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - return $shares; |
|
| 374 | - } |
|
| 238 | + $appManager = $this->serverContainer->getAppManager(); |
|
| 239 | + if (!$appManager->isEnabledForUser('spreed')) { |
|
| 240 | + return null; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + try { |
|
| 244 | + /** |
|
| 245 | + * @psalm-suppress UndefinedClass |
|
| 246 | + */ |
|
| 247 | + $this->roomShareProvider = $this->serverContainer->get(RoomShareProvider::class); |
|
| 248 | + } catch (\Throwable $e) { |
|
| 249 | + $this->serverContainer->get(LoggerInterface::class)->error( |
|
| 250 | + $e->getMessage(), |
|
| 251 | + ['exception' => $e] |
|
| 252 | + ); |
|
| 253 | + return null; |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + return $this->roomShareProvider; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * @inheritdoc |
|
| 262 | + */ |
|
| 263 | + public function getProvider($id) { |
|
| 264 | + $provider = null; |
|
| 265 | + if (isset($this->shareProviders[$id])) { |
|
| 266 | + return $this->shareProviders[$id]; |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + if ($id === 'ocinternal') { |
|
| 270 | + $provider = $this->defaultShareProvider(); |
|
| 271 | + } elseif ($id === 'ocFederatedSharing') { |
|
| 272 | + $provider = $this->federatedShareProvider(); |
|
| 273 | + } elseif ($id === 'ocMailShare') { |
|
| 274 | + $provider = $this->getShareByMailProvider(); |
|
| 275 | + } elseif ($id === 'ocCircleShare') { |
|
| 276 | + $provider = $this->getShareByCircleProvider(); |
|
| 277 | + } elseif ($id === 'ocRoomShare') { |
|
| 278 | + $provider = $this->getRoomShareProvider(); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + foreach ($this->registeredShareProviders as $shareProvider) { |
|
| 282 | + try { |
|
| 283 | + /** @var IShareProvider $instance */ |
|
| 284 | + $instance = $this->serverContainer->get($shareProvider); |
|
| 285 | + $this->shareProviders[$instance->identifier()] = $instance; |
|
| 286 | + } catch (\Throwable $e) { |
|
| 287 | + $this->serverContainer->get(LoggerInterface::class)->error( |
|
| 288 | + $e->getMessage(), |
|
| 289 | + ['exception' => $e] |
|
| 290 | + ); |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + if (isset($this->shareProviders[$id])) { |
|
| 295 | + $provider = $this->shareProviders[$id]; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + if ($provider === null) { |
|
| 299 | + throw new ProviderException('No provider with id .' . $id . ' found.'); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + return $provider; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * @inheritdoc |
|
| 307 | + */ |
|
| 308 | + public function getProviderForType($shareType) { |
|
| 309 | + $provider = null; |
|
| 310 | + |
|
| 311 | + if ($shareType === IShare::TYPE_USER || |
|
| 312 | + $shareType === IShare::TYPE_GROUP || |
|
| 313 | + $shareType === IShare::TYPE_LINK |
|
| 314 | + ) { |
|
| 315 | + $provider = $this->defaultShareProvider(); |
|
| 316 | + } elseif ($shareType === IShare::TYPE_REMOTE || $shareType === IShare::TYPE_REMOTE_GROUP) { |
|
| 317 | + $provider = $this->federatedShareProvider(); |
|
| 318 | + } elseif ($shareType === IShare::TYPE_EMAIL) { |
|
| 319 | + $provider = $this->getShareByMailProvider(); |
|
| 320 | + } elseif ($shareType === IShare::TYPE_CIRCLE) { |
|
| 321 | + $provider = $this->getShareByCircleProvider(); |
|
| 322 | + } elseif ($shareType === IShare::TYPE_ROOM) { |
|
| 323 | + $provider = $this->getRoomShareProvider(); |
|
| 324 | + } elseif ($shareType === IShare::TYPE_DECK) { |
|
| 325 | + $provider = $this->getProvider('deck'); |
|
| 326 | + } elseif ($shareType === IShare::TYPE_SCIENCEMESH) { |
|
| 327 | + $provider = $this->getProvider('sciencemesh'); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + |
|
| 331 | + if ($provider === null) { |
|
| 332 | + throw new ProviderException('No share provider for share type ' . $shareType); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + return $provider; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + public function getAllProviders() { |
|
| 339 | + $shares = [$this->defaultShareProvider(), $this->federatedShareProvider()]; |
|
| 340 | + $shareByMail = $this->getShareByMailProvider(); |
|
| 341 | + if ($shareByMail !== null) { |
|
| 342 | + $shares[] = $shareByMail; |
|
| 343 | + } |
|
| 344 | + $shareByCircle = $this->getShareByCircleProvider(); |
|
| 345 | + if ($shareByCircle !== null) { |
|
| 346 | + $shares[] = $shareByCircle; |
|
| 347 | + } |
|
| 348 | + $roomShare = $this->getRoomShareProvider(); |
|
| 349 | + if ($roomShare !== null) { |
|
| 350 | + $shares[] = $roomShare; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + foreach ($this->registeredShareProviders as $shareProvider) { |
|
| 354 | + try { |
|
| 355 | + /** @var IShareProvider $instance */ |
|
| 356 | + $instance = $this->serverContainer->get($shareProvider); |
|
| 357 | + } catch (\Throwable $e) { |
|
| 358 | + $this->serverContainer->get(LoggerInterface::class)->error( |
|
| 359 | + $e->getMessage(), |
|
| 360 | + ['exception' => $e] |
|
| 361 | + ); |
|
| 362 | + continue; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + if (!isset($this->shareProviders[$instance->identifier()])) { |
|
| 366 | + $this->shareProviders[$instance->identifier()] = $instance; |
|
| 367 | + } |
|
| 368 | + $shares[] = $this->shareProviders[$instance->identifier()]; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + return $shares; |
|
| 374 | + } |
|
| 375 | 375 | } |