3434use  OC \Authentication \Exceptions \TokenPasswordExpiredException ;
3535use  OC \Authentication \Exceptions \PasswordlessTokenException ;
3636use  OC \Authentication \Exceptions \WipeTokenException ;
37+ use  OCP \AppFramework \Db \TTransactional ;
3738use  OCP \Cache \CappedMemoryCache ;
3839use  OCP \AppFramework \Db \DoesNotExistException ;
3940use  OCP \AppFramework \Utility \ITimeFactory ;
4041use  OCP \IConfig ;
42+ use  OCP \IDBConnection ;
4143use  OCP \Security \ICrypto ;
4244use  Psr \Log \LoggerInterface ;
4345
4446class  PublicKeyTokenProvider implements  IProvider {
47+ 	use  TTransactional;
48+ 
4549	/** @var PublicKeyTokenMapper */ 
4650	private  $ mapper
4751
@@ -51,6 +55,8 @@ class PublicKeyTokenProvider implements IProvider {
5155	/** @var IConfig */ 
5256	private  $ config
5357
58+ 	private  IDBConnection $ db
59+ 
5460	/** @var LoggerInterface */ 
5561	private  $ logger
5662
@@ -63,11 +69,13 @@ class PublicKeyTokenProvider implements IProvider {
6369	public  function  __construct (PublicKeyTokenMapper $ mapper
6470								ICrypto $ crypto
6571								IConfig $ config
72+ 								IDBConnection $ db
6673								LoggerInterface $ logger
6774								ITimeFactory $ time
6875		$ this mapper  = $ mapper
6976		$ this crypto  = $ crypto
7077		$ this config  = $ config
78+ 		$ this db  = $ db
7179		$ this logger  = $ logger
7280		$ this time  = $ time
7381
@@ -164,31 +172,32 @@ public function getTokenById(int $tokenId): IToken {
164172	public  function  renewSessionToken (string  $ oldSessionIdstring  $ sessionIdIToken 
165173		$ this cache ->clear ();
166174
167- 		$ token$ this getToken ($ oldSessionId
168- 
169- 		if  (!($ tokeninstanceof  PublicKeyToken)) {
170- 			throw  new  InvalidTokenException ("Invalid token type " );
171- 		}
175+ 		return  $ this atomic (function  () use  ($ oldSessionId$ sessionId
176+ 			$ token$ this getToken ($ oldSessionId
172177
173- 		$ passwordnull ;
174- 		if  (!is_null ($ tokengetPassword ())) {
175- 			$ privateKey$ this decrypt ($ tokengetPrivateKey (), $ oldSessionId
176- 			$ password$ this decryptPassword ($ tokengetPassword (), $ privateKey
177- 		}
178- 
179- 		$ newToken$ this generateToken (
180- 			$ sessionId
181- 			$ tokengetUID (),
182- 			$ tokengetLoginName (),
183- 			$ password
184- 			$ tokengetName (),
185- 			IToken::TEMPORARY_TOKEN ,
186- 			$ tokengetRemember ()
187- 		);
188- 
189- 		$ this mapper ->delete ($ token
178+ 			if  (!($ tokeninstanceof  PublicKeyToken)) {
179+ 				throw  new  InvalidTokenException ("Invalid token type " );
180+ 			}
190181
191- 		return  $ newToken
182+ 			$ passwordnull ;
183+ 			if  (!is_null ($ tokengetPassword ())) {
184+ 				$ privateKey$ this decrypt ($ tokengetPrivateKey (), $ oldSessionId
185+ 				$ password$ this decryptPassword ($ tokengetPassword (), $ privateKey
186+ 			}
187+ 			$ newToken$ this generateToken (
188+ 				$ sessionId
189+ 				$ tokengetUID (),
190+ 				$ tokengetLoginName (),
191+ 				$ password
192+ 				$ tokengetName (),
193+ 				IToken::TEMPORARY_TOKEN ,
194+ 				$ tokengetRemember ()
195+ 			);
196+ 
197+ 			$ this mapper ->delete ($ token
198+ 
199+ 			return  $ newToken
200+ 		}, $ this db );
192201	}
193202
194203	public  function  invalidateToken (string  $ token
0 commit comments