@@ -32,16 +32,16 @@ |
||
32 | 32 | * Rackspace authentication |
33 | 33 | */ |
34 | 34 | class Rackspace extends AuthMechanism { |
35 | - public function __construct(IL10N $l) { |
|
36 | - $this |
|
37 | - ->setIdentifier('openstack::rackspace') |
|
38 | - ->setScheme(self::SCHEME_OPENSTACK) |
|
39 | - ->setText($l->t('Rackspace')) |
|
40 | - ->addParameters([ |
|
41 | - new DefinitionParameter('user', $l->t('Username')), |
|
42 | - (new DefinitionParameter('key', $l->t('API key'))) |
|
43 | - ->setType(DefinitionParameter::VALUE_PASSWORD), |
|
44 | - ]) |
|
45 | - ; |
|
46 | - } |
|
35 | + public function __construct(IL10N $l) { |
|
36 | + $this |
|
37 | + ->setIdentifier('openstack::rackspace') |
|
38 | + ->setScheme(self::SCHEME_OPENSTACK) |
|
39 | + ->setText($l->t('Rackspace')) |
|
40 | + ->addParameters([ |
|
41 | + new DefinitionParameter('user', $l->t('Username')), |
|
42 | + (new DefinitionParameter('key', $l->t('API key'))) |
|
43 | + ->setType(DefinitionParameter::VALUE_PASSWORD), |
|
44 | + ]) |
|
45 | + ; |
|
46 | + } |
|
47 | 47 | } |
@@ -32,15 +32,15 @@ |
||
32 | 32 | * Basic password authentication mechanism |
33 | 33 | */ |
34 | 34 | class Password extends AuthMechanism { |
35 | - public function __construct(IL10N $l) { |
|
36 | - $this |
|
37 | - ->setIdentifier('password::password') |
|
38 | - ->setScheme(self::SCHEME_PASSWORD) |
|
39 | - ->setText($l->t('Username and password')) |
|
40 | - ->addParameters([ |
|
41 | - new DefinitionParameter('user', $l->t('Username')), |
|
42 | - (new DefinitionParameter('password', $l->t('Password'))) |
|
43 | - ->setType(DefinitionParameter::VALUE_PASSWORD), |
|
44 | - ]); |
|
45 | - } |
|
35 | + public function __construct(IL10N $l) { |
|
36 | + $this |
|
37 | + ->setIdentifier('password::password') |
|
38 | + ->setScheme(self::SCHEME_PASSWORD) |
|
39 | + ->setText($l->t('Username and password')) |
|
40 | + ->addParameters([ |
|
41 | + new DefinitionParameter('user', $l->t('Username')), |
|
42 | + (new DefinitionParameter('password', $l->t('Password'))) |
|
43 | + ->setType(DefinitionParameter::VALUE_PASSWORD), |
|
44 | + ]); |
|
45 | + } |
|
46 | 46 | } |
@@ -40,46 +40,46 @@ |
||
40 | 40 | * User provided Global Username and Password |
41 | 41 | */ |
42 | 42 | class UserGlobalAuth extends AuthMechanism { |
43 | - private const CREDENTIALS_IDENTIFIER = 'password::global'; |
|
43 | + private const CREDENTIALS_IDENTIFIER = 'password::global'; |
|
44 | 44 | |
45 | - /** @var ICredentialsManager */ |
|
46 | - protected $credentialsManager; |
|
45 | + /** @var ICredentialsManager */ |
|
46 | + protected $credentialsManager; |
|
47 | 47 | |
48 | - public function __construct(IL10N $l, ICredentialsManager $credentialsManager) { |
|
49 | - $this->credentialsManager = $credentialsManager; |
|
48 | + public function __construct(IL10N $l, ICredentialsManager $credentialsManager) { |
|
49 | + $this->credentialsManager = $credentialsManager; |
|
50 | 50 | |
51 | - $this |
|
52 | - ->setIdentifier('password::global::user') |
|
53 | - ->setVisibility(BackendService::VISIBILITY_DEFAULT) |
|
54 | - ->setScheme(self::SCHEME_PASSWORD) |
|
55 | - ->setText($l->t('Global credentials, user entered')); |
|
56 | - } |
|
51 | + $this |
|
52 | + ->setIdentifier('password::global::user') |
|
53 | + ->setVisibility(BackendService::VISIBILITY_DEFAULT) |
|
54 | + ->setScheme(self::SCHEME_PASSWORD) |
|
55 | + ->setText($l->t('Global credentials, user entered')); |
|
56 | + } |
|
57 | 57 | |
58 | - public function saveBackendOptions(IUser $user, $id, $backendOptions) { |
|
59 | - // backendOptions are set when invoked via Files app |
|
60 | - // but they are not set when invoked via ext storage settings |
|
61 | - if (!isset($backendOptions['user']) && !isset($backendOptions['password'])) { |
|
62 | - return; |
|
63 | - } |
|
64 | - // make sure we're not setting any unexpected keys |
|
65 | - $credentials = [ |
|
66 | - 'user' => $backendOptions['user'], |
|
67 | - 'password' => $backendOptions['password'], |
|
68 | - ]; |
|
69 | - $this->credentialsManager->store($user->getUID(), self::CREDENTIALS_IDENTIFIER, $credentials); |
|
70 | - } |
|
58 | + public function saveBackendOptions(IUser $user, $id, $backendOptions) { |
|
59 | + // backendOptions are set when invoked via Files app |
|
60 | + // but they are not set when invoked via ext storage settings |
|
61 | + if (!isset($backendOptions['user']) && !isset($backendOptions['password'])) { |
|
62 | + return; |
|
63 | + } |
|
64 | + // make sure we're not setting any unexpected keys |
|
65 | + $credentials = [ |
|
66 | + 'user' => $backendOptions['user'], |
|
67 | + 'password' => $backendOptions['password'], |
|
68 | + ]; |
|
69 | + $this->credentialsManager->store($user->getUID(), self::CREDENTIALS_IDENTIFIER, $credentials); |
|
70 | + } |
|
71 | 71 | |
72 | - public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { |
|
73 | - if ($user === null) { |
|
74 | - throw new InsufficientDataForMeaningfulAnswerException('No credentials saved'); |
|
75 | - } |
|
72 | + public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { |
|
73 | + if ($user === null) { |
|
74 | + throw new InsufficientDataForMeaningfulAnswerException('No credentials saved'); |
|
75 | + } |
|
76 | 76 | |
77 | - $uid = $user->getUID(); |
|
78 | - $credentials = $this->credentialsManager->retrieve($uid, self::CREDENTIALS_IDENTIFIER); |
|
77 | + $uid = $user->getUID(); |
|
78 | + $credentials = $this->credentialsManager->retrieve($uid, self::CREDENTIALS_IDENTIFIER); |
|
79 | 79 | |
80 | - if (is_array($credentials)) { |
|
81 | - $storage->setBackendOption('user', $credentials['user']); |
|
82 | - $storage->setBackendOption('password', $credentials['password']); |
|
83 | - } |
|
84 | - } |
|
80 | + if (is_array($credentials)) { |
|
81 | + $storage->setBackendOption('user', $credentials['user']); |
|
82 | + $storage->setBackendOption('password', $credentials['password']); |
|
83 | + } |
|
84 | + } |
|
85 | 85 | } |
@@ -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 | } |
@@ -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,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 | } |
@@ -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 | } |