@@ -1595,20 +1595,19 @@ public UserAccount createUserAccount(final String userName, final String passwor
15951595 }
15961596
15971597 final Long domainIdFinal = domainId ;
1598- final String accountUUIDFinal = accountUUID ;
1598+ final String resolvedAccountUUID = accountUUID != null ? accountUUID : UUID .randomUUID ().toString ();
1599+
1600+ // Check role escalation before the transaction — this is a read-only check
1601+ // that iterates all API commands and doesn't need a write transaction open.
1602+ AccountVO requestedAccount = new AccountVO (accountNameFinal , domainIdFinal , networkDomain , accountType , roleId , resolvedAccountUUID );
1603+ checkRoleEscalation (getCurrentCallingAccount (), requestedAccount );
1604+
15991605 Pair <Long , Account > pair = Transaction .execute (new TransactionCallback <>() {
16001606 @ Override
16011607 public Pair <Long , Account > doInTransaction (TransactionStatus status ) {
1602- // create account
1603- String accountUUID = accountUUIDFinal ;
1604- if (accountUUID == null ) {
1605- accountUUID = UUID .randomUUID ().toString ();
1606- }
1607- AccountVO account = createAccount (accountNameFinal , accountType , roleId , domainIdFinal , networkDomain , details , accountUUID );
1608+ AccountVO account = createAccount (accountNameFinal , accountType , roleId , domainIdFinal , networkDomain , details , resolvedAccountUUID );
16081609 long accountId = account .getId ();
16091610
1610- checkRoleEscalation (getCurrentCallingAccount (), account );
1611-
16121611 // create the first user for the account
16131612 UserVO user = createUser (accountId , userName , password , firstName , lastName , email , timezone , userUUID , source );
16141613
0 commit comments