@@ -30,19 +30,19 @@ |
||
| 30 | 30 | |
| 31 | 31 | class MandatoryTwoFactor { |
| 32 | 32 | |
| 33 | - /** @var IConfig */ |
|
| 34 | - private $config; |
|
| 33 | + /** @var IConfig */ |
|
| 34 | + private $config; |
|
| 35 | 35 | |
| 36 | - public function __construct(IConfig $config) { |
|
| 37 | - $this->config = $config; |
|
| 38 | - } |
|
| 36 | + public function __construct(IConfig $config) { |
|
| 37 | + $this->config = $config; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - public function isEnforced(): bool { |
|
| 41 | - return $this->config->getSystemValue('twofactor_enforced', 'false') === 'true'; |
|
| 42 | - } |
|
| 40 | + public function isEnforced(): bool { |
|
| 41 | + return $this->config->getSystemValue('twofactor_enforced', 'false') === 'true'; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - public function setEnforced(bool $enforced) { |
|
| 45 | - $this->config->setSystemValue('twofactor_enforced', $enforced ? 'true' : 'false'); |
|
| 46 | - } |
|
| 44 | + public function setEnforced(bool $enforced) { |
|
| 45 | + $this->config->setSystemValue('twofactor_enforced', $enforced ? 'true' : 'false'); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | } |
@@ -46,322 +46,322 @@ |
||
| 46 | 46 | |
| 47 | 47 | class Manager { |
| 48 | 48 | |
| 49 | - const SESSION_UID_KEY = 'two_factor_auth_uid'; |
|
| 50 | - const SESSION_UID_DONE = 'two_factor_auth_passed'; |
|
| 51 | - const REMEMBER_LOGIN = 'two_factor_remember_login'; |
|
| 52 | - const BACKUP_CODES_PROVIDER_ID = 'backup_codes'; |
|
| 53 | - |
|
| 54 | - /** @var ProviderLoader */ |
|
| 55 | - private $providerLoader; |
|
| 56 | - |
|
| 57 | - /** @var IRegistry */ |
|
| 58 | - private $providerRegistry; |
|
| 59 | - |
|
| 60 | - /** @var MandatoryTwoFactor */ |
|
| 61 | - private $mandatoryTwoFactor; |
|
| 62 | - |
|
| 63 | - /** @var ISession */ |
|
| 64 | - private $session; |
|
| 65 | - |
|
| 66 | - /** @var IConfig */ |
|
| 67 | - private $config; |
|
| 68 | - |
|
| 69 | - /** @var IManager */ |
|
| 70 | - private $activityManager; |
|
| 71 | - |
|
| 72 | - /** @var ILogger */ |
|
| 73 | - private $logger; |
|
| 74 | - |
|
| 75 | - /** @var TokenProvider */ |
|
| 76 | - private $tokenProvider; |
|
| 77 | - |
|
| 78 | - /** @var ITimeFactory */ |
|
| 79 | - private $timeFactory; |
|
| 80 | - |
|
| 81 | - /** @var EventDispatcherInterface */ |
|
| 82 | - private $dispatcher; |
|
| 83 | - |
|
| 84 | - public function __construct(ProviderLoader $providerLoader, |
|
| 85 | - IRegistry $providerRegistry, |
|
| 86 | - MandatoryTwoFactor $mandatoryTwoFactor, |
|
| 87 | - ISession $session, IConfig $config, |
|
| 88 | - IManager $activityManager, ILogger $logger, TokenProvider $tokenProvider, |
|
| 89 | - ITimeFactory $timeFactory, EventDispatcherInterface $eventDispatcher) { |
|
| 90 | - $this->providerLoader = $providerLoader; |
|
| 91 | - $this->providerRegistry = $providerRegistry; |
|
| 92 | - $this->mandatoryTwoFactor = $mandatoryTwoFactor; |
|
| 93 | - $this->session = $session; |
|
| 94 | - $this->config = $config; |
|
| 95 | - $this->activityManager = $activityManager; |
|
| 96 | - $this->logger = $logger; |
|
| 97 | - $this->tokenProvider = $tokenProvider; |
|
| 98 | - $this->timeFactory = $timeFactory; |
|
| 99 | - $this->dispatcher = $eventDispatcher; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Determine whether the user must provide a second factor challenge |
|
| 104 | - * |
|
| 105 | - * @param IUser $user |
|
| 106 | - * @return boolean |
|
| 107 | - */ |
|
| 108 | - public function isTwoFactorAuthenticated(IUser $user): bool { |
|
| 109 | - if ($this->mandatoryTwoFactor->isEnforced()) { |
|
| 110 | - return true; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $providerStates = $this->providerRegistry->getProviderStates($user); |
|
| 114 | - $providers = $this->providerLoader->getProviders($user); |
|
| 115 | - $fixedStates = $this->fixMissingProviderStates($providerStates, $providers, $user); |
|
| 116 | - $enabled = array_filter($fixedStates); |
|
| 117 | - $providerIds = array_keys($enabled); |
|
| 118 | - $providerIdsWithoutBackupCodes = array_diff($providerIds, [self::BACKUP_CODES_PROVIDER_ID]); |
|
| 119 | - |
|
| 120 | - return !empty($providerIdsWithoutBackupCodes); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Get a 2FA provider by its ID |
|
| 125 | - * |
|
| 126 | - * @param IUser $user |
|
| 127 | - * @param string $challengeProviderId |
|
| 128 | - * @return IProvider|null |
|
| 129 | - */ |
|
| 130 | - public function getProvider(IUser $user, string $challengeProviderId) { |
|
| 131 | - $providers = $this->getProviderSet($user)->getProviders(); |
|
| 132 | - return $providers[$challengeProviderId] ?? null; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Check if the persistant mapping of enabled/disabled state of each available |
|
| 137 | - * provider is missing an entry and add it to the registry in that case. |
|
| 138 | - * |
|
| 139 | - * @todo remove in Nextcloud 17 as by then all providers should have been updated |
|
| 140 | - * |
|
| 141 | - * @param string[] $providerStates |
|
| 142 | - * @param IProvider[] $providers |
|
| 143 | - * @param IUser $user |
|
| 144 | - * @return string[] the updated $providerStates variable |
|
| 145 | - */ |
|
| 146 | - private function fixMissingProviderStates(array $providerStates, |
|
| 147 | - array $providers, IUser $user): array { |
|
| 148 | - |
|
| 149 | - foreach ($providers as $provider) { |
|
| 150 | - if (isset($providerStates[$provider->getId()])) { |
|
| 151 | - // All good |
|
| 152 | - continue; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - $enabled = $provider->isTwoFactorAuthEnabledForUser($user); |
|
| 156 | - if ($enabled) { |
|
| 157 | - $this->providerRegistry->enableProviderFor($provider, $user); |
|
| 158 | - } else { |
|
| 159 | - $this->providerRegistry->disableProviderFor($provider, $user); |
|
| 160 | - } |
|
| 161 | - $providerStates[$provider->getId()] = $enabled; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return $providerStates; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @param array $states |
|
| 169 | - * @param IProvider $providers |
|
| 170 | - */ |
|
| 171 | - private function isProviderMissing(array $states, array $providers): bool { |
|
| 172 | - $indexed = []; |
|
| 173 | - foreach ($providers as $provider) { |
|
| 174 | - $indexed[$provider->getId()] = $provider; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - $missing = []; |
|
| 178 | - foreach ($states as $providerId => $enabled) { |
|
| 179 | - if (!$enabled) { |
|
| 180 | - // Don't care |
|
| 181 | - continue; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - if (!isset($indexed[$providerId])) { |
|
| 185 | - $missing[] = $providerId; |
|
| 186 | - $this->logger->alert("two-factor auth provider '$providerId' failed to load", |
|
| 187 | - [ |
|
| 188 | - 'app' => 'core', |
|
| 189 | - ]); |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - if (!empty($missing)) { |
|
| 194 | - // There was at least one provider missing |
|
| 195 | - $this->logger->alert(count($missing) . " two-factor auth providers failed to load", ['app' => 'core']); |
|
| 196 | - |
|
| 197 | - return true; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // If we reach this, there was not a single provider missing |
|
| 201 | - return false; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Get the list of 2FA providers for the given user |
|
| 206 | - * |
|
| 207 | - * @param IUser $user |
|
| 208 | - * @throws Exception |
|
| 209 | - */ |
|
| 210 | - public function getProviderSet(IUser $user): ProviderSet { |
|
| 211 | - $providerStates = $this->providerRegistry->getProviderStates($user); |
|
| 212 | - $providers = $this->providerLoader->getProviders($user); |
|
| 213 | - |
|
| 214 | - $fixedStates = $this->fixMissingProviderStates($providerStates, $providers, $user); |
|
| 215 | - $isProviderMissing = $this->isProviderMissing($fixedStates, $providers); |
|
| 216 | - |
|
| 217 | - $enabled = array_filter($providers, function (IProvider $provider) use ($fixedStates) { |
|
| 218 | - return $fixedStates[$provider->getId()]; |
|
| 219 | - }); |
|
| 220 | - return new ProviderSet($enabled, $isProviderMissing); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Verify the given challenge |
|
| 225 | - * |
|
| 226 | - * @param string $providerId |
|
| 227 | - * @param IUser $user |
|
| 228 | - * @param string $challenge |
|
| 229 | - * @return boolean |
|
| 230 | - */ |
|
| 231 | - public function verifyChallenge(string $providerId, IUser $user, string $challenge): bool { |
|
| 232 | - $provider = $this->getProvider($user, $providerId); |
|
| 233 | - if ($provider === null) { |
|
| 234 | - return false; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - $passed = $provider->verifyChallenge($user, $challenge); |
|
| 238 | - if ($passed) { |
|
| 239 | - if ($this->session->get(self::REMEMBER_LOGIN) === true) { |
|
| 240 | - // TODO: resolve cyclic dependency and use DI |
|
| 241 | - \OC::$server->getUserSession()->createRememberMeToken($user); |
|
| 242 | - } |
|
| 243 | - $this->session->remove(self::SESSION_UID_KEY); |
|
| 244 | - $this->session->remove(self::REMEMBER_LOGIN); |
|
| 245 | - $this->session->set(self::SESSION_UID_DONE, $user->getUID()); |
|
| 246 | - |
|
| 247 | - // Clear token from db |
|
| 248 | - $sessionId = $this->session->getId(); |
|
| 249 | - $token = $this->tokenProvider->getToken($sessionId); |
|
| 250 | - $tokenId = $token->getId(); |
|
| 251 | - $this->config->deleteUserValue($user->getUID(), 'login_token_2fa', $tokenId); |
|
| 252 | - |
|
| 253 | - $dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]); |
|
| 254 | - $this->dispatcher->dispatch(IProvider::EVENT_SUCCESS, $dispatchEvent); |
|
| 255 | - |
|
| 256 | - $this->publishEvent($user, 'twofactor_success', [ |
|
| 257 | - 'provider' => $provider->getDisplayName(), |
|
| 258 | - ]); |
|
| 259 | - } else { |
|
| 260 | - $dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]); |
|
| 261 | - $this->dispatcher->dispatch(IProvider::EVENT_FAILED, $dispatchEvent); |
|
| 262 | - |
|
| 263 | - $this->publishEvent($user, 'twofactor_failed', [ |
|
| 264 | - 'provider' => $provider->getDisplayName(), |
|
| 265 | - ]); |
|
| 266 | - } |
|
| 267 | - return $passed; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Push a 2fa event the user's activity stream |
|
| 272 | - * |
|
| 273 | - * @param IUser $user |
|
| 274 | - * @param string $event |
|
| 275 | - * @param array $params |
|
| 276 | - */ |
|
| 277 | - private function publishEvent(IUser $user, string $event, array $params) { |
|
| 278 | - $activity = $this->activityManager->generateEvent(); |
|
| 279 | - $activity->setApp('core') |
|
| 280 | - ->setType('security') |
|
| 281 | - ->setAuthor($user->getUID()) |
|
| 282 | - ->setAffectedUser($user->getUID()) |
|
| 283 | - ->setSubject($event, $params); |
|
| 284 | - try { |
|
| 285 | - $this->activityManager->publish($activity); |
|
| 286 | - } catch (BadMethodCallException $e) { |
|
| 287 | - $this->logger->warning('could not publish activity', ['app' => 'core']); |
|
| 288 | - $this->logger->logException($e, ['app' => 'core']); |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Check if the currently logged in user needs to pass 2FA |
|
| 294 | - * |
|
| 295 | - * @param IUser $user the currently logged in user |
|
| 296 | - * @return boolean |
|
| 297 | - */ |
|
| 298 | - public function needsSecondFactor(IUser $user = null): bool { |
|
| 299 | - if ($user === null) { |
|
| 300 | - return false; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - // If we are authenticated using an app password skip all this |
|
| 304 | - if ($this->session->exists('app_password')) { |
|
| 305 | - return false; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - // First check if the session tells us we should do 2FA (99% case) |
|
| 309 | - if (!$this->session->exists(self::SESSION_UID_KEY)) { |
|
| 310 | - |
|
| 311 | - // Check if the session tells us it is 2FA authenticated already |
|
| 312 | - if ($this->session->exists(self::SESSION_UID_DONE) && |
|
| 313 | - $this->session->get(self::SESSION_UID_DONE) === $user->getUID()) { |
|
| 314 | - return false; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /* |
|
| 49 | + const SESSION_UID_KEY = 'two_factor_auth_uid'; |
|
| 50 | + const SESSION_UID_DONE = 'two_factor_auth_passed'; |
|
| 51 | + const REMEMBER_LOGIN = 'two_factor_remember_login'; |
|
| 52 | + const BACKUP_CODES_PROVIDER_ID = 'backup_codes'; |
|
| 53 | + |
|
| 54 | + /** @var ProviderLoader */ |
|
| 55 | + private $providerLoader; |
|
| 56 | + |
|
| 57 | + /** @var IRegistry */ |
|
| 58 | + private $providerRegistry; |
|
| 59 | + |
|
| 60 | + /** @var MandatoryTwoFactor */ |
|
| 61 | + private $mandatoryTwoFactor; |
|
| 62 | + |
|
| 63 | + /** @var ISession */ |
|
| 64 | + private $session; |
|
| 65 | + |
|
| 66 | + /** @var IConfig */ |
|
| 67 | + private $config; |
|
| 68 | + |
|
| 69 | + /** @var IManager */ |
|
| 70 | + private $activityManager; |
|
| 71 | + |
|
| 72 | + /** @var ILogger */ |
|
| 73 | + private $logger; |
|
| 74 | + |
|
| 75 | + /** @var TokenProvider */ |
|
| 76 | + private $tokenProvider; |
|
| 77 | + |
|
| 78 | + /** @var ITimeFactory */ |
|
| 79 | + private $timeFactory; |
|
| 80 | + |
|
| 81 | + /** @var EventDispatcherInterface */ |
|
| 82 | + private $dispatcher; |
|
| 83 | + |
|
| 84 | + public function __construct(ProviderLoader $providerLoader, |
|
| 85 | + IRegistry $providerRegistry, |
|
| 86 | + MandatoryTwoFactor $mandatoryTwoFactor, |
|
| 87 | + ISession $session, IConfig $config, |
|
| 88 | + IManager $activityManager, ILogger $logger, TokenProvider $tokenProvider, |
|
| 89 | + ITimeFactory $timeFactory, EventDispatcherInterface $eventDispatcher) { |
|
| 90 | + $this->providerLoader = $providerLoader; |
|
| 91 | + $this->providerRegistry = $providerRegistry; |
|
| 92 | + $this->mandatoryTwoFactor = $mandatoryTwoFactor; |
|
| 93 | + $this->session = $session; |
|
| 94 | + $this->config = $config; |
|
| 95 | + $this->activityManager = $activityManager; |
|
| 96 | + $this->logger = $logger; |
|
| 97 | + $this->tokenProvider = $tokenProvider; |
|
| 98 | + $this->timeFactory = $timeFactory; |
|
| 99 | + $this->dispatcher = $eventDispatcher; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Determine whether the user must provide a second factor challenge |
|
| 104 | + * |
|
| 105 | + * @param IUser $user |
|
| 106 | + * @return boolean |
|
| 107 | + */ |
|
| 108 | + public function isTwoFactorAuthenticated(IUser $user): bool { |
|
| 109 | + if ($this->mandatoryTwoFactor->isEnforced()) { |
|
| 110 | + return true; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $providerStates = $this->providerRegistry->getProviderStates($user); |
|
| 114 | + $providers = $this->providerLoader->getProviders($user); |
|
| 115 | + $fixedStates = $this->fixMissingProviderStates($providerStates, $providers, $user); |
|
| 116 | + $enabled = array_filter($fixedStates); |
|
| 117 | + $providerIds = array_keys($enabled); |
|
| 118 | + $providerIdsWithoutBackupCodes = array_diff($providerIds, [self::BACKUP_CODES_PROVIDER_ID]); |
|
| 119 | + |
|
| 120 | + return !empty($providerIdsWithoutBackupCodes); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Get a 2FA provider by its ID |
|
| 125 | + * |
|
| 126 | + * @param IUser $user |
|
| 127 | + * @param string $challengeProviderId |
|
| 128 | + * @return IProvider|null |
|
| 129 | + */ |
|
| 130 | + public function getProvider(IUser $user, string $challengeProviderId) { |
|
| 131 | + $providers = $this->getProviderSet($user)->getProviders(); |
|
| 132 | + return $providers[$challengeProviderId] ?? null; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Check if the persistant mapping of enabled/disabled state of each available |
|
| 137 | + * provider is missing an entry and add it to the registry in that case. |
|
| 138 | + * |
|
| 139 | + * @todo remove in Nextcloud 17 as by then all providers should have been updated |
|
| 140 | + * |
|
| 141 | + * @param string[] $providerStates |
|
| 142 | + * @param IProvider[] $providers |
|
| 143 | + * @param IUser $user |
|
| 144 | + * @return string[] the updated $providerStates variable |
|
| 145 | + */ |
|
| 146 | + private function fixMissingProviderStates(array $providerStates, |
|
| 147 | + array $providers, IUser $user): array { |
|
| 148 | + |
|
| 149 | + foreach ($providers as $provider) { |
|
| 150 | + if (isset($providerStates[$provider->getId()])) { |
|
| 151 | + // All good |
|
| 152 | + continue; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + $enabled = $provider->isTwoFactorAuthEnabledForUser($user); |
|
| 156 | + if ($enabled) { |
|
| 157 | + $this->providerRegistry->enableProviderFor($provider, $user); |
|
| 158 | + } else { |
|
| 159 | + $this->providerRegistry->disableProviderFor($provider, $user); |
|
| 160 | + } |
|
| 161 | + $providerStates[$provider->getId()] = $enabled; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return $providerStates; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @param array $states |
|
| 169 | + * @param IProvider $providers |
|
| 170 | + */ |
|
| 171 | + private function isProviderMissing(array $states, array $providers): bool { |
|
| 172 | + $indexed = []; |
|
| 173 | + foreach ($providers as $provider) { |
|
| 174 | + $indexed[$provider->getId()] = $provider; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + $missing = []; |
|
| 178 | + foreach ($states as $providerId => $enabled) { |
|
| 179 | + if (!$enabled) { |
|
| 180 | + // Don't care |
|
| 181 | + continue; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + if (!isset($indexed[$providerId])) { |
|
| 185 | + $missing[] = $providerId; |
|
| 186 | + $this->logger->alert("two-factor auth provider '$providerId' failed to load", |
|
| 187 | + [ |
|
| 188 | + 'app' => 'core', |
|
| 189 | + ]); |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + if (!empty($missing)) { |
|
| 194 | + // There was at least one provider missing |
|
| 195 | + $this->logger->alert(count($missing) . " two-factor auth providers failed to load", ['app' => 'core']); |
|
| 196 | + |
|
| 197 | + return true; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // If we reach this, there was not a single provider missing |
|
| 201 | + return false; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Get the list of 2FA providers for the given user |
|
| 206 | + * |
|
| 207 | + * @param IUser $user |
|
| 208 | + * @throws Exception |
|
| 209 | + */ |
|
| 210 | + public function getProviderSet(IUser $user): ProviderSet { |
|
| 211 | + $providerStates = $this->providerRegistry->getProviderStates($user); |
|
| 212 | + $providers = $this->providerLoader->getProviders($user); |
|
| 213 | + |
|
| 214 | + $fixedStates = $this->fixMissingProviderStates($providerStates, $providers, $user); |
|
| 215 | + $isProviderMissing = $this->isProviderMissing($fixedStates, $providers); |
|
| 216 | + |
|
| 217 | + $enabled = array_filter($providers, function (IProvider $provider) use ($fixedStates) { |
|
| 218 | + return $fixedStates[$provider->getId()]; |
|
| 219 | + }); |
|
| 220 | + return new ProviderSet($enabled, $isProviderMissing); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Verify the given challenge |
|
| 225 | + * |
|
| 226 | + * @param string $providerId |
|
| 227 | + * @param IUser $user |
|
| 228 | + * @param string $challenge |
|
| 229 | + * @return boolean |
|
| 230 | + */ |
|
| 231 | + public function verifyChallenge(string $providerId, IUser $user, string $challenge): bool { |
|
| 232 | + $provider = $this->getProvider($user, $providerId); |
|
| 233 | + if ($provider === null) { |
|
| 234 | + return false; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + $passed = $provider->verifyChallenge($user, $challenge); |
|
| 238 | + if ($passed) { |
|
| 239 | + if ($this->session->get(self::REMEMBER_LOGIN) === true) { |
|
| 240 | + // TODO: resolve cyclic dependency and use DI |
|
| 241 | + \OC::$server->getUserSession()->createRememberMeToken($user); |
|
| 242 | + } |
|
| 243 | + $this->session->remove(self::SESSION_UID_KEY); |
|
| 244 | + $this->session->remove(self::REMEMBER_LOGIN); |
|
| 245 | + $this->session->set(self::SESSION_UID_DONE, $user->getUID()); |
|
| 246 | + |
|
| 247 | + // Clear token from db |
|
| 248 | + $sessionId = $this->session->getId(); |
|
| 249 | + $token = $this->tokenProvider->getToken($sessionId); |
|
| 250 | + $tokenId = $token->getId(); |
|
| 251 | + $this->config->deleteUserValue($user->getUID(), 'login_token_2fa', $tokenId); |
|
| 252 | + |
|
| 253 | + $dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]); |
|
| 254 | + $this->dispatcher->dispatch(IProvider::EVENT_SUCCESS, $dispatchEvent); |
|
| 255 | + |
|
| 256 | + $this->publishEvent($user, 'twofactor_success', [ |
|
| 257 | + 'provider' => $provider->getDisplayName(), |
|
| 258 | + ]); |
|
| 259 | + } else { |
|
| 260 | + $dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]); |
|
| 261 | + $this->dispatcher->dispatch(IProvider::EVENT_FAILED, $dispatchEvent); |
|
| 262 | + |
|
| 263 | + $this->publishEvent($user, 'twofactor_failed', [ |
|
| 264 | + 'provider' => $provider->getDisplayName(), |
|
| 265 | + ]); |
|
| 266 | + } |
|
| 267 | + return $passed; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Push a 2fa event the user's activity stream |
|
| 272 | + * |
|
| 273 | + * @param IUser $user |
|
| 274 | + * @param string $event |
|
| 275 | + * @param array $params |
|
| 276 | + */ |
|
| 277 | + private function publishEvent(IUser $user, string $event, array $params) { |
|
| 278 | + $activity = $this->activityManager->generateEvent(); |
|
| 279 | + $activity->setApp('core') |
|
| 280 | + ->setType('security') |
|
| 281 | + ->setAuthor($user->getUID()) |
|
| 282 | + ->setAffectedUser($user->getUID()) |
|
| 283 | + ->setSubject($event, $params); |
|
| 284 | + try { |
|
| 285 | + $this->activityManager->publish($activity); |
|
| 286 | + } catch (BadMethodCallException $e) { |
|
| 287 | + $this->logger->warning('could not publish activity', ['app' => 'core']); |
|
| 288 | + $this->logger->logException($e, ['app' => 'core']); |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Check if the currently logged in user needs to pass 2FA |
|
| 294 | + * |
|
| 295 | + * @param IUser $user the currently logged in user |
|
| 296 | + * @return boolean |
|
| 297 | + */ |
|
| 298 | + public function needsSecondFactor(IUser $user = null): bool { |
|
| 299 | + if ($user === null) { |
|
| 300 | + return false; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + // If we are authenticated using an app password skip all this |
|
| 304 | + if ($this->session->exists('app_password')) { |
|
| 305 | + return false; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + // First check if the session tells us we should do 2FA (99% case) |
|
| 309 | + if (!$this->session->exists(self::SESSION_UID_KEY)) { |
|
| 310 | + |
|
| 311 | + // Check if the session tells us it is 2FA authenticated already |
|
| 312 | + if ($this->session->exists(self::SESSION_UID_DONE) && |
|
| 313 | + $this->session->get(self::SESSION_UID_DONE) === $user->getUID()) { |
|
| 314 | + return false; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /* |
|
| 318 | 318 | * If the session is expired check if we are not logged in by a token |
| 319 | 319 | * that still needs 2FA auth |
| 320 | 320 | */ |
| 321 | - try { |
|
| 322 | - $sessionId = $this->session->getId(); |
|
| 323 | - $token = $this->tokenProvider->getToken($sessionId); |
|
| 324 | - $tokenId = $token->getId(); |
|
| 325 | - $tokensNeeding2FA = $this->config->getUserKeys($user->getUID(), 'login_token_2fa'); |
|
| 326 | - |
|
| 327 | - if (!\in_array($tokenId, $tokensNeeding2FA, true)) { |
|
| 328 | - $this->session->set(self::SESSION_UID_DONE, $user->getUID()); |
|
| 329 | - return false; |
|
| 330 | - } |
|
| 331 | - } catch (InvalidTokenException $e) { |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - if (!$this->isTwoFactorAuthenticated($user)) { |
|
| 336 | - // There is no second factor any more -> let the user pass |
|
| 337 | - // This prevents infinite redirect loops when a user is about |
|
| 338 | - // to solve the 2FA challenge, and the provider app is |
|
| 339 | - // disabled the same time |
|
| 340 | - $this->session->remove(self::SESSION_UID_KEY); |
|
| 341 | - |
|
| 342 | - $keys = $this->config->getUserKeys($user->getUID(), 'login_token_2fa'); |
|
| 343 | - foreach ($keys as $key) { |
|
| 344 | - $this->config->deleteUserValue($user->getUID(), 'login_token_2fa', $key); |
|
| 345 | - } |
|
| 346 | - return false; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - return true; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Prepare the 2FA login |
|
| 354 | - * |
|
| 355 | - * @param IUser $user |
|
| 356 | - * @param boolean $rememberMe |
|
| 357 | - */ |
|
| 358 | - public function prepareTwoFactorLogin(IUser $user, bool $rememberMe) { |
|
| 359 | - $this->session->set(self::SESSION_UID_KEY, $user->getUID()); |
|
| 360 | - $this->session->set(self::REMEMBER_LOGIN, $rememberMe); |
|
| 361 | - |
|
| 362 | - $id = $this->session->getId(); |
|
| 363 | - $token = $this->tokenProvider->getToken($id); |
|
| 364 | - $this->config->setUserValue($user->getUID(), 'login_token_2fa', $token->getId(), $this->timeFactory->getTime()); |
|
| 365 | - } |
|
| 321 | + try { |
|
| 322 | + $sessionId = $this->session->getId(); |
|
| 323 | + $token = $this->tokenProvider->getToken($sessionId); |
|
| 324 | + $tokenId = $token->getId(); |
|
| 325 | + $tokensNeeding2FA = $this->config->getUserKeys($user->getUID(), 'login_token_2fa'); |
|
| 326 | + |
|
| 327 | + if (!\in_array($tokenId, $tokensNeeding2FA, true)) { |
|
| 328 | + $this->session->set(self::SESSION_UID_DONE, $user->getUID()); |
|
| 329 | + return false; |
|
| 330 | + } |
|
| 331 | + } catch (InvalidTokenException $e) { |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + if (!$this->isTwoFactorAuthenticated($user)) { |
|
| 336 | + // There is no second factor any more -> let the user pass |
|
| 337 | + // This prevents infinite redirect loops when a user is about |
|
| 338 | + // to solve the 2FA challenge, and the provider app is |
|
| 339 | + // disabled the same time |
|
| 340 | + $this->session->remove(self::SESSION_UID_KEY); |
|
| 341 | + |
|
| 342 | + $keys = $this->config->getUserKeys($user->getUID(), 'login_token_2fa'); |
|
| 343 | + foreach ($keys as $key) { |
|
| 344 | + $this->config->deleteUserValue($user->getUID(), 'login_token_2fa', $key); |
|
| 345 | + } |
|
| 346 | + return false; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + return true; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Prepare the 2FA login |
|
| 354 | + * |
|
| 355 | + * @param IUser $user |
|
| 356 | + * @param boolean $rememberMe |
|
| 357 | + */ |
|
| 358 | + public function prepareTwoFactorLogin(IUser $user, bool $rememberMe) { |
|
| 359 | + $this->session->set(self::SESSION_UID_KEY, $user->getUID()); |
|
| 360 | + $this->session->set(self::REMEMBER_LOGIN, $rememberMe); |
|
| 361 | + |
|
| 362 | + $id = $this->session->getId(); |
|
| 363 | + $token = $this->tokenProvider->getToken($id); |
|
| 364 | + $this->config->setUserValue($user->getUID(), 'login_token_2fa', $token->getId(), $this->timeFactory->getTime()); |
|
| 365 | + } |
|
| 366 | 366 | |
| 367 | 367 | } |
@@ -43,124 +43,124 @@ |
||
| 43 | 43 | $application->add(new OC\Core\Command\App\CheckCode()); |
| 44 | 44 | $application->add(new OC\Core\Command\L10n\CreateJs()); |
| 45 | 45 | $application->add(new \OC\Core\Command\Integrity\SignApp( |
| 46 | - \OC::$server->getIntegrityCodeChecker(), |
|
| 47 | - new \OC\IntegrityCheck\Helpers\FileAccessHelper(), |
|
| 48 | - \OC::$server->getURLGenerator() |
|
| 46 | + \OC::$server->getIntegrityCodeChecker(), |
|
| 47 | + new \OC\IntegrityCheck\Helpers\FileAccessHelper(), |
|
| 48 | + \OC::$server->getURLGenerator() |
|
| 49 | 49 | )); |
| 50 | 50 | $application->add(new \OC\Core\Command\Integrity\SignCore( |
| 51 | - \OC::$server->getIntegrityCodeChecker(), |
|
| 52 | - new \OC\IntegrityCheck\Helpers\FileAccessHelper() |
|
| 51 | + \OC::$server->getIntegrityCodeChecker(), |
|
| 52 | + new \OC\IntegrityCheck\Helpers\FileAccessHelper() |
|
| 53 | 53 | )); |
| 54 | 54 | $application->add(new \OC\Core\Command\Integrity\CheckApp( |
| 55 | - \OC::$server->getIntegrityCodeChecker() |
|
| 55 | + \OC::$server->getIntegrityCodeChecker() |
|
| 56 | 56 | )); |
| 57 | 57 | $application->add(new \OC\Core\Command\Integrity\CheckCore( |
| 58 | - \OC::$server->getIntegrityCodeChecker() |
|
| 58 | + \OC::$server->getIntegrityCodeChecker() |
|
| 59 | 59 | )); |
| 60 | 60 | |
| 61 | 61 | |
| 62 | 62 | if (\OC::$server->getConfig()->getSystemValue('installed', false)) { |
| 63 | - $application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager())); |
|
| 64 | - $application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager())); |
|
| 65 | - $application->add(new OC\Core\Command\App\Install()); |
|
| 66 | - $application->add(new OC\Core\Command\App\GetPath()); |
|
| 67 | - $application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager())); |
|
| 63 | + $application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager())); |
|
| 64 | + $application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager())); |
|
| 65 | + $application->add(new OC\Core\Command\App\Install()); |
|
| 66 | + $application->add(new OC\Core\Command\App\GetPath()); |
|
| 67 | + $application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager())); |
|
| 68 | 68 | |
| 69 | - $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Cleanup::class)); |
|
| 70 | - $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enforce::class)); |
|
| 71 | - $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enable::class)); |
|
| 72 | - $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Disable::class)); |
|
| 73 | - $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\State::class)); |
|
| 69 | + $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Cleanup::class)); |
|
| 70 | + $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enforce::class)); |
|
| 71 | + $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enable::class)); |
|
| 72 | + $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Disable::class)); |
|
| 73 | + $application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\State::class)); |
|
| 74 | 74 | |
| 75 | - $application->add(new OC\Core\Command\Background\Cron(\OC::$server->getConfig())); |
|
| 76 | - $application->add(new OC\Core\Command\Background\WebCron(\OC::$server->getConfig())); |
|
| 77 | - $application->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig())); |
|
| 75 | + $application->add(new OC\Core\Command\Background\Cron(\OC::$server->getConfig())); |
|
| 76 | + $application->add(new OC\Core\Command\Background\WebCron(\OC::$server->getConfig())); |
|
| 77 | + $application->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig())); |
|
| 78 | 78 | |
| 79 | - $application->add(new OC\Core\Command\Config\App\DeleteConfig(\OC::$server->getConfig())); |
|
| 80 | - $application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig())); |
|
| 81 | - $application->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig())); |
|
| 82 | - $application->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig())); |
|
| 83 | - $application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig())); |
|
| 84 | - $application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig())); |
|
| 85 | - $application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig())); |
|
| 86 | - $application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig())); |
|
| 79 | + $application->add(new OC\Core\Command\Config\App\DeleteConfig(\OC::$server->getConfig())); |
|
| 80 | + $application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig())); |
|
| 81 | + $application->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig())); |
|
| 82 | + $application->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig())); |
|
| 83 | + $application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig())); |
|
| 84 | + $application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig())); |
|
| 85 | + $application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig())); |
|
| 86 | + $application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig())); |
|
| 87 | 87 | |
| 88 | - $application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig()))); |
|
| 89 | - $application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->getLogger())); |
|
| 90 | - $application->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->getDatabaseConnection())); |
|
| 91 | - $application->add(new OC\Core\Command\Db\AddMissingIndices(\OC::$server->getDatabaseConnection(), \OC::$server->getEventDispatcher())); |
|
| 92 | - $application->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->getDatabaseConnection())); |
|
| 93 | - $application->add(new OC\Core\Command\Db\Migrations\MigrateCommand(\OC::$server->getDatabaseConnection())); |
|
| 94 | - $application->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->getDatabaseConnection(), \OC::$server->getAppManager())); |
|
| 95 | - $application->add(new OC\Core\Command\Db\Migrations\GenerateFromSchemaFileCommand(\OC::$server->getConfig(), \OC::$server->getAppManager(), \OC::$server->getDatabaseConnection())); |
|
| 96 | - $application->add(new OC\Core\Command\Db\Migrations\ExecuteCommand(\OC::$server->getDatabaseConnection(), \OC::$server->getAppManager(), \OC::$server->getConfig())); |
|
| 88 | + $application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig()))); |
|
| 89 | + $application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->getLogger())); |
|
| 90 | + $application->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->getDatabaseConnection())); |
|
| 91 | + $application->add(new OC\Core\Command\Db\AddMissingIndices(\OC::$server->getDatabaseConnection(), \OC::$server->getEventDispatcher())); |
|
| 92 | + $application->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->getDatabaseConnection())); |
|
| 93 | + $application->add(new OC\Core\Command\Db\Migrations\MigrateCommand(\OC::$server->getDatabaseConnection())); |
|
| 94 | + $application->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->getDatabaseConnection(), \OC::$server->getAppManager())); |
|
| 95 | + $application->add(new OC\Core\Command\Db\Migrations\GenerateFromSchemaFileCommand(\OC::$server->getConfig(), \OC::$server->getAppManager(), \OC::$server->getDatabaseConnection())); |
|
| 96 | + $application->add(new OC\Core\Command\Db\Migrations\ExecuteCommand(\OC::$server->getDatabaseConnection(), \OC::$server->getAppManager(), \OC::$server->getConfig())); |
|
| 97 | 97 | |
| 98 | - $application->add(new OC\Core\Command\Encryption\Disable(\OC::$server->getConfig())); |
|
| 99 | - $application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager())); |
|
| 100 | - $application->add(new OC\Core\Command\Encryption\ListModules(\OC::$server->getEncryptionManager())); |
|
| 101 | - $application->add(new OC\Core\Command\Encryption\SetDefaultModule(\OC::$server->getEncryptionManager())); |
|
| 102 | - $application->add(new OC\Core\Command\Encryption\Status(\OC::$server->getEncryptionManager())); |
|
| 103 | - $application->add(new OC\Core\Command\Encryption\EncryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getAppManager(), \OC::$server->getConfig(), new \Symfony\Component\Console\Helper\QuestionHelper())); |
|
| 104 | - $application->add(new OC\Core\Command\Encryption\DecryptAll( |
|
| 105 | - \OC::$server->getEncryptionManager(), |
|
| 106 | - \OC::$server->getAppManager(), |
|
| 107 | - \OC::$server->getConfig(), |
|
| 108 | - new \OC\Encryption\DecryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getUserManager(), new \OC\Files\View()), |
|
| 109 | - new \Symfony\Component\Console\Helper\QuestionHelper()) |
|
| 110 | - ); |
|
| 98 | + $application->add(new OC\Core\Command\Encryption\Disable(\OC::$server->getConfig())); |
|
| 99 | + $application->add(new OC\Core\Command\Encryption\Enable(\OC::$server->getConfig(), \OC::$server->getEncryptionManager())); |
|
| 100 | + $application->add(new OC\Core\Command\Encryption\ListModules(\OC::$server->getEncryptionManager())); |
|
| 101 | + $application->add(new OC\Core\Command\Encryption\SetDefaultModule(\OC::$server->getEncryptionManager())); |
|
| 102 | + $application->add(new OC\Core\Command\Encryption\Status(\OC::$server->getEncryptionManager())); |
|
| 103 | + $application->add(new OC\Core\Command\Encryption\EncryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getAppManager(), \OC::$server->getConfig(), new \Symfony\Component\Console\Helper\QuestionHelper())); |
|
| 104 | + $application->add(new OC\Core\Command\Encryption\DecryptAll( |
|
| 105 | + \OC::$server->getEncryptionManager(), |
|
| 106 | + \OC::$server->getAppManager(), |
|
| 107 | + \OC::$server->getConfig(), |
|
| 108 | + new \OC\Encryption\DecryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getUserManager(), new \OC\Files\View()), |
|
| 109 | + new \Symfony\Component\Console\Helper\QuestionHelper()) |
|
| 110 | + ); |
|
| 111 | 111 | |
| 112 | - $application->add(new OC\Core\Command\Log\Manage(\OC::$server->getConfig())); |
|
| 113 | - $application->add(new OC\Core\Command\Log\File(\OC::$server->getConfig())); |
|
| 112 | + $application->add(new OC\Core\Command\Log\Manage(\OC::$server->getConfig())); |
|
| 113 | + $application->add(new OC\Core\Command\Log\File(\OC::$server->getConfig())); |
|
| 114 | 114 | |
| 115 | - $view = new \OC\Files\View(); |
|
| 116 | - $util = new \OC\Encryption\Util( |
|
| 117 | - $view, |
|
| 118 | - \OC::$server->getUserManager(), |
|
| 119 | - \OC::$server->getGroupManager(), |
|
| 120 | - \OC::$server->getConfig() |
|
| 121 | - ); |
|
| 122 | - $application->add(new OC\Core\Command\Encryption\ChangeKeyStorageRoot( |
|
| 123 | - $view, |
|
| 124 | - \OC::$server->getUserManager(), |
|
| 125 | - \OC::$server->getConfig(), |
|
| 126 | - $util, |
|
| 127 | - new \Symfony\Component\Console\Helper\QuestionHelper() |
|
| 128 | - ) |
|
| 129 | - ); |
|
| 130 | - $application->add(new OC\Core\Command\Encryption\ShowKeyStorageRoot($util)); |
|
| 115 | + $view = new \OC\Files\View(); |
|
| 116 | + $util = new \OC\Encryption\Util( |
|
| 117 | + $view, |
|
| 118 | + \OC::$server->getUserManager(), |
|
| 119 | + \OC::$server->getGroupManager(), |
|
| 120 | + \OC::$server->getConfig() |
|
| 121 | + ); |
|
| 122 | + $application->add(new OC\Core\Command\Encryption\ChangeKeyStorageRoot( |
|
| 123 | + $view, |
|
| 124 | + \OC::$server->getUserManager(), |
|
| 125 | + \OC::$server->getConfig(), |
|
| 126 | + $util, |
|
| 127 | + new \Symfony\Component\Console\Helper\QuestionHelper() |
|
| 128 | + ) |
|
| 129 | + ); |
|
| 130 | + $application->add(new OC\Core\Command\Encryption\ShowKeyStorageRoot($util)); |
|
| 131 | 131 | |
| 132 | - $application->add(new OC\Core\Command\Maintenance\DataFingerprint(\OC::$server->getConfig(), new \OC\AppFramework\Utility\TimeFactory())); |
|
| 133 | - $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->getMimeTypeDetector(), \OC::$server->getMimeTypeLoader())); |
|
| 134 | - $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector())); |
|
| 135 | - $application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig())); |
|
| 136 | - $application->add(new OC\Core\Command\Maintenance\UpdateHtaccess()); |
|
| 137 | - $application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory())); |
|
| 132 | + $application->add(new OC\Core\Command\Maintenance\DataFingerprint(\OC::$server->getConfig(), new \OC\AppFramework\Utility\TimeFactory())); |
|
| 133 | + $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->getMimeTypeDetector(), \OC::$server->getMimeTypeLoader())); |
|
| 134 | + $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector())); |
|
| 135 | + $application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig())); |
|
| 136 | + $application->add(new OC\Core\Command\Maintenance\UpdateHtaccess()); |
|
| 137 | + $application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory())); |
|
| 138 | 138 | |
| 139 | - $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->query(\OC\Installer::class))); |
|
| 140 | - $application->add(new OC\Core\Command\Maintenance\Repair( |
|
| 141 | - new \OC\Repair(\OC\Repair::getRepairSteps(), \OC::$server->getEventDispatcher()), \OC::$server->getConfig(), |
|
| 142 | - \OC::$server->getEventDispatcher(), \OC::$server->getAppManager())); |
|
| 139 | + $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->query(\OC\Installer::class))); |
|
| 140 | + $application->add(new OC\Core\Command\Maintenance\Repair( |
|
| 141 | + new \OC\Repair(\OC\Repair::getRepairSteps(), \OC::$server->getEventDispatcher()), \OC::$server->getConfig(), |
|
| 142 | + \OC::$server->getEventDispatcher(), \OC::$server->getAppManager())); |
|
| 143 | 143 | |
| 144 | - $application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
| 145 | - $application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager())); |
|
| 146 | - $application->add(new OC\Core\Command\User\Disable(\OC::$server->getUserManager())); |
|
| 147 | - $application->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager())); |
|
| 148 | - $application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager())); |
|
| 149 | - $application->add(new OC\Core\Command\User\Report(\OC::$server->getUserManager())); |
|
| 150 | - $application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager())); |
|
| 151 | - $application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig(), \OC::$server->getDatabaseConnection())); |
|
| 152 | - $application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager())); |
|
| 153 | - $application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
| 144 | + $application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
| 145 | + $application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager())); |
|
| 146 | + $application->add(new OC\Core\Command\User\Disable(\OC::$server->getUserManager())); |
|
| 147 | + $application->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager())); |
|
| 148 | + $application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager())); |
|
| 149 | + $application->add(new OC\Core\Command\User\Report(\OC::$server->getUserManager())); |
|
| 150 | + $application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager())); |
|
| 151 | + $application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig(), \OC::$server->getDatabaseConnection())); |
|
| 152 | + $application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager())); |
|
| 153 | + $application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
| 154 | 154 | |
| 155 | - $application->add(new OC\Core\Command\Group\Add(\OC::$server->getGroupManager())); |
|
| 156 | - $application->add(new OC\Core\Command\Group\Delete(\OC::$server->getGroupManager())); |
|
| 157 | - $application->add(new OC\Core\Command\Group\ListCommand(\OC::$server->getGroupManager())); |
|
| 158 | - $application->add(new OC\Core\Command\Group\AddUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
| 159 | - $application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
| 155 | + $application->add(new OC\Core\Command\Group\Add(\OC::$server->getGroupManager())); |
|
| 156 | + $application->add(new OC\Core\Command\Group\Delete(\OC::$server->getGroupManager())); |
|
| 157 | + $application->add(new OC\Core\Command\Group\ListCommand(\OC::$server->getGroupManager())); |
|
| 158 | + $application->add(new OC\Core\Command\Group\AddUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
| 159 | + $application->add(new OC\Core\Command\Group\RemoveUser(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); |
|
| 160 | 160 | |
| 161 | - $application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(null), \OC::$server->getL10N('core'))); |
|
| 162 | - $application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager(null))); |
|
| 163 | - $application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager(null))); |
|
| 161 | + $application->add(new OC\Core\Command\Security\ListCertificates(\OC::$server->getCertificateManager(null), \OC::$server->getL10N('core'))); |
|
| 162 | + $application->add(new OC\Core\Command\Security\ImportCertificate(\OC::$server->getCertificateManager(null))); |
|
| 163 | + $application->add(new OC\Core\Command\Security\RemoveCertificate(\OC::$server->getCertificateManager(null))); |
|
| 164 | 164 | } else { |
| 165 | - $application->add(new OC\Core\Command\Maintenance\Install(\OC::$server->getSystemConfig())); |
|
| 165 | + $application->add(new OC\Core\Command\Maintenance\Install(\OC::$server->getSystemConfig())); |
|
| 166 | 166 | } |
@@ -34,58 +34,58 @@ |
||
| 34 | 34 | |
| 35 | 35 | class Enforce extends Command { |
| 36 | 36 | |
| 37 | - /** @var MandatoryTwoFactor */ |
|
| 38 | - private $mandatoryTwoFactor; |
|
| 37 | + /** @var MandatoryTwoFactor */ |
|
| 38 | + private $mandatoryTwoFactor; |
|
| 39 | 39 | |
| 40 | - public function __construct(MandatoryTwoFactor $mandatoryTwoFactor) { |
|
| 41 | - parent::__construct(); |
|
| 40 | + public function __construct(MandatoryTwoFactor $mandatoryTwoFactor) { |
|
| 41 | + parent::__construct(); |
|
| 42 | 42 | |
| 43 | - $this->mandatoryTwoFactor = $mandatoryTwoFactor; |
|
| 44 | - } |
|
| 43 | + $this->mandatoryTwoFactor = $mandatoryTwoFactor; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - protected function configure() { |
|
| 47 | - $this->setName('twofactorauth:enforce'); |
|
| 48 | - $this->setDescription('Enabled/disable enforced two-factor authentication'); |
|
| 49 | - $this->addOption( |
|
| 50 | - 'on', |
|
| 51 | - null, |
|
| 52 | - InputOption::VALUE_NONE, |
|
| 53 | - 'enforce two-factor authentication' |
|
| 54 | - ); |
|
| 55 | - $this->addOption( |
|
| 56 | - 'off', |
|
| 57 | - null, |
|
| 58 | - InputOption::VALUE_NONE, |
|
| 59 | - 'don\'t enforce two-factor authenticaton' |
|
| 60 | - ); |
|
| 61 | - } |
|
| 46 | + protected function configure() { |
|
| 47 | + $this->setName('twofactorauth:enforce'); |
|
| 48 | + $this->setDescription('Enabled/disable enforced two-factor authentication'); |
|
| 49 | + $this->addOption( |
|
| 50 | + 'on', |
|
| 51 | + null, |
|
| 52 | + InputOption::VALUE_NONE, |
|
| 53 | + 'enforce two-factor authentication' |
|
| 54 | + ); |
|
| 55 | + $this->addOption( |
|
| 56 | + 'off', |
|
| 57 | + null, |
|
| 58 | + InputOption::VALUE_NONE, |
|
| 59 | + 'don\'t enforce two-factor authenticaton' |
|
| 60 | + ); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 64 | - if ($input->getOption('on')) { |
|
| 65 | - $this->mandatoryTwoFactor->setEnforced(true); |
|
| 66 | - } elseif ($input->getOption('off')) { |
|
| 67 | - $this->mandatoryTwoFactor->setEnforced(false); |
|
| 68 | - } |
|
| 63 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 64 | + if ($input->getOption('on')) { |
|
| 65 | + $this->mandatoryTwoFactor->setEnforced(true); |
|
| 66 | + } elseif ($input->getOption('off')) { |
|
| 67 | + $this->mandatoryTwoFactor->setEnforced(false); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - if ($this->mandatoryTwoFactor->isEnforced()) { |
|
| 71 | - $this->writeEnforced($output); |
|
| 72 | - } else { |
|
| 73 | - $this->writeNotEnforced($output); |
|
| 74 | - } |
|
| 75 | - } |
|
| 70 | + if ($this->mandatoryTwoFactor->isEnforced()) { |
|
| 71 | + $this->writeEnforced($output); |
|
| 72 | + } else { |
|
| 73 | + $this->writeNotEnforced($output); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @param OutputInterface $output |
|
| 79 | - */ |
|
| 80 | - protected function writeEnforced(OutputInterface $output) { |
|
| 81 | - $output->writeln('Two-factor authentication is enforced for all users'); |
|
| 82 | - } |
|
| 77 | + /** |
|
| 78 | + * @param OutputInterface $output |
|
| 79 | + */ |
|
| 80 | + protected function writeEnforced(OutputInterface $output) { |
|
| 81 | + $output->writeln('Two-factor authentication is enforced for all users'); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * @param OutputInterface $output |
|
| 86 | - */ |
|
| 87 | - protected function writeNotEnforced(OutputInterface $output) { |
|
| 88 | - $output->writeln('Two-factor authentication is not enforced'); |
|
| 89 | - } |
|
| 84 | + /** |
|
| 85 | + * @param OutputInterface $output |
|
| 86 | + */ |
|
| 87 | + protected function writeNotEnforced(OutputInterface $output) { |
|
| 88 | + $output->writeln('Two-factor authentication is not enforced'); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | 91 | } |