Avoid reading from a stale `Account` after a contested reglock event
This commit is contained in:
		
							parent
							
								
									d3f0ab8c6d
								
							
						
					
					
						commit
						2c9c50711f
					
				| 
						 | 
					@ -808,20 +808,22 @@ public class AccountController {
 | 
				
			||||||
        rateLimiters.getPinLimiter().validate(existingAccount.getNumber());
 | 
					        rateLimiters.getPinLimiter().validate(existingAccount.getNumber());
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      final String phoneNumber = existingAccount.getNumber();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (!existingRegistrationLock.verify(clientRegistrationLock)) {
 | 
					      if (!existingRegistrationLock.verify(clientRegistrationLock)) {
 | 
				
			||||||
        // At this point, the client verified ownership of the phone number but doesn’t have the reglock PIN.
 | 
					        // At this point, the client verified ownership of the phone number but doesn’t have the reglock PIN.
 | 
				
			||||||
        // Freezing the existing account credentials will definitively start the reglock timeout. Until the timeout, the current reglock can still be supplied,
 | 
					        // Freezing the existing account credentials will definitively start the reglock timeout. Until the timeout, the current reglock can still be supplied,
 | 
				
			||||||
        // along with phone number verification, to restore access.
 | 
					        // along with phone number verification, to restore access.
 | 
				
			||||||
        accounts.update(existingAccount, Account::lockAuthenticationCredentials);
 | 
					        final Account updatedAccount = accounts.update(existingAccount, Account::lockAuthenticationCredentials);
 | 
				
			||||||
        List<Long> deviceIds = existingAccount.getDevices().stream().map(Device::getId).toList();
 | 
					        List<Long> deviceIds = updatedAccount.getDevices().stream().map(Device::getId).toList();
 | 
				
			||||||
        clientPresenceManager.disconnectAllPresences(existingAccount.getUuid(), deviceIds);
 | 
					        clientPresenceManager.disconnectAllPresences(updatedAccount.getUuid(), deviceIds);
 | 
				
			||||||
        throw new WebApplicationException(Response.status(423)
 | 
					        throw new WebApplicationException(Response.status(423)
 | 
				
			||||||
            .entity(new RegistrationLockFailure(existingRegistrationLock.getTimeRemaining(),
 | 
					            .entity(new RegistrationLockFailure(existingRegistrationLock.getTimeRemaining(),
 | 
				
			||||||
                existingRegistrationLock.needsFailureCredentials() ? existingBackupCredentials : null))
 | 
					                existingRegistrationLock.needsFailureCredentials() ? existingBackupCredentials : null))
 | 
				
			||||||
            .build());
 | 
					            .build());
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      rateLimiters.getPinLimiter().clear(existingAccount.getNumber());
 | 
					      rateLimiters.getPinLimiter().clear(phoneNumber);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue