@@ -36,68 +36,68 @@ |
||
| 36 | 36 | * Object can affect storage mounting |
| 37 | 37 | */ |
| 38 | 38 | class AuthMechanism implements \JsonSerializable, IIdentifier, IFrontendDefinition { |
| 39 | - /** Standard authentication schemes */ |
|
| 40 | - public const SCHEME_NULL = 'null'; |
|
| 41 | - public const SCHEME_BUILTIN = 'builtin'; |
|
| 42 | - public const SCHEME_PASSWORD = 'password'; |
|
| 43 | - public const SCHEME_OAUTH2 = 'oauth2'; |
|
| 44 | - public const SCHEME_PUBLICKEY = 'publickey'; |
|
| 45 | - public const SCHEME_OPENSTACK = 'openstack'; |
|
| 46 | - public const SCHEME_SMB = 'smb'; |
|
| 39 | + /** Standard authentication schemes */ |
|
| 40 | + public const SCHEME_NULL = 'null'; |
|
| 41 | + public const SCHEME_BUILTIN = 'builtin'; |
|
| 42 | + public const SCHEME_PASSWORD = 'password'; |
|
| 43 | + public const SCHEME_OAUTH2 = 'oauth2'; |
|
| 44 | + public const SCHEME_PUBLICKEY = 'publickey'; |
|
| 45 | + public const SCHEME_OPENSTACK = 'openstack'; |
|
| 46 | + public const SCHEME_SMB = 'smb'; |
|
| 47 | 47 | |
| 48 | - use VisibilityTrait; |
|
| 49 | - use FrontendDefinitionTrait; |
|
| 50 | - use StorageModifierTrait; |
|
| 51 | - use IdentifierTrait; |
|
| 48 | + use VisibilityTrait; |
|
| 49 | + use FrontendDefinitionTrait; |
|
| 50 | + use StorageModifierTrait; |
|
| 51 | + use IdentifierTrait; |
|
| 52 | 52 | |
| 53 | - /** @var string */ |
|
| 54 | - protected $scheme; |
|
| 53 | + /** @var string */ |
|
| 54 | + protected $scheme; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Get the authentication scheme implemented |
|
| 58 | - * See self::SCHEME_* constants |
|
| 59 | - * |
|
| 60 | - * @return string |
|
| 61 | - */ |
|
| 62 | - public function getScheme() { |
|
| 63 | - return $this->scheme; |
|
| 64 | - } |
|
| 56 | + /** |
|
| 57 | + * Get the authentication scheme implemented |
|
| 58 | + * See self::SCHEME_* constants |
|
| 59 | + * |
|
| 60 | + * @return string |
|
| 61 | + */ |
|
| 62 | + public function getScheme() { |
|
| 63 | + return $this->scheme; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @param string $scheme |
|
| 68 | - * @return $this |
|
| 69 | - */ |
|
| 70 | - public function setScheme($scheme) { |
|
| 71 | - $this->scheme = $scheme; |
|
| 72 | - return $this; |
|
| 73 | - } |
|
| 66 | + /** |
|
| 67 | + * @param string $scheme |
|
| 68 | + * @return $this |
|
| 69 | + */ |
|
| 70 | + public function setScheme($scheme) { |
|
| 71 | + $this->scheme = $scheme; |
|
| 72 | + return $this; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Serialize into JSON for client-side JS |
|
| 77 | - */ |
|
| 78 | - public function jsonSerialize(): array { |
|
| 79 | - $data = $this->jsonSerializeDefinition(); |
|
| 80 | - $data += $this->jsonSerializeIdentifier(); |
|
| 75 | + /** |
|
| 76 | + * Serialize into JSON for client-side JS |
|
| 77 | + */ |
|
| 78 | + public function jsonSerialize(): array { |
|
| 79 | + $data = $this->jsonSerializeDefinition(); |
|
| 80 | + $data += $this->jsonSerializeIdentifier(); |
|
| 81 | 81 | |
| 82 | - $data['scheme'] = $this->getScheme(); |
|
| 83 | - $data['visibility'] = $this->getVisibility(); |
|
| 82 | + $data['scheme'] = $this->getScheme(); |
|
| 83 | + $data['visibility'] = $this->getVisibility(); |
|
| 84 | 84 | |
| 85 | - return $data; |
|
| 86 | - } |
|
| 85 | + return $data; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Check if parameters are satisfied in a StorageConfig |
|
| 90 | - * |
|
| 91 | - * @param StorageConfig $storage |
|
| 92 | - * @return bool |
|
| 93 | - */ |
|
| 94 | - public function validateStorage(StorageConfig $storage) { |
|
| 95 | - // does the backend actually support this scheme |
|
| 96 | - $supportedSchemes = $storage->getBackend()->getAuthSchemes(); |
|
| 97 | - if (!isset($supportedSchemes[$this->getScheme()])) { |
|
| 98 | - return false; |
|
| 99 | - } |
|
| 88 | + /** |
|
| 89 | + * Check if parameters are satisfied in a StorageConfig |
|
| 90 | + * |
|
| 91 | + * @param StorageConfig $storage |
|
| 92 | + * @return bool |
|
| 93 | + */ |
|
| 94 | + public function validateStorage(StorageConfig $storage) { |
|
| 95 | + // does the backend actually support this scheme |
|
| 96 | + $supportedSchemes = $storage->getBackend()->getAuthSchemes(); |
|
| 97 | + if (!isset($supportedSchemes[$this->getScheme()])) { |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - return $this->validateStorageDefinition($storage); |
|
| 102 | - } |
|
| 101 | + return $this->validateStorageDefinition($storage); |
|
| 102 | + } |
|
| 103 | 103 | } |
@@ -57,100 +57,100 @@ |
||
| 57 | 57 | * @package OCA\Files_External\AppInfo |
| 58 | 58 | */ |
| 59 | 59 | class Application extends App implements IBackendProvider, IAuthMechanismProvider, IBootstrap { |
| 60 | - public const APP_ID = 'files_external'; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Application constructor. |
|
| 64 | - * |
|
| 65 | - * @throws QueryException |
|
| 66 | - */ |
|
| 67 | - public function __construct(array $urlParams = []) { |
|
| 68 | - parent::__construct(self::APP_ID, $urlParams); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - public function register(IRegistrationContext $context): void { |
|
| 72 | - $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); |
|
| 73 | - $context->registerEventListener(GroupDeletedEvent::class, GroupDeletedListener::class); |
|
| 74 | - $context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class); |
|
| 75 | - $context->registerConfigLexicon(ConfigLexicon::class); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - public function boot(IBootContext $context): void { |
|
| 79 | - $context->injectFn(function (IMountProviderCollection $mountProviderCollection, ConfigAdapter $configAdapter): void { |
|
| 80 | - $mountProviderCollection->registerProvider($configAdapter); |
|
| 81 | - }); |
|
| 82 | - $context->injectFn(function (BackendService $backendService, UserPlaceholderHandler $userConfigHandler): void { |
|
| 83 | - $backendService->registerBackendProvider($this); |
|
| 84 | - $backendService->registerAuthMechanismProvider($this); |
|
| 85 | - $backendService->registerConfigHandler('user', function () use ($userConfigHandler) { |
|
| 86 | - return $userConfigHandler; |
|
| 87 | - }); |
|
| 88 | - }); |
|
| 89 | - |
|
| 90 | - // force-load auth mechanisms since some will register hooks |
|
| 91 | - // TODO: obsolete these and use the TokenProvider to get the user's password from the session |
|
| 92 | - $this->getAuthMechanisms(); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @{inheritdoc} |
|
| 97 | - */ |
|
| 98 | - public function getBackends() { |
|
| 99 | - $container = $this->getContainer(); |
|
| 100 | - |
|
| 101 | - $backends = [ |
|
| 102 | - $container->get(Local::class), |
|
| 103 | - $container->get(FTP::class), |
|
| 104 | - $container->get(DAV::class), |
|
| 105 | - $container->get(OwnCloud::class), |
|
| 106 | - $container->get(SFTP::class), |
|
| 107 | - $container->get(AmazonS3::class), |
|
| 108 | - $container->get(Swift::class), |
|
| 109 | - $container->get(SFTP_Key::class), |
|
| 110 | - $container->get(SMB::class), |
|
| 111 | - $container->get(SMB_OC::class), |
|
| 112 | - ]; |
|
| 113 | - |
|
| 114 | - return $backends; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @{inheritdoc} |
|
| 119 | - */ |
|
| 120 | - public function getAuthMechanisms() { |
|
| 121 | - $container = $this->getContainer(); |
|
| 122 | - |
|
| 123 | - return [ |
|
| 124 | - // AuthMechanism::SCHEME_NULL mechanism |
|
| 125 | - $container->get(NullMechanism::class), |
|
| 126 | - |
|
| 127 | - // AuthMechanism::SCHEME_BUILTIN mechanism |
|
| 128 | - $container->get(Builtin::class), |
|
| 129 | - |
|
| 130 | - // AuthMechanism::SCHEME_PASSWORD mechanisms |
|
| 131 | - $container->get(Password::class), |
|
| 132 | - $container->get(SessionCredentials::class), |
|
| 133 | - $container->get(LoginCredentials::class), |
|
| 134 | - $container->get(UserProvided::class), |
|
| 135 | - $container->get(GlobalAuth::class), |
|
| 136 | - $container->get(UserGlobalAuth::class), |
|
| 137 | - |
|
| 138 | - // AuthMechanism::SCHEME_OAUTH2 mechanisms |
|
| 139 | - $container->get(OAuth2::class), |
|
| 140 | - |
|
| 141 | - // AuthMechanism::SCHEME_PUBLICKEY mechanisms |
|
| 142 | - $container->get(RSA::class), |
|
| 143 | - $container->get(RSAPrivateKey::class), |
|
| 144 | - |
|
| 145 | - // AuthMechanism::SCHEME_OPENSTACK mechanisms |
|
| 146 | - $container->get(OpenStackV2::class), |
|
| 147 | - $container->get(OpenStackV3::class), |
|
| 148 | - $container->get(Rackspace::class), |
|
| 149 | - |
|
| 150 | - // Specialized mechanisms |
|
| 151 | - $container->get(AccessKey::class), |
|
| 152 | - $container->get(KerberosAuth::class), |
|
| 153 | - $container->get(KerberosApacheAuth::class), |
|
| 154 | - ]; |
|
| 155 | - } |
|
| 60 | + public const APP_ID = 'files_external'; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Application constructor. |
|
| 64 | + * |
|
| 65 | + * @throws QueryException |
|
| 66 | + */ |
|
| 67 | + public function __construct(array $urlParams = []) { |
|
| 68 | + parent::__construct(self::APP_ID, $urlParams); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + public function register(IRegistrationContext $context): void { |
|
| 72 | + $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); |
|
| 73 | + $context->registerEventListener(GroupDeletedEvent::class, GroupDeletedListener::class); |
|
| 74 | + $context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class); |
|
| 75 | + $context->registerConfigLexicon(ConfigLexicon::class); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + public function boot(IBootContext $context): void { |
|
| 79 | + $context->injectFn(function (IMountProviderCollection $mountProviderCollection, ConfigAdapter $configAdapter): void { |
|
| 80 | + $mountProviderCollection->registerProvider($configAdapter); |
|
| 81 | + }); |
|
| 82 | + $context->injectFn(function (BackendService $backendService, UserPlaceholderHandler $userConfigHandler): void { |
|
| 83 | + $backendService->registerBackendProvider($this); |
|
| 84 | + $backendService->registerAuthMechanismProvider($this); |
|
| 85 | + $backendService->registerConfigHandler('user', function () use ($userConfigHandler) { |
|
| 86 | + return $userConfigHandler; |
|
| 87 | + }); |
|
| 88 | + }); |
|
| 89 | + |
|
| 90 | + // force-load auth mechanisms since some will register hooks |
|
| 91 | + // TODO: obsolete these and use the TokenProvider to get the user's password from the session |
|
| 92 | + $this->getAuthMechanisms(); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @{inheritdoc} |
|
| 97 | + */ |
|
| 98 | + public function getBackends() { |
|
| 99 | + $container = $this->getContainer(); |
|
| 100 | + |
|
| 101 | + $backends = [ |
|
| 102 | + $container->get(Local::class), |
|
| 103 | + $container->get(FTP::class), |
|
| 104 | + $container->get(DAV::class), |
|
| 105 | + $container->get(OwnCloud::class), |
|
| 106 | + $container->get(SFTP::class), |
|
| 107 | + $container->get(AmazonS3::class), |
|
| 108 | + $container->get(Swift::class), |
|
| 109 | + $container->get(SFTP_Key::class), |
|
| 110 | + $container->get(SMB::class), |
|
| 111 | + $container->get(SMB_OC::class), |
|
| 112 | + ]; |
|
| 113 | + |
|
| 114 | + return $backends; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @{inheritdoc} |
|
| 119 | + */ |
|
| 120 | + public function getAuthMechanisms() { |
|
| 121 | + $container = $this->getContainer(); |
|
| 122 | + |
|
| 123 | + return [ |
|
| 124 | + // AuthMechanism::SCHEME_NULL mechanism |
|
| 125 | + $container->get(NullMechanism::class), |
|
| 126 | + |
|
| 127 | + // AuthMechanism::SCHEME_BUILTIN mechanism |
|
| 128 | + $container->get(Builtin::class), |
|
| 129 | + |
|
| 130 | + // AuthMechanism::SCHEME_PASSWORD mechanisms |
|
| 131 | + $container->get(Password::class), |
|
| 132 | + $container->get(SessionCredentials::class), |
|
| 133 | + $container->get(LoginCredentials::class), |
|
| 134 | + $container->get(UserProvided::class), |
|
| 135 | + $container->get(GlobalAuth::class), |
|
| 136 | + $container->get(UserGlobalAuth::class), |
|
| 137 | + |
|
| 138 | + // AuthMechanism::SCHEME_OAUTH2 mechanisms |
|
| 139 | + $container->get(OAuth2::class), |
|
| 140 | + |
|
| 141 | + // AuthMechanism::SCHEME_PUBLICKEY mechanisms |
|
| 142 | + $container->get(RSA::class), |
|
| 143 | + $container->get(RSAPrivateKey::class), |
|
| 144 | + |
|
| 145 | + // AuthMechanism::SCHEME_OPENSTACK mechanisms |
|
| 146 | + $container->get(OpenStackV2::class), |
|
| 147 | + $container->get(OpenStackV3::class), |
|
| 148 | + $container->get(Rackspace::class), |
|
| 149 | + |
|
| 150 | + // Specialized mechanisms |
|
| 151 | + $container->get(AccessKey::class), |
|
| 152 | + $container->get(KerberosAuth::class), |
|
| 153 | + $container->get(KerberosApacheAuth::class), |
|
| 154 | + ]; |
|
| 155 | + } |
|
| 156 | 156 | } |
@@ -8,35 +8,35 @@ |
||
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | $this->create('files_external_oauth2', 'apps/files_external/ajax/oauth2.php') |
| 11 | - ->actionInclude('files_external/ajax/oauth2.php'); |
|
| 11 | + ->actionInclude('files_external/ajax/oauth2.php'); |
|
| 12 | 12 | |
| 13 | 13 | $this->create('files_external_list_applicable', '/apps/files_external/applicable') |
| 14 | - ->actionInclude('files_external/ajax/applicable.php'); |
|
| 14 | + ->actionInclude('files_external/ajax/applicable.php'); |
|
| 15 | 15 | |
| 16 | 16 | return [ |
| 17 | - 'resources' => [ |
|
| 18 | - 'global_storages' => ['url' => '/globalstorages'], |
|
| 19 | - 'user_storages' => ['url' => '/userstorages'], |
|
| 20 | - 'user_global_storages' => ['url' => '/userglobalstorages'], |
|
| 21 | - ], |
|
| 22 | - 'routes' => [ |
|
| 23 | - [ |
|
| 24 | - 'name' => 'Ajax#getSshKeys', |
|
| 25 | - 'url' => '/ajax/public_key.php', |
|
| 26 | - 'verb' => 'POST', |
|
| 27 | - 'requirements' => [], |
|
| 28 | - ], |
|
| 29 | - [ |
|
| 30 | - 'name' => 'Ajax#saveGlobalCredentials', |
|
| 31 | - 'url' => '/globalcredentials', |
|
| 32 | - 'verb' => 'POST', |
|
| 33 | - ], |
|
| 34 | - ], |
|
| 35 | - 'ocs' => [ |
|
| 36 | - [ |
|
| 37 | - 'name' => 'Api#getUserMounts', |
|
| 38 | - 'url' => '/api/v1/mounts', |
|
| 39 | - 'verb' => 'GET', |
|
| 40 | - ], |
|
| 41 | - ], |
|
| 17 | + 'resources' => [ |
|
| 18 | + 'global_storages' => ['url' => '/globalstorages'], |
|
| 19 | + 'user_storages' => ['url' => '/userstorages'], |
|
| 20 | + 'user_global_storages' => ['url' => '/userglobalstorages'], |
|
| 21 | + ], |
|
| 22 | + 'routes' => [ |
|
| 23 | + [ |
|
| 24 | + 'name' => 'Ajax#getSshKeys', |
|
| 25 | + 'url' => '/ajax/public_key.php', |
|
| 26 | + 'verb' => 'POST', |
|
| 27 | + 'requirements' => [], |
|
| 28 | + ], |
|
| 29 | + [ |
|
| 30 | + 'name' => 'Ajax#saveGlobalCredentials', |
|
| 31 | + 'url' => '/globalcredentials', |
|
| 32 | + 'verb' => 'POST', |
|
| 33 | + ], |
|
| 34 | + ], |
|
| 35 | + 'ocs' => [ |
|
| 36 | + [ |
|
| 37 | + 'name' => 'Api#getUserMounts', |
|
| 38 | + 'url' => '/api/v1/mounts', |
|
| 39 | + 'verb' => 'GET', |
|
| 40 | + ], |
|
| 41 | + ], |
|
| 42 | 42 | ]; |