|
34 | 34 | namespace OC\Template; |
35 | 35 |
|
36 | 36 | use bantu\IniGetWrapper\IniGetWrapper; |
| 37 | +use OC\Authentication\Token\IProvider; |
37 | 38 | use OC\CapabilitiesManager; |
38 | 39 | use OC\Share\Share; |
39 | 40 | use OCP\App\AppPathNotFoundException; |
40 | 41 | use OCP\App\IAppManager; |
| 42 | +use OCP\Authentication\Exceptions\ExpiredTokenException; |
| 43 | +use OCP\Authentication\Exceptions\InvalidTokenException; |
| 44 | +use OCP\Authentication\Exceptions\WipeTokenException; |
41 | 45 | use OCP\Constants; |
42 | 46 | use OCP\Defaults; |
43 | 47 | use OCP\Files\FileInfo; |
|
53 | 57 | use OCP\Util; |
54 | 58 |
|
55 | 59 | class JSConfigHelper { |
56 | | - protected IL10N $l; |
57 | | - protected Defaults $defaults; |
58 | | - protected IAppManager $appManager; |
59 | | - protected ISession $session; |
60 | | - protected ?IUser $currentUser; |
61 | | - protected IConfig $config; |
62 | | - protected IGroupManager $groupManager; |
63 | | - protected IniGetWrapper $iniWrapper; |
64 | | - protected IURLGenerator $urlGenerator; |
65 | | - protected CapabilitiesManager $capabilitiesManager; |
66 | | - protected IInitialStateService $initialStateService; |
67 | 60 |
|
68 | 61 | /** @var array user back-ends excluded from password verification */ |
69 | 62 | private $excludedUserBackEnds = ['user_saml' => true, 'user_globalsiteselector' => true]; |
70 | 63 |
|
71 | | - public function __construct(IL10N $l, |
72 | | - Defaults $defaults, |
73 | | - IAppManager $appManager, |
74 | | - ISession $session, |
75 | | - ?IUser $currentUser, |
76 | | - IConfig $config, |
77 | | - IGroupManager $groupManager, |
78 | | - IniGetWrapper $iniWrapper, |
79 | | - IURLGenerator $urlGenerator, |
80 | | - CapabilitiesManager $capabilitiesManager, |
81 | | - IInitialStateService $initialStateService) { |
82 | | - $this->l = $l; |
83 | | - $this->defaults = $defaults; |
84 | | - $this->appManager = $appManager; |
85 | | - $this->session = $session; |
86 | | - $this->currentUser = $currentUser; |
87 | | - $this->config = $config; |
88 | | - $this->groupManager = $groupManager; |
89 | | - $this->iniWrapper = $iniWrapper; |
90 | | - $this->urlGenerator = $urlGenerator; |
91 | | - $this->capabilitiesManager = $capabilitiesManager; |
92 | | - $this->initialStateService = $initialStateService; |
| 64 | + public function __construct( |
| 65 | + protected IL10N $l, |
| 66 | + protected Defaults $defaults, |
| 67 | + protected IAppManager $appManager, |
| 68 | + protected ISession $session, |
| 69 | + protected ?IUser $currentUser, |
| 70 | + protected IConfig $config, |
| 71 | + protected IGroupManager $groupManager, |
| 72 | + protected IniGetWrapper $iniWrapper, |
| 73 | + protected IURLGenerator $urlGenerator, |
| 74 | + protected CapabilitiesManager $capabilitiesManager, |
| 75 | + protected IInitialStateService $initialStateService, |
| 76 | + protected IProvider $tokenProvider, |
| 77 | + ) { |
93 | 78 | } |
94 | 79 |
|
95 | 80 | public function getConfig(): string { |
@@ -155,9 +140,13 @@ public function getConfig(): string { |
155 | 140 | } |
156 | 141 |
|
157 | 142 | if ($this->currentUser instanceof IUser) { |
158 | | - $lastConfirmTimestamp = $this->session->get('last-password-confirm'); |
159 | | - if (!is_int($lastConfirmTimestamp)) { |
160 | | - $lastConfirmTimestamp = 0; |
| 143 | + if ($this->canUserValidatePassword()) { |
| 144 | + $lastConfirmTimestamp = $this->session->get('last-password-confirm'); |
| 145 | + if (!is_int($lastConfirmTimestamp)) { |
| 146 | + $lastConfirmTimestamp = 0; |
| 147 | + } |
| 148 | + } else { |
| 149 | + $lastConfirmTimestamp = PHP_INT_MAX; |
161 | 150 | } |
162 | 151 | } else { |
163 | 152 | $lastConfirmTimestamp = 0; |
@@ -311,4 +300,15 @@ public function getConfig(): string { |
311 | 300 |
|
312 | 301 | return $result; |
313 | 302 | } |
| 303 | + |
| 304 | + protected function canUserValidatePassword(): bool { |
| 305 | + try { |
| 306 | + $token = $this->tokenProvider->getToken($this->session->getId()); |
| 307 | + } catch (ExpiredTokenException|WipeTokenException|InvalidTokenException|SessionNotAvailableException) { |
| 308 | + // actually we do not know, so we fall back to this statement |
| 309 | + return true; |
| 310 | + } |
| 311 | + $scope = $token->getScopeAsArray(); |
| 312 | + return !isset($scope['sso-based-login']) || $scope['sso-based-login'] === false; |
| 313 | + } |
314 | 314 | } |
0 commit comments