@@ -80,6 +80,10 @@ public function generateToken(string $token,
8080 string $ name ,
8181 int $ type = IToken::TEMPORARY_TOKEN ,
8282 int $ remember = IToken::DO_NOT_REMEMBER ): IToken {
83+ if ($ this ->config ->getSystemValueBool ('auth.authtoken.v1.disabled ' )) {
84+ throw new InvalidTokenException ('Authtokens v1 disabled ' );
85+ }
86+
8387 $ dbToken = new DefaultToken ();
8488 $ dbToken ->setUid ($ uid );
8589 $ dbToken ->setLoginName ($ loginName );
@@ -106,6 +110,10 @@ public function generateToken(string $token,
106110 * @throws InvalidTokenException
107111 */
108112 public function updateToken (IToken $ token ) {
113+ if ($ this ->config ->getSystemValueBool ('auth.authtoken.v1.disabled ' )) {
114+ throw new InvalidTokenException ('Authtokens v1 disabled ' );
115+ }
116+
109117 if (!($ token instanceof DefaultToken)) {
110118 throw new InvalidTokenException ("Invalid token type " );
111119 }
@@ -119,6 +127,10 @@ public function updateToken(IToken $token) {
119127 * @param IToken $token
120128 */
121129 public function updateTokenActivity (IToken $ token ) {
130+ if ($ this ->config ->getSystemValueBool ('auth.authtoken.v1.disabled ' )) {
131+ throw new InvalidTokenException ('Authtokens v1 disabled ' );
132+ }
133+
122134 if (!($ token instanceof DefaultToken)) {
123135 throw new InvalidTokenException ("Invalid token type " );
124136 }
@@ -132,6 +144,10 @@ public function updateTokenActivity(IToken $token) {
132144 }
133145
134146 public function getTokenByUser (string $ uid ): array {
147+ if ($ this ->config ->getSystemValueBool ('auth.authtoken.v1.disabled ' )) {
148+ return [];
149+ }
150+
135151 return $ this ->mapper ->getTokenByUser ($ uid );
136152 }
137153
@@ -144,6 +160,10 @@ public function getTokenByUser(string $uid): array {
144160 * @return IToken
145161 */
146162 public function getToken (string $ tokenId ): IToken {
163+ if ($ this ->config ->getSystemValueBool ('auth.authtoken.v1.disabled ' )) {
164+ throw new InvalidTokenException ('Authtokens v1 disabled ' );
165+ }
166+
147167 try {
148168 $ token = $ this ->mapper ->getToken ($ this ->hashToken ($ tokenId ));
149169 } catch (DoesNotExistException $ ex ) {
@@ -166,6 +186,10 @@ public function getToken(string $tokenId): IToken {
166186 * @return IToken
167187 */
168188 public function getTokenById (int $ tokenId ): IToken {
189+ if ($ this ->config ->getSystemValueBool ('auth.authtoken.v1.disabled ' )) {
190+ throw new InvalidTokenException ('Authtokens v1 disabled ' );
191+ }
192+
169193 try {
170194 $ token = $ this ->mapper ->getTokenById ($ tokenId );
171195 } catch (DoesNotExistException $ ex ) {
@@ -186,6 +210,10 @@ public function getTokenById(int $tokenId): IToken {
186210 * @return IToken
187211 */
188212 public function renewSessionToken (string $ oldSessionId , string $ sessionId ): IToken {
213+ if ($ this ->config ->getSystemValueBool ('auth.authtoken.v1.disabled ' )) {
214+ throw new InvalidTokenException ('Authtokens v1 disabled ' );
215+ }
216+
189217 $ token = $ this ->getToken ($ oldSessionId );
190218
191219 $ newToken = new DefaultToken ();
@@ -214,6 +242,10 @@ public function renewSessionToken(string $oldSessionId, string $sessionId): ITok
214242 * @return string
215243 */
216244 public function getPassword (IToken $ savedToken , string $ tokenId ): string {
245+ if ($ this ->config ->getSystemValueBool ('auth.authtoken.v1.disabled ' )) {
246+ throw new InvalidTokenException ('Authtokens v1 disabled ' );
247+ }
248+
217249 $ password = $ savedToken ->getPassword ();
218250 if ($ password === null || $ password === '' ) {
219251 throw new PasswordlessTokenException ();
@@ -230,6 +262,10 @@ public function getPassword(IToken $savedToken, string $tokenId): string {
230262 * @throws InvalidTokenException
231263 */
232264 public function setPassword (IToken $ token , string $ tokenId , string $ password ) {
265+ if ($ this ->config ->getSystemValueBool ('auth.authtoken.v1.disabled ' )) {
266+ throw new InvalidTokenException ('Authtokens v1 disabled ' );
267+ }
268+
233269 if (!($ token instanceof DefaultToken)) {
234270 throw new InvalidTokenException ("Invalid token type " );
235271 }
@@ -244,17 +280,29 @@ public function setPassword(IToken $token, string $tokenId, string $password) {
244280 * @param string $token
245281 */
246282 public function invalidateToken (string $ token ) {
283+ if ($ this ->config ->getSystemValueBool ('auth.authtoken.v1.disabled ' )) {
284+ return ;
285+ }
286+
247287 $ this ->mapper ->invalidate ($ this ->hashToken ($ token ));
248288 }
249289
250290 public function invalidateTokenById (string $ uid , int $ id ) {
291+ if ($ this ->config ->getSystemValueBool ('auth.authtoken.v1.disabled ' )) {
292+ return ;
293+ }
294+
251295 $ this ->mapper ->deleteById ($ uid , $ id );
252296 }
253297
254298 /**
255299 * Invalidate (delete) old session tokens
256300 */
257301 public function invalidateOldTokens () {
302+ if ($ this ->config ->getSystemValueBool ('auth.authtoken.v1.disabled ' )) {
303+ return ;
304+ }
305+
258306 $ olderThan = $ this ->time ->getTime () - (int ) $ this ->config ->getSystemValue ('session_lifetime ' , 60 * 60 * 24 );
259307 $ this ->logger ->debug ('Invalidating session tokens older than ' . date ('c ' , $ olderThan ), ['app ' => 'cron ' ]);
260308 $ this ->mapper ->invalidateOld ($ olderThan , IToken::DO_NOT_REMEMBER );
@@ -272,6 +320,10 @@ public function invalidateOldTokens() {
272320 * @return IToken
273321 */
274322 public function rotate (IToken $ token , string $ oldTokenId , string $ newTokenId ): IToken {
323+ if ($ this ->config ->getSystemValueBool ('auth.authtoken.v1.disabled ' )) {
324+ throw new InvalidTokenException ('Authtokens v1 disabled ' );
325+ }
326+
275327 try {
276328 $ password = $ this ->getPassword ($ token , $ oldTokenId );
277329 $ token ->setPassword ($ this ->encryptPassword ($ password , $ newTokenId ));
@@ -329,6 +381,10 @@ private function decryptPassword(string $password, string $token): string {
329381 }
330382
331383 public function markPasswordInvalid (IToken $ token , string $ tokenId ) {
384+ if ($ this ->config ->getSystemValueBool ('auth.authtoken.v1.disabled ' )) {
385+ throw new InvalidTokenException ('Authtokens v1 disabled ' );
386+ }
387+
332388 if (!($ token instanceof DefaultToken)) {
333389 throw new InvalidTokenException ("Invalid token type " );
334390 }
0 commit comments