@@ -32,21 +32,21 @@ |
||
32 | 32 | * OAuth2 authentication |
33 | 33 | */ |
34 | 34 | class OAuth2 extends AuthMechanism { |
35 | - public function __construct(IL10N $l) { |
|
36 | - $this |
|
37 | - ->setIdentifier('oauth2::oauth2') |
|
38 | - ->setScheme(self::SCHEME_OAUTH2) |
|
39 | - ->setText($l->t('OAuth2')) |
|
40 | - ->addParameters([ |
|
41 | - (new DefinitionParameter('configured', 'configured')) |
|
42 | - ->setType(DefinitionParameter::VALUE_HIDDEN), |
|
43 | - new DefinitionParameter('client_id', $l->t('Client ID')), |
|
44 | - (new DefinitionParameter('client_secret', $l->t('Client secret'))) |
|
45 | - ->setType(DefinitionParameter::VALUE_PASSWORD), |
|
46 | - (new DefinitionParameter('token', 'token')) |
|
47 | - ->setType(DefinitionParameter::VALUE_HIDDEN), |
|
48 | - ]) |
|
49 | - ->addCustomJs('oauth2') |
|
50 | - ; |
|
51 | - } |
|
35 | + public function __construct(IL10N $l) { |
|
36 | + $this |
|
37 | + ->setIdentifier('oauth2::oauth2') |
|
38 | + ->setScheme(self::SCHEME_OAUTH2) |
|
39 | + ->setText($l->t('OAuth2')) |
|
40 | + ->addParameters([ |
|
41 | + (new DefinitionParameter('configured', 'configured')) |
|
42 | + ->setType(DefinitionParameter::VALUE_HIDDEN), |
|
43 | + new DefinitionParameter('client_id', $l->t('Client ID')), |
|
44 | + (new DefinitionParameter('client_secret', $l->t('Client secret'))) |
|
45 | + ->setType(DefinitionParameter::VALUE_PASSWORD), |
|
46 | + (new DefinitionParameter('token', 'token')) |
|
47 | + ->setType(DefinitionParameter::VALUE_HIDDEN), |
|
48 | + ]) |
|
49 | + ->addCustomJs('oauth2') |
|
50 | + ; |
|
51 | + } |
|
52 | 52 | } |
@@ -31,23 +31,23 @@ |
||
31 | 31 | use OCP\IL10N; |
32 | 32 | |
33 | 33 | class FTP extends Backend { |
34 | - use LegacyDependencyCheckPolyfill; |
|
34 | + use LegacyDependencyCheckPolyfill; |
|
35 | 35 | |
36 | - public function __construct(IL10N $l, Password $legacyAuth) { |
|
37 | - $this |
|
38 | - ->setIdentifier('ftp') |
|
39 | - ->addIdentifierAlias('\OC\Files\Storage\FTP') // legacy compat |
|
40 | - ->setStorageClass('\OCA\Files_External\Lib\Storage\FTP') |
|
41 | - ->setText($l->t('FTP')) |
|
42 | - ->addParameters([ |
|
43 | - new DefinitionParameter('host', $l->t('Host')), |
|
44 | - (new DefinitionParameter('root', $l->t('Remote subfolder'))) |
|
45 | - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
46 | - (new DefinitionParameter('secure', $l->t('Secure ftps://'))) |
|
47 | - ->setType(DefinitionParameter::VALUE_BOOLEAN), |
|
48 | - ]) |
|
49 | - ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) |
|
50 | - ->setLegacyAuthMechanism($legacyAuth) |
|
51 | - ; |
|
52 | - } |
|
36 | + public function __construct(IL10N $l, Password $legacyAuth) { |
|
37 | + $this |
|
38 | + ->setIdentifier('ftp') |
|
39 | + ->addIdentifierAlias('\OC\Files\Storage\FTP') // legacy compat |
|
40 | + ->setStorageClass('\OCA\Files_External\Lib\Storage\FTP') |
|
41 | + ->setText($l->t('FTP')) |
|
42 | + ->addParameters([ |
|
43 | + new DefinitionParameter('host', $l->t('Host')), |
|
44 | + (new DefinitionParameter('root', $l->t('Remote subfolder'))) |
|
45 | + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
46 | + (new DefinitionParameter('secure', $l->t('Secure ftps://'))) |
|
47 | + ->setType(DefinitionParameter::VALUE_BOOLEAN), |
|
48 | + ]) |
|
49 | + ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) |
|
50 | + ->setLegacyAuthMechanism($legacyAuth) |
|
51 | + ; |
|
52 | + } |
|
53 | 53 | } |
@@ -30,19 +30,19 @@ |
||
30 | 30 | use OCP\IL10N; |
31 | 31 | |
32 | 32 | class SFTP_Key extends Backend { |
33 | - public function __construct(IL10N $l, RSA $legacyAuth, SFTP $sftpBackend) { |
|
34 | - $this |
|
35 | - ->setIdentifier('\OC\Files\Storage\SFTP_Key') |
|
36 | - ->setStorageClass('\OCA\Files_External\Lib\Storage\SFTP') |
|
37 | - ->setText($l->t('SFTP with secret key login')) |
|
38 | - ->addParameters([ |
|
39 | - new DefinitionParameter('host', $l->t('Host')), |
|
40 | - (new DefinitionParameter('root', $l->t('Remote subfolder'))) |
|
41 | - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
42 | - ]) |
|
43 | - ->addAuthScheme(AuthMechanism::SCHEME_PUBLICKEY) |
|
44 | - ->setLegacyAuthMechanism($legacyAuth) |
|
45 | - ->deprecateTo($sftpBackend) |
|
46 | - ; |
|
47 | - } |
|
33 | + public function __construct(IL10N $l, RSA $legacyAuth, SFTP $sftpBackend) { |
|
34 | + $this |
|
35 | + ->setIdentifier('\OC\Files\Storage\SFTP_Key') |
|
36 | + ->setStorageClass('\OCA\Files_External\Lib\Storage\SFTP') |
|
37 | + ->setText($l->t('SFTP with secret key login')) |
|
38 | + ->addParameters([ |
|
39 | + new DefinitionParameter('host', $l->t('Host')), |
|
40 | + (new DefinitionParameter('root', $l->t('Remote subfolder'))) |
|
41 | + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
42 | + ]) |
|
43 | + ->addAuthScheme(AuthMechanism::SCHEME_PUBLICKEY) |
|
44 | + ->setLegacyAuthMechanism($legacyAuth) |
|
45 | + ->deprecateTo($sftpBackend) |
|
46 | + ; |
|
47 | + } |
|
48 | 48 | } |
@@ -31,21 +31,21 @@ |
||
31 | 31 | use OCP\IL10N; |
32 | 32 | |
33 | 33 | class OwnCloud extends Backend { |
34 | - public function __construct(IL10N $l, Password $legacyAuth) { |
|
35 | - $this |
|
36 | - ->setIdentifier('owncloud') |
|
37 | - ->addIdentifierAlias('\OC\Files\Storage\OwnCloud') // legacy compat |
|
38 | - ->setStorageClass('\OCA\Files_External\Lib\Storage\OwnCloud') |
|
39 | - ->setText($l->t('Nextcloud')) |
|
40 | - ->addParameters([ |
|
41 | - new DefinitionParameter('host', $l->t('URL')), |
|
42 | - (new DefinitionParameter('root', $l->t('Remote subfolder'))) |
|
43 | - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
44 | - (new DefinitionParameter('secure', $l->t('Secure https://'))) |
|
45 | - ->setType(DefinitionParameter::VALUE_BOOLEAN), |
|
46 | - ]) |
|
47 | - ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) |
|
48 | - ->setLegacyAuthMechanism($legacyAuth) |
|
49 | - ; |
|
50 | - } |
|
34 | + public function __construct(IL10N $l, Password $legacyAuth) { |
|
35 | + $this |
|
36 | + ->setIdentifier('owncloud') |
|
37 | + ->addIdentifierAlias('\OC\Files\Storage\OwnCloud') // legacy compat |
|
38 | + ->setStorageClass('\OCA\Files_External\Lib\Storage\OwnCloud') |
|
39 | + ->setText($l->t('Nextcloud')) |
|
40 | + ->addParameters([ |
|
41 | + new DefinitionParameter('host', $l->t('URL')), |
|
42 | + (new DefinitionParameter('root', $l->t('Remote subfolder'))) |
|
43 | + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
44 | + (new DefinitionParameter('secure', $l->t('Secure https://'))) |
|
45 | + ->setType(DefinitionParameter::VALUE_BOOLEAN), |
|
46 | + ]) |
|
47 | + ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) |
|
48 | + ->setLegacyAuthMechanism($legacyAuth) |
|
49 | + ; |
|
50 | + } |
|
51 | 51 | } |
@@ -31,19 +31,19 @@ |
||
31 | 31 | use OCP\IL10N; |
32 | 32 | |
33 | 33 | class Local extends Backend { |
34 | - public function __construct(IL10N $l, NullMechanism $legacyAuth) { |
|
35 | - $this |
|
36 | - ->setIdentifier('local') |
|
37 | - ->addIdentifierAlias('\OC\Files\Storage\Local') // legacy compat |
|
38 | - ->setStorageClass('\OC\Files\Storage\Local') |
|
39 | - ->setText($l->t('Local')) |
|
40 | - ->addParameters([ |
|
41 | - new DefinitionParameter('datadir', $l->t('Location')), |
|
42 | - ]) |
|
43 | - ->setAllowedVisibility(BackendService::VISIBILITY_ADMIN) |
|
44 | - ->setPriority(BackendService::PRIORITY_DEFAULT + 50) |
|
45 | - ->addAuthScheme(AuthMechanism::SCHEME_NULL) |
|
46 | - ->setLegacyAuthMechanism($legacyAuth) |
|
47 | - ; |
|
48 | - } |
|
34 | + public function __construct(IL10N $l, NullMechanism $legacyAuth) { |
|
35 | + $this |
|
36 | + ->setIdentifier('local') |
|
37 | + ->addIdentifierAlias('\OC\Files\Storage\Local') // legacy compat |
|
38 | + ->setStorageClass('\OC\Files\Storage\Local') |
|
39 | + ->setText($l->t('Local')) |
|
40 | + ->addParameters([ |
|
41 | + new DefinitionParameter('datadir', $l->t('Location')), |
|
42 | + ]) |
|
43 | + ->setAllowedVisibility(BackendService::VISIBILITY_ADMIN) |
|
44 | + ->setPriority(BackendService::PRIORITY_DEFAULT + 50) |
|
45 | + ->addAuthScheme(AuthMechanism::SCHEME_NULL) |
|
46 | + ->setLegacyAuthMechanism($legacyAuth) |
|
47 | + ; |
|
48 | + } |
|
49 | 49 | } |
@@ -30,20 +30,20 @@ |
||
30 | 30 | use OCP\IL10N; |
31 | 31 | |
32 | 32 | class SFTP extends Backend { |
33 | - public function __construct(IL10N $l, Password $legacyAuth) { |
|
34 | - $this |
|
35 | - ->setIdentifier('sftp') |
|
36 | - ->addIdentifierAlias('\OC\Files\Storage\SFTP') // legacy compat |
|
37 | - ->setStorageClass('\OCA\Files_External\Lib\Storage\SFTP') |
|
38 | - ->setText($l->t('SFTP')) |
|
39 | - ->addParameters([ |
|
40 | - new DefinitionParameter('host', $l->t('Host')), |
|
41 | - (new DefinitionParameter('root', $l->t('Root'))) |
|
42 | - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
43 | - ]) |
|
44 | - ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) |
|
45 | - ->addAuthScheme(AuthMechanism::SCHEME_PUBLICKEY) |
|
46 | - ->setLegacyAuthMechanism($legacyAuth) |
|
47 | - ; |
|
48 | - } |
|
33 | + public function __construct(IL10N $l, Password $legacyAuth) { |
|
34 | + $this |
|
35 | + ->setIdentifier('sftp') |
|
36 | + ->addIdentifierAlias('\OC\Files\Storage\SFTP') // legacy compat |
|
37 | + ->setStorageClass('\OCA\Files_External\Lib\Storage\SFTP') |
|
38 | + ->setText($l->t('SFTP')) |
|
39 | + ->addParameters([ |
|
40 | + new DefinitionParameter('host', $l->t('Host')), |
|
41 | + (new DefinitionParameter('root', $l->t('Root'))) |
|
42 | + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
43 | + ]) |
|
44 | + ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) |
|
45 | + ->addAuthScheme(AuthMechanism::SCHEME_PUBLICKEY) |
|
46 | + ->setLegacyAuthMechanism($legacyAuth) |
|
47 | + ; |
|
48 | + } |
|
49 | 49 | } |
@@ -31,23 +31,23 @@ |
||
31 | 31 | use OCP\IL10N; |
32 | 32 | |
33 | 33 | class DAV extends Backend { |
34 | - use LegacyDependencyCheckPolyfill; |
|
34 | + use LegacyDependencyCheckPolyfill; |
|
35 | 35 | |
36 | - public function __construct(IL10N $l, Password $legacyAuth) { |
|
37 | - $this |
|
38 | - ->setIdentifier('dav') |
|
39 | - ->addIdentifierAlias('\OC\Files\Storage\DAV') // legacy compat |
|
40 | - ->setStorageClass('\OC\Files\Storage\DAV') |
|
41 | - ->setText($l->t('WebDAV')) |
|
42 | - ->addParameters([ |
|
43 | - new DefinitionParameter('host', $l->t('URL')), |
|
44 | - (new DefinitionParameter('root', $l->t('Remote subfolder'))) |
|
45 | - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
46 | - (new DefinitionParameter('secure', $l->t('Secure https://'))) |
|
47 | - ->setType(DefinitionParameter::VALUE_BOOLEAN), |
|
48 | - ]) |
|
49 | - ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) |
|
50 | - ->setLegacyAuthMechanism($legacyAuth) |
|
51 | - ; |
|
52 | - } |
|
36 | + public function __construct(IL10N $l, Password $legacyAuth) { |
|
37 | + $this |
|
38 | + ->setIdentifier('dav') |
|
39 | + ->addIdentifierAlias('\OC\Files\Storage\DAV') // legacy compat |
|
40 | + ->setStorageClass('\OC\Files\Storage\DAV') |
|
41 | + ->setText($l->t('WebDAV')) |
|
42 | + ->addParameters([ |
|
43 | + new DefinitionParameter('host', $l->t('URL')), |
|
44 | + (new DefinitionParameter('root', $l->t('Remote subfolder'))) |
|
45 | + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
46 | + (new DefinitionParameter('secure', $l->t('Secure https://'))) |
|
47 | + ->setType(DefinitionParameter::VALUE_BOOLEAN), |
|
48 | + ]) |
|
49 | + ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) |
|
50 | + ->setLegacyAuthMechanism($legacyAuth) |
|
51 | + ; |
|
52 | + } |
|
53 | 53 | } |
@@ -25,19 +25,19 @@ |
||
25 | 25 | namespace OCA\Files_External\Config; |
26 | 26 | |
27 | 27 | class UserPlaceholderHandler extends UserContext implements IConfigHandler { |
28 | - use SimpleSubstitutionTrait; |
|
28 | + use SimpleSubstitutionTrait; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param mixed $optionValue |
|
32 | - * @return mixed the same type as $optionValue |
|
33 | - * @since 16.0.0 |
|
34 | - */ |
|
35 | - public function handle($optionValue) { |
|
36 | - $this->placeholder = 'user'; |
|
37 | - $uid = $this->getUserId(); |
|
38 | - if ($uid === null) { |
|
39 | - return $optionValue; |
|
40 | - } |
|
41 | - return $this->processInput($optionValue, $uid); |
|
42 | - } |
|
30 | + /** |
|
31 | + * @param mixed $optionValue |
|
32 | + * @return mixed the same type as $optionValue |
|
33 | + * @since 16.0.0 |
|
34 | + */ |
|
35 | + public function handle($optionValue) { |
|
36 | + $this->placeholder = 'user'; |
|
37 | + $uid = $this->getUserId(); |
|
38 | + if ($uid === null) { |
|
39 | + return $optionValue; |
|
40 | + } |
|
41 | + return $this->processInput($optionValue, $uid); |
|
42 | + } |
|
43 | 43 | } |
@@ -31,57 +31,57 @@ |
||
31 | 31 | * @since 16.0.0 |
32 | 32 | */ |
33 | 33 | trait SimpleSubstitutionTrait { |
34 | - /** |
|
35 | - * @var string the placeholder without $ prefix |
|
36 | - * @since 16.0.0 |
|
37 | - */ |
|
38 | - protected $placeholder; |
|
34 | + /** |
|
35 | + * @var string the placeholder without $ prefix |
|
36 | + * @since 16.0.0 |
|
37 | + */ |
|
38 | + protected $placeholder; |
|
39 | 39 | |
40 | - /** @var string */ |
|
41 | - protected $sanitizedPlaceholder; |
|
40 | + /** @var string */ |
|
41 | + protected $sanitizedPlaceholder; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param mixed $optionValue |
|
45 | - * @param string $replacement |
|
46 | - * @return mixed |
|
47 | - * @since 16.0.0 |
|
48 | - */ |
|
49 | - private function processInput($optionValue, string $replacement) { |
|
50 | - $this->checkPlaceholder(); |
|
51 | - if (is_array($optionValue)) { |
|
52 | - foreach ($optionValue as &$value) { |
|
53 | - $value = $this->substituteIfString($value, $replacement); |
|
54 | - } |
|
55 | - } else { |
|
56 | - $optionValue = $this->substituteIfString($optionValue, $replacement); |
|
57 | - } |
|
58 | - return $optionValue; |
|
59 | - } |
|
43 | + /** |
|
44 | + * @param mixed $optionValue |
|
45 | + * @param string $replacement |
|
46 | + * @return mixed |
|
47 | + * @since 16.0.0 |
|
48 | + */ |
|
49 | + private function processInput($optionValue, string $replacement) { |
|
50 | + $this->checkPlaceholder(); |
|
51 | + if (is_array($optionValue)) { |
|
52 | + foreach ($optionValue as &$value) { |
|
53 | + $value = $this->substituteIfString($value, $replacement); |
|
54 | + } |
|
55 | + } else { |
|
56 | + $optionValue = $this->substituteIfString($optionValue, $replacement); |
|
57 | + } |
|
58 | + return $optionValue; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @throws \RuntimeException |
|
63 | - */ |
|
64 | - protected function checkPlaceholder(): void { |
|
65 | - $this->sanitizedPlaceholder = trim(strtolower($this->placeholder)); |
|
66 | - if (!(bool)\preg_match('/^[a-z0-9]*$/', $this->sanitizedPlaceholder)) { |
|
67 | - throw new \RuntimeException(sprintf( |
|
68 | - 'Invalid placeholder %s, only [a-z0-9] are allowed', $this->sanitizedPlaceholder |
|
69 | - )); |
|
70 | - } |
|
71 | - if ($this->sanitizedPlaceholder === '') { |
|
72 | - throw new \RuntimeException('Invalid empty placeholder'); |
|
73 | - } |
|
74 | - } |
|
61 | + /** |
|
62 | + * @throws \RuntimeException |
|
63 | + */ |
|
64 | + protected function checkPlaceholder(): void { |
|
65 | + $this->sanitizedPlaceholder = trim(strtolower($this->placeholder)); |
|
66 | + if (!(bool)\preg_match('/^[a-z0-9]*$/', $this->sanitizedPlaceholder)) { |
|
67 | + throw new \RuntimeException(sprintf( |
|
68 | + 'Invalid placeholder %s, only [a-z0-9] are allowed', $this->sanitizedPlaceholder |
|
69 | + )); |
|
70 | + } |
|
71 | + if ($this->sanitizedPlaceholder === '') { |
|
72 | + throw new \RuntimeException('Invalid empty placeholder'); |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @param mixed $value |
|
78 | - * @param string $replacement |
|
79 | - * @return mixed |
|
80 | - */ |
|
81 | - protected function substituteIfString($value, string $replacement) { |
|
82 | - if (is_string($value)) { |
|
83 | - return str_ireplace('$' . $this->sanitizedPlaceholder, $replacement, $value); |
|
84 | - } |
|
85 | - return $value; |
|
86 | - } |
|
76 | + /** |
|
77 | + * @param mixed $value |
|
78 | + * @param string $replacement |
|
79 | + * @return mixed |
|
80 | + */ |
|
81 | + protected function substituteIfString($value, string $replacement) { |
|
82 | + if (is_string($value)) { |
|
83 | + return str_ireplace('$' . $this->sanitizedPlaceholder, $replacement, $value); |
|
84 | + } |
|
85 | + return $value; |
|
86 | + } |
|
87 | 87 | } |