@@ -30,24 +30,24 @@ |
||
30 | 30 | use OCP\IL10N; |
31 | 31 | |
32 | 32 | class KerberosApacheAuth extends AuthMechanism { |
33 | - /** @var IStore */ |
|
34 | - private $credentialsStore; |
|
33 | + /** @var IStore */ |
|
34 | + private $credentialsStore; |
|
35 | 35 | |
36 | - public function __construct(IL10N $l, IStore $credentialsStore) { |
|
37 | - $realm = new DefinitionParameter('default_realm', 'Default realm'); |
|
38 | - $realm |
|
39 | - ->setType(DefinitionParameter::VALUE_TEXT) |
|
40 | - ->setFlag(DefinitionParameter::FLAG_OPTIONAL) |
|
41 | - ->setTooltip($l->t('Kerberos default realm, defaults to "WORKGROUP"')); |
|
42 | - $this |
|
43 | - ->setIdentifier('smb::kerberosapache') |
|
44 | - ->setScheme(self::SCHEME_SMB) |
|
45 | - ->setText($l->t('Kerberos ticket apache mode')) |
|
46 | - ->addParameter($realm); |
|
47 | - $this->credentialsStore = $credentialsStore; |
|
48 | - } |
|
36 | + public function __construct(IL10N $l, IStore $credentialsStore) { |
|
37 | + $realm = new DefinitionParameter('default_realm', 'Default realm'); |
|
38 | + $realm |
|
39 | + ->setType(DefinitionParameter::VALUE_TEXT) |
|
40 | + ->setFlag(DefinitionParameter::FLAG_OPTIONAL) |
|
41 | + ->setTooltip($l->t('Kerberos default realm, defaults to "WORKGROUP"')); |
|
42 | + $this |
|
43 | + ->setIdentifier('smb::kerberosapache') |
|
44 | + ->setScheme(self::SCHEME_SMB) |
|
45 | + ->setText($l->t('Kerberos ticket apache mode')) |
|
46 | + ->addParameter($realm); |
|
47 | + $this->credentialsStore = $credentialsStore; |
|
48 | + } |
|
49 | 49 | |
50 | - public function getCredentialsStore(): IStore { |
|
51 | - return $this->credentialsStore; |
|
52 | - } |
|
50 | + public function getCredentialsStore(): IStore { |
|
51 | + return $this->credentialsStore; |
|
52 | + } |
|
53 | 53 | } |
@@ -41,98 +41,98 @@ |
||
41 | 41 | use OCP\IUser; |
42 | 42 | |
43 | 43 | class SMB extends Backend { |
44 | - use LegacyDependencyCheckPolyfill; |
|
44 | + use LegacyDependencyCheckPolyfill; |
|
45 | 45 | |
46 | - public function __construct(IL10N $l, Password $legacyAuth) { |
|
47 | - $this |
|
48 | - ->setIdentifier('smb') |
|
49 | - ->addIdentifierAlias('\OC\Files\Storage\SMB')// legacy compat |
|
50 | - ->setStorageClass('\OCA\Files_External\Lib\Storage\SMB') |
|
51 | - ->setText($l->t('SMB/CIFS')) |
|
52 | - ->addParameters([ |
|
53 | - new DefinitionParameter('host', $l->t('Host')), |
|
54 | - new DefinitionParameter('share', $l->t('Share')), |
|
55 | - (new DefinitionParameter('root', $l->t('Remote subfolder'))) |
|
56 | - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
57 | - (new DefinitionParameter('domain', $l->t('Domain'))) |
|
58 | - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
59 | - (new DefinitionParameter('show_hidden', $l->t('Show hidden files'))) |
|
60 | - ->setType(DefinitionParameter::VALUE_BOOLEAN) |
|
61 | - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
62 | - (new DefinitionParameter('check_acl', $l->t('Verify ACL access when listing files'))) |
|
63 | - ->setType(DefinitionParameter::VALUE_BOOLEAN) |
|
64 | - ->setFlag(DefinitionParameter::FLAG_OPTIONAL) |
|
65 | - ->setTooltip($l->t("Check the ACL's of each file or folder inside a directory to filter out items where the user has no read permissions, comes with a performance penalty")), |
|
66 | - (new DefinitionParameter('timeout', $l->t('Timeout'))) |
|
67 | - ->setType(DefinitionParameter::VALUE_HIDDEN) |
|
68 | - ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
69 | - ]) |
|
70 | - ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) |
|
71 | - ->addAuthScheme(AuthMechanism::SCHEME_SMB) |
|
72 | - ->setLegacyAuthMechanism($legacyAuth); |
|
73 | - } |
|
46 | + public function __construct(IL10N $l, Password $legacyAuth) { |
|
47 | + $this |
|
48 | + ->setIdentifier('smb') |
|
49 | + ->addIdentifierAlias('\OC\Files\Storage\SMB')// legacy compat |
|
50 | + ->setStorageClass('\OCA\Files_External\Lib\Storage\SMB') |
|
51 | + ->setText($l->t('SMB/CIFS')) |
|
52 | + ->addParameters([ |
|
53 | + new DefinitionParameter('host', $l->t('Host')), |
|
54 | + new DefinitionParameter('share', $l->t('Share')), |
|
55 | + (new DefinitionParameter('root', $l->t('Remote subfolder'))) |
|
56 | + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
57 | + (new DefinitionParameter('domain', $l->t('Domain'))) |
|
58 | + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
59 | + (new DefinitionParameter('show_hidden', $l->t('Show hidden files'))) |
|
60 | + ->setType(DefinitionParameter::VALUE_BOOLEAN) |
|
61 | + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
62 | + (new DefinitionParameter('check_acl', $l->t('Verify ACL access when listing files'))) |
|
63 | + ->setType(DefinitionParameter::VALUE_BOOLEAN) |
|
64 | + ->setFlag(DefinitionParameter::FLAG_OPTIONAL) |
|
65 | + ->setTooltip($l->t("Check the ACL's of each file or folder inside a directory to filter out items where the user has no read permissions, comes with a performance penalty")), |
|
66 | + (new DefinitionParameter('timeout', $l->t('Timeout'))) |
|
67 | + ->setType(DefinitionParameter::VALUE_HIDDEN) |
|
68 | + ->setFlag(DefinitionParameter::FLAG_OPTIONAL), |
|
69 | + ]) |
|
70 | + ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD) |
|
71 | + ->addAuthScheme(AuthMechanism::SCHEME_SMB) |
|
72 | + ->setLegacyAuthMechanism($legacyAuth); |
|
73 | + } |
|
74 | 74 | |
75 | - public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { |
|
76 | - $auth = $storage->getAuthMechanism(); |
|
77 | - if ($auth->getScheme() === AuthMechanism::SCHEME_PASSWORD) { |
|
78 | - if (!is_string($storage->getBackendOption('user')) || !is_string($storage->getBackendOption('password'))) { |
|
79 | - throw new \InvalidArgumentException('user or password is not set'); |
|
80 | - } |
|
75 | + public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) { |
|
76 | + $auth = $storage->getAuthMechanism(); |
|
77 | + if ($auth->getScheme() === AuthMechanism::SCHEME_PASSWORD) { |
|
78 | + if (!is_string($storage->getBackendOption('user')) || !is_string($storage->getBackendOption('password'))) { |
|
79 | + throw new \InvalidArgumentException('user or password is not set'); |
|
80 | + } |
|
81 | 81 | |
82 | - $smbAuth = new BasicAuth( |
|
83 | - $storage->getBackendOption('user'), |
|
84 | - $storage->getBackendOption('domain'), |
|
85 | - $storage->getBackendOption('password') |
|
86 | - ); |
|
87 | - } else { |
|
88 | - switch ($auth->getIdentifier()) { |
|
89 | - case 'smb::kerberos': |
|
90 | - $smbAuth = new KerberosAuth(); |
|
91 | - break; |
|
92 | - case 'smb::kerberosapache': |
|
93 | - if (!$auth instanceof KerberosApacheAuthMechanism) { |
|
94 | - throw new \InvalidArgumentException('invalid authentication backend'); |
|
95 | - } |
|
96 | - $credentialsStore = $auth->getCredentialsStore(); |
|
97 | - $kerbAuth = new KerberosApacheAuth(); |
|
98 | - // check if a kerberos ticket is available, else fallback to session credentials |
|
99 | - if ($kerbAuth->checkTicket()) { |
|
100 | - $smbAuth = $kerbAuth; |
|
101 | - } else { |
|
102 | - try { |
|
103 | - $credentials = $credentialsStore->getLoginCredentials(); |
|
104 | - $user = $credentials->getLoginName(); |
|
105 | - $pass = $credentials->getPassword(); |
|
106 | - preg_match('/(.*)@(.*)/', $user, $matches); |
|
107 | - $realm = $storage->getBackendOption('default_realm'); |
|
108 | - if (empty($realm)) { |
|
109 | - $realm = 'WORKGROUP'; |
|
110 | - } |
|
111 | - $userPart = $matches[1]; |
|
112 | - $domainPart = $matches[2]; |
|
113 | - if (count($matches) === 0) { |
|
114 | - $username = $user; |
|
115 | - $workgroup = $realm; |
|
116 | - } else { |
|
117 | - $username = $userPart; |
|
118 | - $workgroup = $domainPart; |
|
119 | - } |
|
120 | - $smbAuth = new BasicAuth( |
|
121 | - $username, |
|
122 | - $workgroup, |
|
123 | - $pass |
|
124 | - ); |
|
125 | - } catch (\Exception $e) { |
|
126 | - throw new InsufficientDataForMeaningfulAnswerException('No session credentials saved'); |
|
127 | - } |
|
128 | - } |
|
82 | + $smbAuth = new BasicAuth( |
|
83 | + $storage->getBackendOption('user'), |
|
84 | + $storage->getBackendOption('domain'), |
|
85 | + $storage->getBackendOption('password') |
|
86 | + ); |
|
87 | + } else { |
|
88 | + switch ($auth->getIdentifier()) { |
|
89 | + case 'smb::kerberos': |
|
90 | + $smbAuth = new KerberosAuth(); |
|
91 | + break; |
|
92 | + case 'smb::kerberosapache': |
|
93 | + if (!$auth instanceof KerberosApacheAuthMechanism) { |
|
94 | + throw new \InvalidArgumentException('invalid authentication backend'); |
|
95 | + } |
|
96 | + $credentialsStore = $auth->getCredentialsStore(); |
|
97 | + $kerbAuth = new KerberosApacheAuth(); |
|
98 | + // check if a kerberos ticket is available, else fallback to session credentials |
|
99 | + if ($kerbAuth->checkTicket()) { |
|
100 | + $smbAuth = $kerbAuth; |
|
101 | + } else { |
|
102 | + try { |
|
103 | + $credentials = $credentialsStore->getLoginCredentials(); |
|
104 | + $user = $credentials->getLoginName(); |
|
105 | + $pass = $credentials->getPassword(); |
|
106 | + preg_match('/(.*)@(.*)/', $user, $matches); |
|
107 | + $realm = $storage->getBackendOption('default_realm'); |
|
108 | + if (empty($realm)) { |
|
109 | + $realm = 'WORKGROUP'; |
|
110 | + } |
|
111 | + $userPart = $matches[1]; |
|
112 | + $domainPart = $matches[2]; |
|
113 | + if (count($matches) === 0) { |
|
114 | + $username = $user; |
|
115 | + $workgroup = $realm; |
|
116 | + } else { |
|
117 | + $username = $userPart; |
|
118 | + $workgroup = $domainPart; |
|
119 | + } |
|
120 | + $smbAuth = new BasicAuth( |
|
121 | + $username, |
|
122 | + $workgroup, |
|
123 | + $pass |
|
124 | + ); |
|
125 | + } catch (\Exception $e) { |
|
126 | + throw new InsufficientDataForMeaningfulAnswerException('No session credentials saved'); |
|
127 | + } |
|
128 | + } |
|
129 | 129 | |
130 | - break; |
|
131 | - default: |
|
132 | - throw new \InvalidArgumentException('unknown authentication backend'); |
|
133 | - } |
|
134 | - } |
|
130 | + break; |
|
131 | + default: |
|
132 | + throw new \InvalidArgumentException('unknown authentication backend'); |
|
133 | + } |
|
134 | + } |
|
135 | 135 | |
136 | - $storage->setBackendOption('auth', $smbAuth); |
|
137 | - } |
|
136 | + $storage->setBackendOption('auth', $smbAuth); |
|
137 | + } |
|
138 | 138 | } |
@@ -79,109 +79,109 @@ |
||
79 | 79 | */ |
80 | 80 | class Application extends App implements IBackendProvider, IAuthMechanismProvider, IBootstrap { |
81 | 81 | |
82 | - /** |
|
83 | - * Application constructor. |
|
84 | - * |
|
85 | - * @throws \OCP\AppFramework\QueryException |
|
86 | - */ |
|
87 | - public function __construct(array $urlParams = []) { |
|
88 | - parent::__construct('files_external', $urlParams); |
|
89 | - } |
|
90 | - |
|
91 | - public function register(IRegistrationContext $context): void { |
|
92 | - $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); |
|
93 | - $context->registerEventListener(GroupDeletedEvent::class, GroupDeletedListener::class); |
|
94 | - } |
|
95 | - |
|
96 | - public function boot(IBootContext $context): void { |
|
97 | - $context->injectFn(function (IMountProviderCollection $mountProviderCollection, ConfigAdapter $configAdapter) { |
|
98 | - $mountProviderCollection->registerProvider($configAdapter); |
|
99 | - }); |
|
100 | - \OCA\Files\App::getNavigationManager()->add(function () { |
|
101 | - $l = \OC::$server->getL10N('files_external'); |
|
102 | - return [ |
|
103 | - 'id' => 'extstoragemounts', |
|
104 | - 'appname' => 'files_external', |
|
105 | - 'script' => 'list.php', |
|
106 | - 'order' => 30, |
|
107 | - 'name' => $l->t('External storage'), |
|
108 | - ]; |
|
109 | - }); |
|
110 | - $context->injectFn(function (BackendService $backendService, UserPlaceholderHandler $userConfigHandler) { |
|
111 | - $backendService->registerBackendProvider($this); |
|
112 | - $backendService->registerAuthMechanismProvider($this); |
|
113 | - $backendService->registerConfigHandler('user', function () use ($userConfigHandler) { |
|
114 | - return $userConfigHandler; |
|
115 | - }); |
|
116 | - }); |
|
117 | - |
|
118 | - // force-load auth mechanisms since some will register hooks |
|
119 | - // TODO: obsolete these and use the TokenProvider to get the user's password from the session |
|
120 | - $this->getAuthMechanisms(); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * @{inheritdoc} |
|
125 | - */ |
|
126 | - public function getBackends() { |
|
127 | - $container = $this->getContainer(); |
|
128 | - |
|
129 | - $backends = [ |
|
130 | - $container->get(Local::class), |
|
131 | - $container->get(FTP::class), |
|
132 | - $container->get(DAV::class), |
|
133 | - $container->get(OwnCloud::class), |
|
134 | - $container->get(SFTP::class), |
|
135 | - $container->get(AmazonS3::class), |
|
136 | - $container->get(Swift::class), |
|
137 | - $container->get(SFTP_Key::class), |
|
138 | - $container->get(SMB::class), |
|
139 | - $container->get(SMB_OC::class), |
|
140 | - ]; |
|
141 | - |
|
142 | - return $backends; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @{inheritdoc} |
|
147 | - */ |
|
148 | - public function getAuthMechanisms() { |
|
149 | - $container = $this->getContainer(); |
|
150 | - |
|
151 | - return [ |
|
152 | - // AuthMechanism::SCHEME_NULL mechanism |
|
153 | - $container->get(NullMechanism::class), |
|
154 | - |
|
155 | - // AuthMechanism::SCHEME_BUILTIN mechanism |
|
156 | - $container->get(Builtin::class), |
|
157 | - |
|
158 | - // AuthMechanism::SCHEME_PASSWORD mechanisms |
|
159 | - $container->get(Password::class), |
|
160 | - $container->get(SessionCredentials::class), |
|
161 | - $container->get(LoginCredentials::class), |
|
162 | - $container->get(UserProvided::class), |
|
163 | - $container->get(GlobalAuth::class), |
|
164 | - $container->get(UserGlobalAuth::class), |
|
165 | - |
|
166 | - // AuthMechanism::SCHEME_OAUTH1 mechanisms |
|
167 | - $container->get(OAuth1::class), |
|
168 | - |
|
169 | - // AuthMechanism::SCHEME_OAUTH2 mechanisms |
|
170 | - $container->get(OAuth2::class), |
|
171 | - |
|
172 | - // AuthMechanism::SCHEME_PUBLICKEY mechanisms |
|
173 | - $container->get(RSA::class), |
|
174 | - $container->get(RSAPrivateKey::class), |
|
175 | - |
|
176 | - // AuthMechanism::SCHEME_OPENSTACK mechanisms |
|
177 | - $container->get(OpenStackV2::class), |
|
178 | - $container->get(OpenStackV3::class), |
|
179 | - $container->get(Rackspace::class), |
|
180 | - |
|
181 | - // Specialized mechanisms |
|
182 | - $container->get(AccessKey::class), |
|
183 | - $container->get(KerberosAuth::class), |
|
184 | - $container->get(KerberosApacheAuth::class), |
|
185 | - ]; |
|
186 | - } |
|
82 | + /** |
|
83 | + * Application constructor. |
|
84 | + * |
|
85 | + * @throws \OCP\AppFramework\QueryException |
|
86 | + */ |
|
87 | + public function __construct(array $urlParams = []) { |
|
88 | + parent::__construct('files_external', $urlParams); |
|
89 | + } |
|
90 | + |
|
91 | + public function register(IRegistrationContext $context): void { |
|
92 | + $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); |
|
93 | + $context->registerEventListener(GroupDeletedEvent::class, GroupDeletedListener::class); |
|
94 | + } |
|
95 | + |
|
96 | + public function boot(IBootContext $context): void { |
|
97 | + $context->injectFn(function (IMountProviderCollection $mountProviderCollection, ConfigAdapter $configAdapter) { |
|
98 | + $mountProviderCollection->registerProvider($configAdapter); |
|
99 | + }); |
|
100 | + \OCA\Files\App::getNavigationManager()->add(function () { |
|
101 | + $l = \OC::$server->getL10N('files_external'); |
|
102 | + return [ |
|
103 | + 'id' => 'extstoragemounts', |
|
104 | + 'appname' => 'files_external', |
|
105 | + 'script' => 'list.php', |
|
106 | + 'order' => 30, |
|
107 | + 'name' => $l->t('External storage'), |
|
108 | + ]; |
|
109 | + }); |
|
110 | + $context->injectFn(function (BackendService $backendService, UserPlaceholderHandler $userConfigHandler) { |
|
111 | + $backendService->registerBackendProvider($this); |
|
112 | + $backendService->registerAuthMechanismProvider($this); |
|
113 | + $backendService->registerConfigHandler('user', function () use ($userConfigHandler) { |
|
114 | + return $userConfigHandler; |
|
115 | + }); |
|
116 | + }); |
|
117 | + |
|
118 | + // force-load auth mechanisms since some will register hooks |
|
119 | + // TODO: obsolete these and use the TokenProvider to get the user's password from the session |
|
120 | + $this->getAuthMechanisms(); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * @{inheritdoc} |
|
125 | + */ |
|
126 | + public function getBackends() { |
|
127 | + $container = $this->getContainer(); |
|
128 | + |
|
129 | + $backends = [ |
|
130 | + $container->get(Local::class), |
|
131 | + $container->get(FTP::class), |
|
132 | + $container->get(DAV::class), |
|
133 | + $container->get(OwnCloud::class), |
|
134 | + $container->get(SFTP::class), |
|
135 | + $container->get(AmazonS3::class), |
|
136 | + $container->get(Swift::class), |
|
137 | + $container->get(SFTP_Key::class), |
|
138 | + $container->get(SMB::class), |
|
139 | + $container->get(SMB_OC::class), |
|
140 | + ]; |
|
141 | + |
|
142 | + return $backends; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @{inheritdoc} |
|
147 | + */ |
|
148 | + public function getAuthMechanisms() { |
|
149 | + $container = $this->getContainer(); |
|
150 | + |
|
151 | + return [ |
|
152 | + // AuthMechanism::SCHEME_NULL mechanism |
|
153 | + $container->get(NullMechanism::class), |
|
154 | + |
|
155 | + // AuthMechanism::SCHEME_BUILTIN mechanism |
|
156 | + $container->get(Builtin::class), |
|
157 | + |
|
158 | + // AuthMechanism::SCHEME_PASSWORD mechanisms |
|
159 | + $container->get(Password::class), |
|
160 | + $container->get(SessionCredentials::class), |
|
161 | + $container->get(LoginCredentials::class), |
|
162 | + $container->get(UserProvided::class), |
|
163 | + $container->get(GlobalAuth::class), |
|
164 | + $container->get(UserGlobalAuth::class), |
|
165 | + |
|
166 | + // AuthMechanism::SCHEME_OAUTH1 mechanisms |
|
167 | + $container->get(OAuth1::class), |
|
168 | + |
|
169 | + // AuthMechanism::SCHEME_OAUTH2 mechanisms |
|
170 | + $container->get(OAuth2::class), |
|
171 | + |
|
172 | + // AuthMechanism::SCHEME_PUBLICKEY mechanisms |
|
173 | + $container->get(RSA::class), |
|
174 | + $container->get(RSAPrivateKey::class), |
|
175 | + |
|
176 | + // AuthMechanism::SCHEME_OPENSTACK mechanisms |
|
177 | + $container->get(OpenStackV2::class), |
|
178 | + $container->get(OpenStackV3::class), |
|
179 | + $container->get(Rackspace::class), |
|
180 | + |
|
181 | + // Specialized mechanisms |
|
182 | + $container->get(AccessKey::class), |
|
183 | + $container->get(KerberosAuth::class), |
|
184 | + $container->get(KerberosApacheAuth::class), |
|
185 | + ]; |
|
186 | + } |
|
187 | 187 | } |