Skip to content

Commit 4915eb4

Browse files
committed
fixes bug
1 parent a399467 commit 4915eb4

File tree

6 files changed

+153
-57
lines changed

6 files changed

+153
-57
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [unreleased]
99

10+
## [6.0.7] - 2023-07-28
11+
12+
- Fixes session removing for user with useridmapping when disassociating from tenant.
13+
- Fixes issue with access token migration from version v1 and v2
14+
1015
## [6.0.6] - 2023-07-24
1116

1217
- Adds all ee features enabled for in memory database.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ compileTestJava { options.encoding = "UTF-8" }
1919
// }
2020
//}
2121

22-
version = "6.0.6"
22+
version = "6.0.7"
2323

2424

2525
repositories {

src/main/java/io/supertokens/multitenancy/Multitenancy.java

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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()

src/main/java/io/supertokens/webserver/api/multitenancy/DisassociateUserFromTenant.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,16 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
5959
}
6060

6161
try {
62+
String externalUserId = null;
6263
AppIdentifierWithStorageAndUserIdMapping mappingAndStorage =
6364
getAppIdentifierWithStorageAndUserIdMappingFromRequest(req, userId, UserIdType.ANY);
6465
if (mappingAndStorage.userIdMapping != null) {
6566
userId = mappingAndStorage.userIdMapping.superTokensUserId;
67+
externalUserId = mappingAndStorage.userIdMapping.externalUserId;
6668
}
6769

6870
boolean wasAssociated = Multitenancy.removeUserIdFromTenant(main,
69-
getTenantIdentifierWithStorageFromRequest(req), userId);
71+
getTenantIdentifierWithStorageFromRequest(req), userId, externalUserId);
7072

7173
JsonObject result = new JsonObject();
7274
result.addProperty("status", "OK");

src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@ public void testDeletingAppDeleteNonAuthRecipeData() throws Exception {
116116
new JsonObject()
117117
), false);
118118

119-
TenantIdentifierWithStorage tWithStorage = t.withStorage(StorageLayer.getStorage(t, process.getProcess()));
119+
TenantIdentifierWithStorage tWithStorage = t.withStorage(
120+
StorageLayer.getStorage(t, process.getProcess()));
120121

121122

122-
UserInfo user = EmailPassword.signUp(tWithStorage, process.getProcess(), "[email protected]", "password");
123+
UserInfo user = EmailPassword.signUp(tWithStorage, process.getProcess(), "[email protected]",
124+
"password");
123125
String userId = user.id;
124126

125127
// create entry in nonAuth table
@@ -154,7 +156,8 @@ public void testDeletingAppDeleteNonAuthRecipeData() throws Exception {
154156
new JsonObject()
155157
), false);
156158

157-
UserIdMapping.assertThatUserIdIsNotBeingUsedInNonAuthRecipes(tWithStorage.toAppIdentifierWithStorage(), userId);
159+
UserIdMapping.assertThatUserIdIsNotBeingUsedInNonAuthRecipes(tWithStorage.toAppIdentifierWithStorage(),
160+
userId);
158161
}
159162
}
160163

@@ -237,9 +240,10 @@ public void testDisassociationOfUserDeletesNonAuthRecipeData() throws Exception
237240
}
238241

239242
// Disassociate user
240-
Multitenancy.removeUserIdFromTenant(process.getProcess(), tenantWithStorage, userId);
243+
Multitenancy.removeUserIdFromTenant(process.getProcess(), tenantWithStorage, userId, null);
241244

242-
assertFalse(AuthRecipe.deleteNonAuthRecipeUser(tenantWithStorage, userId)); // Nothing deleted indicates that the non auth recipe user data was deleted already
245+
assertFalse(AuthRecipe.deleteNonAuthRecipeUser(tenantWithStorage,
246+
userId)); // Nothing deleted indicates that the non auth recipe user data was deleted already
243247

244248
AuthRecipe.deleteUser(appWithStorage.toAppIdentifierWithStorage(), userId);
245249
}
@@ -292,7 +296,8 @@ public void deletingTenantKeepsTheUserInTheApp() throws Exception {
292296

293297
Multitenancy.deleteTenant(tenant, process.getProcess());
294298

295-
Multitenancy.addUserIdToTenant(process.getProcess(), appWithStorage, userId); // user id must be intact to do this
299+
Multitenancy.addUserIdToTenant(process.getProcess(), appWithStorage,
300+
userId); // user id must be intact to do this
296301

297302
UserInfo appUser = EmailPassword.getUserUsingId(appWithStorage.toAppIdentifierWithStorage(), userId);
298303

0 commit comments

Comments
 (0)