@@ -62,8 +62,8 @@ public class Multitenancy extends ResourceDistributor.SingletonResource {
6262 public static void checkPermissionsForCreateOrUpdate (Main main , TenantIdentifier sourceTenant ,
6363 TenantIdentifier targetTenant )
6464 throws BadPermissionException , CannotModifyBaseConfigException , FeatureNotEnabledException ,
65- TenantOrAppNotFoundException , StorageQueryException , InvalidConfigException , InvalidProviderConfigException
66- {
65+ TenantOrAppNotFoundException , StorageQueryException , InvalidConfigException ,
66+ InvalidProviderConfigException {
6767
6868 {
6969 if (!targetTenant .equals (new TenantIdentifier (null , null , null ))) {
@@ -91,38 +91,43 @@ public static void checkPermissionsForCreateOrUpdate(Main main, TenantIdentifier
9191 // this means that we are creating a new app for this connectionuridomain and must use the public or
9292 // same app and public tenant for this
9393 if (!sourceTenant .getTenantId ().equals (TenantIdentifier .DEFAULT_TENANT_ID )
94- || (!sourceTenant .getAppId ().equals (TenantIdentifier .DEFAULT_APP_ID ) && !sourceTenant .getAppId ().equals (targetTenant .getAppId ()))) {
94+ || (!sourceTenant .getAppId ().equals (TenantIdentifier .DEFAULT_APP_ID ) &&
95+ !sourceTenant .getAppId ().equals (targetTenant .getAppId ()))) {
9596 throw new BadPermissionException (
9697 "You must use the public or same app to add/update an app" );
9798 }
9899 if (!sourceTenant .getConnectionUriDomain ()
99100 .equals (targetTenant .getConnectionUriDomain ())) {
100- throw new BadPermissionException ("You must use the same connection URI domain to create/update an app" );
101+ throw new BadPermissionException (
102+ "You must use the same connection URI domain to create/update an app" );
101103 }
102104 } else if (!targetTenant .getConnectionUriDomain ()
103105 .equals (TenantIdentifier .DEFAULT_CONNECTION_URI )) {
104106 // this means that we are creating a new connectionuridomain, and must use the base tenant for this
105107 if (!sourceTenant .equals (new TenantIdentifier (null , null , null ))
106108 && !sourceTenant .getConnectionUriDomain ().equals (targetTenant .getConnectionUriDomain ())) {
107109 throw new BadPermissionException (
108- "You must use the default or same connectionUriDomain to create/update a connectionUriDomain" );
110+ "You must use the default or same connectionUriDomain to create/update a " +
111+ "connectionUriDomain" );
109112 }
110113 }
111114 }
112115 }
113116
114- private static void validateConfigJsonForInvalidKeys (Main main , JsonObject coreConfig ) throws InvalidConfigException {
117+ private static void validateConfigJsonForInvalidKeys (Main main , JsonObject coreConfig )
118+ throws InvalidConfigException {
115119 Set <String > coreFields = CoreConfig .getValidFields ();
116120 Set <String > storageFields = StorageLayer .getBaseStorage (main ).getValidFieldsInConfig ();
117121
118- for (Map .Entry <String , JsonElement > entry : coreConfig .entrySet ()) {
122+ for (Map .Entry <String , JsonElement > entry : coreConfig .entrySet ()) {
119123 if (!coreFields .contains (entry .getKey ()) && !storageFields .contains (entry .getKey ())) {
120124 throw new InvalidConfigException ("Invalid config key: " + entry .getKey ());
121125 }
122126 }
123127 }
124128
125- private static void validateTenantConfig (Main main , TenantConfig targetTenantConfig , boolean shouldPreventProtecterdConfigUpdate ,
129+ private static void validateTenantConfig (Main main , TenantConfig targetTenantConfig ,
130+ boolean shouldPreventProtecterdConfigUpdate ,
126131 boolean skipThirdPartyConfigValidation )
127132 throws IOException , InvalidConfigException , InvalidProviderConfigException , BadPermissionException ,
128133 TenantOrAppNotFoundException , CannotModifyBaseConfigException {
@@ -149,13 +154,15 @@ private static void validateTenantConfig(Main main, TenantConfig targetTenantCon
149154
150155 for (String s : StorageLayer .getStorage (new TenantIdentifier (null , null , null ), main )
151156 .getProtectedConfigsFromSuperTokensSaaSUsers ()) {
152- if (targetTenantConfig .coreConfig .has (s ) && !targetTenantConfig .coreConfig .get (s ).equals (currentConfig .get (s ))) {
157+ if (targetTenantConfig .coreConfig .has (s ) &&
158+ !targetTenantConfig .coreConfig .get (s ).equals (currentConfig .get (s ))) {
153159 throw new BadPermissionException ("Not allowed to modify DB related configs." );
154160 }
155161 }
156162
157163 for (String s : CoreConfig .PROTECTED_CONFIGS ) {
158- if (targetTenantConfig .coreConfig .has (s ) && !targetTenantConfig .coreConfig .get (s ).equals (currentConfig .get (s ))) {
164+ if (targetTenantConfig .coreConfig .has (s ) &&
165+ !targetTenantConfig .coreConfig .get (s ).equals (currentConfig .get (s ))) {
159166 throw new BadPermissionException ("Not allowed to modify protected configs." );
160167 }
161168 }
@@ -200,14 +207,17 @@ public static boolean addNewOrUpdateAppOrTenant(Main main, TenantIdentifier sour
200207 return addNewOrUpdateAppOrTenant (main , newTenant , false );
201208 }
202209
203- public static boolean addNewOrUpdateAppOrTenant (Main main , TenantConfig newTenant , boolean shouldPreventDbConfigUpdate )
210+ public static boolean addNewOrUpdateAppOrTenant (Main main , TenantConfig newTenant ,
211+ boolean shouldPreventDbConfigUpdate )
204212 throws CannotModifyBaseConfigException , BadPermissionException ,
205213 StorageQueryException , FeatureNotEnabledException , IOException , InvalidConfigException ,
206214 InvalidProviderConfigException , TenantOrAppNotFoundException {
207215 return addNewOrUpdateAppOrTenant (main , newTenant , shouldPreventDbConfigUpdate , false );
208216 }
209217
210- public static boolean addNewOrUpdateAppOrTenant (Main main , TenantConfig newTenant , boolean shouldPreventProtectedConfigUpdate , boolean skipThirdPartyConfigValidation )
218+ public static boolean addNewOrUpdateAppOrTenant (Main main , TenantConfig newTenant ,
219+ boolean shouldPreventProtectedConfigUpdate ,
220+ boolean skipThirdPartyConfigValidation )
211221 throws CannotModifyBaseConfigException , BadPermissionException ,
212222 StorageQueryException , FeatureNotEnabledException , IOException , InvalidConfigException ,
213223 InvalidProviderConfigException , TenantOrAppNotFoundException {
@@ -237,7 +247,8 @@ public static boolean addNewOrUpdateAppOrTenant(Main main, TenantConfig newTenan
237247 // the tenant being there in the tenants table. But that insertion is done in the addTenantIdInUserPool
238248 // function below. So in order to actually refresh the resources, we have a finally block here which
239249 // calls the forceReloadAllResources function.
240- tenantsThatChanged = MultitenancyHelper .getInstance (main ).refreshTenantsInCoreBasedOnChangesInCoreConfigOrIfTenantListChanged (false );
250+ tenantsThatChanged = MultitenancyHelper .getInstance (main )
251+ .refreshTenantsInCoreBasedOnChangesInCoreConfigOrIfTenantListChanged (false );
241252 try {
242253 ((MultitenancyStorage ) StorageLayer .getStorage (newTenant .tenantIdentifier , main ))
243254 .addTenantIdInTargetStorage (newTenant .tenantIdentifier );
@@ -250,7 +261,8 @@ public static boolean addNewOrUpdateAppOrTenant(Main main, TenantConfig newTenan
250261 if (!creationInSharedDbSucceeded ) {
251262 try {
252263 StorageLayer .getMultitenancyStorage (main ).overwriteTenantConfig (newTenant );
253- tenantsThatChanged = MultitenancyHelper .getInstance (main ).refreshTenantsInCoreBasedOnChangesInCoreConfigOrIfTenantListChanged (false );
264+ tenantsThatChanged = MultitenancyHelper .getInstance (main )
265+ .refreshTenantsInCoreBasedOnChangesInCoreConfigOrIfTenantListChanged (false );
254266
255267 // we do this extra step cause if previously an attempt to add a tenant failed midway,
256268 // such that the main tenant was added in the user pool, but did not get created
@@ -357,12 +369,14 @@ public static boolean deleteConnectionUriDomain(String connectionUriDomain, Main
357369 // we ignore this since it may have been that past deletion attempt deleted this successfully,
358370 // but not from the main table.
359371 }
360- boolean didExist = StorageLayer .getMultitenancyStorage (main ).deleteConnectionUriDomainInfoInBaseStorage (connectionUriDomain );
372+ boolean didExist = StorageLayer .getMultitenancyStorage (main )
373+ .deleteConnectionUriDomainInfoInBaseStorage (connectionUriDomain );
361374 MultitenancyHelper .getInstance (main ).refreshTenantsInCoreBasedOnChangesInCoreConfigOrIfTenantListChanged (true );
362375 return didExist ;
363376 }
364377
365- public static boolean addUserIdToTenant (Main main , TenantIdentifierWithStorage tenantIdentifierWithStorage , String userId )
378+ public static boolean addUserIdToTenant (Main main , TenantIdentifierWithStorage tenantIdentifierWithStorage ,
379+ String userId )
366380 throws TenantOrAppNotFoundException , UnknownUserIdException , StorageQueryException ,
367381 FeatureNotEnabledException , DuplicateEmailException , DuplicatePhoneNumberException ,
368382 DuplicateThirdPartyUserException {
@@ -375,7 +389,8 @@ public static boolean addUserIdToTenant(Main main, TenantIdentifierWithStorage t
375389 .addUserIdToTenant (tenantIdentifierWithStorage , userId );
376390 }
377391
378- public static boolean removeUserIdFromTenant (Main main , TenantIdentifierWithStorage tenantIdentifierWithStorage , String userId )
392+ public static boolean removeUserIdFromTenant (Main main , TenantIdentifierWithStorage tenantIdentifierWithStorage ,
393+ String userId , String externalUserId )
379394 throws FeatureNotEnabledException , TenantOrAppNotFoundException , StorageQueryException ,
380395 UnknownUserIdException {
381396 if (Arrays .stream (FeatureFlag .getInstance (main , new AppIdentifier (null , null )).getEnabledFeatures ())
@@ -384,7 +399,8 @@ public static boolean removeUserIdFromTenant(Main main, TenantIdentifierWithStor
384399 }
385400
386401 boolean finalDidExist = false ;
387- boolean didExist = AuthRecipe .deleteNonAuthRecipeUser (tenantIdentifierWithStorage , userId );
402+ boolean didExist = AuthRecipe .deleteNonAuthRecipeUser (tenantIdentifierWithStorage ,
403+ externalUserId == null ? userId : externalUserId );
388404 finalDidExist = finalDidExist || didExist ;
389405
390406 didExist = tenantIdentifierWithStorage .getMultitenancyStorageWithTargetStorage ()
0 commit comments