2015-08-11 20:45:07 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2015-08-11 20:45:07 +03:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-08-11 20:45:07 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Files_External\Lib;
|
|
|
|
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\Files\Storage;
|
|
|
|
use OCP\Files\StorageNotAvailableException;
|
|
|
|
use OCP\IUser;
|
2015-08-11 20:45:07 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Trait for objects that can modify StorageConfigs and wrap Storages
|
Authentication mechanisms for external storage backends
A backend can now specify generic authentication schemes that it
supports, instead of specifying the parameters for its authentication
method directly. This allows multiple authentication mechanisms to be
implemented for a single scheme, providing altered functionality.
This commit introduces the backend framework for this feature, and so at
this point the UI will be broken as the frontend does not specify the
required information.
Terminology:
- authentication scheme
Parameter interface for the authentication method. A backend
supporting the 'password' scheme accepts two parameters, 'user' and
'password'.
- authentication mechanism
Specific mechanism implementing a scheme. Basic mechanisms may
forward configuration options directly to the backend, more advanced
ones may lookup parameters or retrieve them from the session
New dropdown selector for external storage configurations to select the
authentication mechanism to be used.
Authentication mechanisms can have visibilities, just like backends.
The API was extended too to make it easier to add/remove visibilities.
In addition, the concept of 'allowed visibility' has been introduced, so
a backend/auth mechanism can force a maximum visibility level (e.g.
Local storage type) that cannot be overridden by configuration in the
web UI.
An authentication mechanism is a fully instantiated implementation. This
allows an implementation to have dependencies injected into it, e.g. an
\OCP\IDB for database operations.
When a StorageConfig is being prepared for mounting, the authentication
mechanism implementation has manipulateStorage() called,
which inserts the relevant authentication method options into the
storage ready for mounting.
2015-08-12 12:54:03 +03:00
|
|
|
*
|
|
|
|
* When a storage implementation is being prepared for use, the StorageConfig
|
|
|
|
* is passed through manipulateStorageConfig() to update any parameters as
|
|
|
|
* necessary. After the storage implementation has been constructed, it is
|
|
|
|
* passed through wrapStorage(), potentially replacing the implementation with
|
|
|
|
* a wrapped storage that changes its behaviour.
|
|
|
|
*
|
|
|
|
* Certain configuration options need to be set before the implementation is
|
|
|
|
* constructed, while others are retrieved directly from the storage
|
|
|
|
* implementation and so need a wrapper to be modified.
|
2015-08-11 20:45:07 +03:00
|
|
|
*/
|
|
|
|
trait StorageModifierTrait {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Modify a StorageConfig parameters
|
|
|
|
*
|
|
|
|
* @param StorageConfig $storage
|
2015-08-24 18:32:44 +03:00
|
|
|
* @param IUser $user User the storage is being used as
|
2015-08-12 21:51:09 +03:00
|
|
|
* @throws InsufficientDataForMeaningfulAnswerException
|
|
|
|
* @throws StorageNotAvailableException
|
2015-08-11 20:45:07 +03:00
|
|
|
*/
|
2015-08-24 18:32:44 +03:00
|
|
|
public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
|
2015-08-11 20:45:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrap a Storage if necessary
|
|
|
|
*
|
|
|
|
* @param Storage $storage
|
|
|
|
* @return Storage
|
2015-08-12 21:51:09 +03:00
|
|
|
* @throws InsufficientDataForMeaningfulAnswerException
|
|
|
|
* @throws StorageNotAvailableException
|
2015-08-11 20:45:07 +03:00
|
|
|
*/
|
|
|
|
public function wrapStorage(Storage $storage) {
|
|
|
|
return $storage;
|
|
|
|
}
|
|
|
|
}
|