From b4cdd5a7abe07f5c7b3e96e95d1cfc2937ca3e78 Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Mon, 8 Jul 2024 21:49:15 +0530 Subject: [PATCH] reformats code --- .../inmemorydb/queries/EmailVerificationQueries.java | 4 ++-- .../inmemorydb/queries/MultitenancyQueries.java | 4 ++-- .../io/supertokens/multitenancy/Multitenancy.java | 10 ++++++---- src/main/java/io/supertokens/session/Session.java | 8 +++++--- .../java/io/supertokens/thirdparty/ThirdParty.java | 12 +++++++----- .../io/supertokens/useridmapping/UserIdMapping.java | 2 +- .../api/emailverification/UnverifyEmailAPI.java | 6 +++--- .../api/emailverification/VerifyEmailAPI.java | 10 +++++----- .../api/totp/CreateOrUpdateTotpDeviceAPI.java | 2 +- .../webserver/api/totp/GetTotpDevicesAPI.java | 2 +- .../webserver/api/totp/ImportTotpDeviceAPI.java | 2 +- .../webserver/api/totp/RemoveTotpDeviceAPI.java | 2 +- .../webserver/api/usermetadata/UserMetadataAPI.java | 10 +++++----- .../test/userIdMapping/api/MultitenantAPITest.java | 3 ++- 14 files changed, 42 insertions(+), 35 deletions(-) diff --git a/src/main/java/io/supertokens/inmemorydb/queries/EmailVerificationQueries.java b/src/main/java/io/supertokens/inmemorydb/queries/EmailVerificationQueries.java index 8a6292529..8d5ccc7d8 100644 --- a/src/main/java/io/supertokens/inmemorydb/queries/EmailVerificationQueries.java +++ b/src/main/java/io/supertokens/inmemorydb/queries/EmailVerificationQueries.java @@ -291,8 +291,8 @@ public static List isEmailVerified_transaction(Start start, Connection s HashMap supertokensUserIdToExternalUserIdMap = UserIdMappingQueries.getUserIdMappingWithUserIds_Transaction( - start, - sqlCon, appIdentifier, supertokensUserIds); + start, + sqlCon, appIdentifier, supertokensUserIds); HashMap externalUserIdToSupertokensUserIdMap = new HashMap<>(); List supertokensOrExternalUserIdsToQuery = new ArrayList<>(); diff --git a/src/main/java/io/supertokens/inmemorydb/queries/MultitenancyQueries.java b/src/main/java/io/supertokens/inmemorydb/queries/MultitenancyQueries.java index 488c682a7..1fd491626 100644 --- a/src/main/java/io/supertokens/inmemorydb/queries/MultitenancyQueries.java +++ b/src/main/java/io/supertokens/inmemorydb/queries/MultitenancyQueries.java @@ -239,7 +239,7 @@ public static TenantConfig[] getAllTenants(Start start) throws StorageQueryExcep // Map (tenantIdentifier) -> thirdPartyId -> provider HashMap> providerMap = ThirdPartyProviderSQLHelper.selectAll( - start, providerClientsMap); + start, providerClientsMap); // Map (tenantIdentifier) -> firstFactors HashMap firstFactorsMap = MfaSqlHelper.selectAllFirstFactors(start); @@ -247,7 +247,7 @@ public static TenantConfig[] getAllTenants(Start start) throws StorageQueryExcep // Map (tenantIdentifier) -> requiredSecondaryFactors HashMap requiredSecondaryFactorsMap = MfaSqlHelper.selectAllRequiredSecondaryFactors( - start); + start); return TenantConfigSQLHelper.selectAll(start, providerMap, firstFactorsMap, requiredSecondaryFactorsMap); } catch (SQLException throwables) { diff --git a/src/main/java/io/supertokens/multitenancy/Multitenancy.java b/src/main/java/io/supertokens/multitenancy/Multitenancy.java index ee4a2580e..e6994dd6a 100644 --- a/src/main/java/io/supertokens/multitenancy/Multitenancy.java +++ b/src/main/java/io/supertokens/multitenancy/Multitenancy.java @@ -39,13 +39,15 @@ import io.supertokens.pluginInterface.exceptions.InvalidConfigException; import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException; -import io.supertokens.pluginInterface.multitenancy.*; +import io.supertokens.pluginInterface.multitenancy.AppIdentifier; +import io.supertokens.pluginInterface.multitenancy.MultitenancyStorage; +import io.supertokens.pluginInterface.multitenancy.TenantConfig; +import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.DuplicateClientTypeException; import io.supertokens.pluginInterface.multitenancy.exceptions.DuplicateTenantException; import io.supertokens.pluginInterface.multitenancy.exceptions.DuplicateThirdPartyIdException; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.pluginInterface.multitenancy.sqlStorage.MultitenancySQLStorage; -import io.supertokens.pluginInterface.multitenancy.TenantConfig; import io.supertokens.pluginInterface.passwordless.exception.DuplicatePhoneNumberException; import io.supertokens.pluginInterface.thirdparty.exception.DuplicateThirdPartyUserException; import io.supertokens.storageLayer.StorageLayer; @@ -459,7 +461,7 @@ public static boolean addUserIdToTenant(Main main, TenantIdentifier tenantIdenti for (String phoneNumber : phoneNumbers) { AuthRecipeUserInfo[] usersWithSamePhoneNumber = authRecipeStorage.listPrimaryUsersByPhoneNumber_Transaction( - tenantIdentifier.toAppIdentifier(), con, phoneNumber); + tenantIdentifier.toAppIdentifier(), con, phoneNumber); for (AuthRecipeUserInfo userWithSamePhoneNumber : usersWithSamePhoneNumber) { if (userWithSamePhoneNumber.getSupertokensUserId() .equals(userToAssociate.getSupertokensUserId())) { @@ -489,7 +491,7 @@ public static boolean addUserIdToTenant(Main main, TenantIdentifier tenantIdenti for (LoginMethod.ThirdParty tp : thirdParties) { AuthRecipeUserInfo[] usersWithSameThirdPartyInfo = authRecipeStorage.listPrimaryUsersByThirdPartyInfo_Transaction( - tenantIdentifier.toAppIdentifier(), con, tp.id, tp.userId); + tenantIdentifier.toAppIdentifier(), con, tp.id, tp.userId); for (AuthRecipeUserInfo userWithSameThirdPartyInfo : usersWithSameThirdPartyInfo) { if (userWithSameThirdPartyInfo.getSupertokensUserId() .equals(userToAssociate.getSupertokensUserId())) { diff --git a/src/main/java/io/supertokens/session/Session.java b/src/main/java/io/supertokens/session/Session.java index 980502228..380068a5e 100644 --- a/src/main/java/io/supertokens/session/Session.java +++ b/src/main/java/io/supertokens/session/Session.java @@ -35,7 +35,9 @@ import io.supertokens.pluginInterface.authRecipe.LoginMethod; import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException; -import io.supertokens.pluginInterface.multitenancy.*; +import io.supertokens.pluginInterface.multitenancy.AppIdentifier; +import io.supertokens.pluginInterface.multitenancy.TenantConfig; +import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.pluginInterface.session.SessionStorage; import io.supertokens.pluginInterface.session.noSqlStorage.SessionNoSQLStorage_1; @@ -461,7 +463,7 @@ public static SessionInformationHolder getSession(AppIdentifier appIdentifier, M io.supertokens.pluginInterface.session.noSqlStorage.SessionInfoWithLastUpdated sessionInfo = sessionStorage - .getSessionInfo_Transaction(accessToken.sessionHandle); + .getSessionInfo_Transaction(accessToken.sessionHandle); if (sessionInfo == null) { throw new UnauthorisedException("Session missing in db"); @@ -686,7 +688,7 @@ private static SessionInformationHolder refreshSessionHelper( String sessionHandle = refreshTokenInfo.sessionHandle; io.supertokens.pluginInterface.session.noSqlStorage.SessionInfoWithLastUpdated sessionInfo = sessionStorage - .getSessionInfo_Transaction(sessionHandle); + .getSessionInfo_Transaction(sessionHandle); if (sessionInfo == null || sessionInfo.expiry < System.currentTimeMillis()) { throw new UnauthorisedException("Session missing in db or has expired"); diff --git a/src/main/java/io/supertokens/thirdparty/ThirdParty.java b/src/main/java/io/supertokens/thirdparty/ThirdParty.java index 9a1f3f889..e29b3e44c 100644 --- a/src/main/java/io/supertokens/thirdparty/ThirdParty.java +++ b/src/main/java/io/supertokens/thirdparty/ThirdParty.java @@ -29,9 +29,11 @@ import io.supertokens.pluginInterface.emailverification.sqlStorage.EmailVerificationSQLStorage; import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException; -import io.supertokens.pluginInterface.multitenancy.*; -import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; +import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.multitenancy.TenantConfig; +import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; +import io.supertokens.pluginInterface.multitenancy.ThirdPartyConfig; +import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.pluginInterface.thirdparty.exception.DuplicateThirdPartyUserException; import io.supertokens.pluginInterface.thirdparty.exception.DuplicateUserIdException; import io.supertokens.pluginInterface.thirdparty.sqlStorage.ThirdPartySQLStorage; @@ -271,9 +273,9 @@ private static SignInUpResponse signInUpHelper(TenantIdentifier tenantIdentifier AuthRecipeUserInfo[] usersFromDb1 = authRecipeStorage.listPrimaryUsersByThirdPartyInfo_Transaction( - appIdentifier, - con, - thirdPartyId, thirdPartyUserId); + appIdentifier, + con, + thirdPartyId, thirdPartyUserId); for (AuthRecipeUserInfo user : usersFromDb1) { if (user.tenantIds.contains(tenantIdentifier.getTenantId())) { if (userFromDb1 != null) { diff --git a/src/main/java/io/supertokens/useridmapping/UserIdMapping.java b/src/main/java/io/supertokens/useridmapping/UserIdMapping.java index 36cd1b1bc..5f81c81ee 100644 --- a/src/main/java/io/supertokens/useridmapping/UserIdMapping.java +++ b/src/main/java/io/supertokens/useridmapping/UserIdMapping.java @@ -226,7 +226,7 @@ public static io.supertokens.pluginInterface.useridmapping.UserIdMapping getUser io.supertokens.pluginInterface.useridmapping.UserIdMapping[] userIdMappings = uidMappingStorage.getUserIdMapping_Transaction( - con, appIdentifier, userId); + con, appIdentifier, userId); if (userIdMappings.length == 0) { return null; diff --git a/src/main/java/io/supertokens/webserver/api/emailverification/UnverifyEmailAPI.java b/src/main/java/io/supertokens/webserver/api/emailverification/UnverifyEmailAPI.java index 0e6d85567..0279e4b81 100644 --- a/src/main/java/io/supertokens/webserver/api/emailverification/UnverifyEmailAPI.java +++ b/src/main/java/io/supertokens/webserver/api/emailverification/UnverifyEmailAPI.java @@ -21,12 +21,12 @@ import io.supertokens.StorageAndUserIdMapping; import io.supertokens.emailverification.EmailVerification; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.Storage; import io.supertokens.pluginInterface.emailpassword.exceptions.UnknownUserIdException; +import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; -import io.supertokens.pluginInterface.RECIPE_ID; -import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.useridmapping.UserIdType; import io.supertokens.utils.Utils; import io.supertokens.webserver.InputParser; @@ -63,7 +63,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I try { StorageAndUserIdMapping storageAndUidMapping = enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( - req, userId, UserIdType.ANY, false); + req, userId, UserIdType.ANY, false); storage = storageAndUidMapping.storage; } catch (UnknownUserIdException e) { throw new IllegalStateException("should never happen"); diff --git a/src/main/java/io/supertokens/webserver/api/emailverification/VerifyEmailAPI.java b/src/main/java/io/supertokens/webserver/api/emailverification/VerifyEmailAPI.java index cb758a6a2..bfee307c8 100644 --- a/src/main/java/io/supertokens/webserver/api/emailverification/VerifyEmailAPI.java +++ b/src/main/java/io/supertokens/webserver/api/emailverification/VerifyEmailAPI.java @@ -23,15 +23,15 @@ import io.supertokens.emailverification.User; import io.supertokens.emailverification.exception.EmailVerificationInvalidTokenException; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.output.Logging; +import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.Storage; import io.supertokens.pluginInterface.emailpassword.exceptions.UnknownUserIdException; +import io.supertokens.pluginInterface.exceptions.StorageQueryException; +import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException; import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; -import io.supertokens.output.Logging; -import io.supertokens.pluginInterface.RECIPE_ID; -import io.supertokens.pluginInterface.exceptions.StorageQueryException; -import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException; import io.supertokens.useridmapping.UserIdType; import io.supertokens.utils.Utils; import io.supertokens.webserver.InputParser; @@ -115,7 +115,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws Servl try { StorageAndUserIdMapping storageAndUserIdMapping = enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( - req, userId, UserIdType.ANY, false); + req, userId, UserIdType.ANY, false); storage = storageAndUserIdMapping.storage; } catch (UnknownUserIdException e) { throw new IllegalStateException("should never happen"); diff --git a/src/main/java/io/supertokens/webserver/api/totp/CreateOrUpdateTotpDeviceAPI.java b/src/main/java/io/supertokens/webserver/api/totp/CreateOrUpdateTotpDeviceAPI.java index 5898fb375..6c464ff4c 100644 --- a/src/main/java/io/supertokens/webserver/api/totp/CreateOrUpdateTotpDeviceAPI.java +++ b/src/main/java/io/supertokens/webserver/api/totp/CreateOrUpdateTotpDeviceAPI.java @@ -76,7 +76,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I // Try to find the appIdentifier with right storage based on the userId StorageAndUserIdMapping storageAndUserIdMapping = enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( - req, userId, UserIdType.ANY, false); + req, userId, UserIdType.ANY, false); storage = storageAndUserIdMapping.storage; } catch (UnknownUserIdException e) { throw new IllegalStateException("should never happen"); diff --git a/src/main/java/io/supertokens/webserver/api/totp/GetTotpDevicesAPI.java b/src/main/java/io/supertokens/webserver/api/totp/GetTotpDevicesAPI.java index bb1631abd..b01134685 100644 --- a/src/main/java/io/supertokens/webserver/api/totp/GetTotpDevicesAPI.java +++ b/src/main/java/io/supertokens/webserver/api/totp/GetTotpDevicesAPI.java @@ -55,7 +55,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO // Try to find the appIdentifier with right storage based on the userId StorageAndUserIdMapping storageAndUserIdMapping = enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( - req, userId, UserIdType.ANY, false); + req, userId, UserIdType.ANY, false); storage = storageAndUserIdMapping.storage; } catch (UnknownUserIdException e) { throw new IllegalStateException("should never happen"); diff --git a/src/main/java/io/supertokens/webserver/api/totp/ImportTotpDeviceAPI.java b/src/main/java/io/supertokens/webserver/api/totp/ImportTotpDeviceAPI.java index 17971c571..4c0360165 100644 --- a/src/main/java/io/supertokens/webserver/api/totp/ImportTotpDeviceAPI.java +++ b/src/main/java/io/supertokens/webserver/api/totp/ImportTotpDeviceAPI.java @@ -78,7 +78,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I try { StorageAndUserIdMapping mappingAndStorage = enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( - req, userId, UserIdType.ANY, false); + req, userId, UserIdType.ANY, false); storage = mappingAndStorage.storage; } catch (UnknownUserIdException e) { throw new IllegalStateException("should never happen"); diff --git a/src/main/java/io/supertokens/webserver/api/totp/RemoveTotpDeviceAPI.java b/src/main/java/io/supertokens/webserver/api/totp/RemoveTotpDeviceAPI.java index 3f5943f97..6a8ad488a 100644 --- a/src/main/java/io/supertokens/webserver/api/totp/RemoveTotpDeviceAPI.java +++ b/src/main/java/io/supertokens/webserver/api/totp/RemoveTotpDeviceAPI.java @@ -61,7 +61,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I // Try to find the appIdentifier with right storage based on the userId StorageAndUserIdMapping storageAndUserIdMapping = enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( - req, userId, UserIdType.ANY, false); + req, userId, UserIdType.ANY, false); storage = storageAndUserIdMapping.storage; } catch (UnknownUserIdException e) { throw new IllegalStateException("should never happen"); diff --git a/src/main/java/io/supertokens/webserver/api/usermetadata/UserMetadataAPI.java b/src/main/java/io/supertokens/webserver/api/usermetadata/UserMetadataAPI.java index 6417a2152..f7cc949e7 100644 --- a/src/main/java/io/supertokens/webserver/api/usermetadata/UserMetadataAPI.java +++ b/src/main/java/io/supertokens/webserver/api/usermetadata/UserMetadataAPI.java @@ -20,12 +20,12 @@ import io.supertokens.Main; import io.supertokens.StorageAndUserIdMapping; import io.supertokens.multitenancy.exception.BadPermissionException; -import io.supertokens.pluginInterface.emailpassword.exceptions.UnknownUserIdException; -import io.supertokens.pluginInterface.multitenancy.AppIdentifier; -import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.pluginInterface.RECIPE_ID; +import io.supertokens.pluginInterface.emailpassword.exceptions.UnknownUserIdException; import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException; +import io.supertokens.pluginInterface.multitenancy.AppIdentifier; +import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.useridmapping.UserIdType; import io.supertokens.usermetadata.UserMetadata; import io.supertokens.webserver.InputParser; @@ -59,7 +59,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO try { StorageAndUserIdMapping storageAndUserIdMapping = this.enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( - req, userId, UserIdType.ANY, false); + req, userId, UserIdType.ANY, false); metadata = UserMetadata.getUserMetadata(appIdentifier, storageAndUserIdMapping.storage, userId); } catch (UnknownUserIdException e) { throw new IllegalStateException("should never happen"); @@ -88,7 +88,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO try { StorageAndUserIdMapping storageAndUserIdMapping = this.enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( - req, userId, UserIdType.ANY, false); + req, userId, UserIdType.ANY, false); metadata = UserMetadata.updateUserMetadata(appIdentifier, storageAndUserIdMapping.storage, userId, update); } catch (UnknownUserIdException e) { diff --git a/src/test/java/io/supertokens/test/userIdMapping/api/MultitenantAPITest.java b/src/test/java/io/supertokens/test/userIdMapping/api/MultitenantAPITest.java index 0b57e6f3c..a399d1227 100644 --- a/src/test/java/io/supertokens/test/userIdMapping/api/MultitenantAPITest.java +++ b/src/test/java/io/supertokens/test/userIdMapping/api/MultitenantAPITest.java @@ -503,7 +503,8 @@ public void testUserIdFromDifferentAppIsAllowedForUserIdMapping() throws Excepti } catch (HttpResponseException e) { assertEquals(400, e.statusCode); assertEquals( - "Http error. Status Code: 400. Message: Cannot create a userId mapping where the externalId is also a SuperTokens userID", + "Http error. Status Code: 400. Message: Cannot create a userId mapping where the externalId is " + + "also a SuperTokens userID", e.getMessage()); } }