|
31 | 31 | import io.supertokens.pluginInterface.emailpassword.exceptions.DuplicateUserIdException; |
32 | 32 | import io.supertokens.pluginInterface.emailpassword.exceptions.UnknownUserIdException; |
33 | 33 | import io.supertokens.pluginInterface.emailpassword.sqlStorage.EmailPasswordSQLStorage; |
| 34 | +import io.supertokens.pluginInterface.emailverification.EmailVerificationStorage; |
34 | 35 | import io.supertokens.pluginInterface.emailverification.EmailVerificationTokenInfo; |
35 | 36 | import io.supertokens.pluginInterface.emailverification.exception.DuplicateEmailVerificationTokenException; |
36 | 37 | import io.supertokens.pluginInterface.emailverification.sqlStorage.EmailVerificationSQLStorage; |
37 | 38 | import io.supertokens.pluginInterface.exceptions.QuitProgramFromPluginException; |
38 | 39 | import io.supertokens.pluginInterface.exceptions.StorageQueryException; |
39 | 40 | import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException; |
| 41 | +import io.supertokens.pluginInterface.jwt.JWTRecipeStorage; |
40 | 42 | import io.supertokens.pluginInterface.jwt.JWTSigningKeyInfo; |
41 | 43 | import io.supertokens.pluginInterface.jwt.exceptions.DuplicateKeyIdException; |
42 | 44 | import io.supertokens.pluginInterface.jwt.sqlstorage.JWTRecipeSQLStorage; |
|
45 | 47 | import io.supertokens.pluginInterface.passwordless.exception.*; |
46 | 48 | import io.supertokens.pluginInterface.passwordless.sqlStorage.PasswordlessSQLStorage; |
47 | 49 | import io.supertokens.pluginInterface.session.SessionInfo; |
| 50 | +import io.supertokens.pluginInterface.session.SessionStorage; |
48 | 51 | import io.supertokens.pluginInterface.session.sqlStorage.SessionSQLStorage; |
49 | 52 | import io.supertokens.pluginInterface.sqlStorage.TransactionConnection; |
50 | 53 | import io.supertokens.pluginInterface.thirdparty.exception.DuplicateThirdPartyUserException; |
|
53 | 56 | import io.supertokens.pluginInterface.useridmapping.UserIdMappingStorage; |
54 | 57 | import io.supertokens.pluginInterface.useridmapping.exception.UnknownSuperTokensUserIdException; |
55 | 58 | import io.supertokens.pluginInterface.useridmapping.exception.UserIdMappingAlreadyExistsException; |
| 59 | +import io.supertokens.pluginInterface.usermetadata.UserMetadataStorage; |
56 | 60 | import io.supertokens.pluginInterface.usermetadata.sqlStorage.UserMetadataSQLStorage; |
| 61 | +import io.supertokens.pluginInterface.userroles.UserRolesStorage; |
57 | 62 | import io.supertokens.pluginInterface.userroles.exception.DuplicateUserRoleMappingException; |
58 | 63 | import io.supertokens.pluginInterface.userroles.exception.UnknownRoleException; |
59 | 64 | import io.supertokens.pluginInterface.userroles.sqlStorage.UserRolesSQLStorage; |
|
72 | 77 | import java.sql.Connection; |
73 | 78 | import java.sql.SQLException; |
74 | 79 | import java.sql.SQLTransactionRollbackException; |
| 80 | +import java.util.ArrayList; |
| 81 | +import java.util.HashMap; |
75 | 82 | import java.util.List; |
76 | 83 |
|
77 | 84 | public class Start |
@@ -540,6 +547,84 @@ public boolean canBeUsed(String configFilePath) { |
540 | 547 | return Config.canBeUsed(configFilePath); |
541 | 548 | } |
542 | 549 |
|
| 550 | + @Override |
| 551 | + public boolean isUserIdBeingUsedInNonAuthRecipe(String className, String userId) throws StorageQueryException { |
| 552 | + // check if the input userId is being used in nonAuthRecipes. |
| 553 | + if (className.equals(SessionStorage.class.getName())) { |
| 554 | + String[] sessionHandlesForUser = getAllNonExpiredSessionHandlesForUser(userId); |
| 555 | + return sessionHandlesForUser.length > 0; |
| 556 | + } else if (className.equals(UserRolesStorage.class.getName())) { |
| 557 | + String[] roles = getRolesForUser(userId); |
| 558 | + return roles.length > 0; |
| 559 | + } else if (className.equals(UserMetadataStorage.class.getName())) { |
| 560 | + JsonObject userMetadata = getUserMetadata(userId); |
| 561 | + return userMetadata != null; |
| 562 | + } else if (className.equals(EmailVerificationStorage.class.getName())) { |
| 563 | + try { |
| 564 | + return EmailVerificationQueries.isUserIdBeingUsedForEmailVerification(this, userId); |
| 565 | + } catch (SQLException e) { |
| 566 | + throw new StorageQueryException(e); |
| 567 | + } |
| 568 | + } else if (className.equals(JWTRecipeStorage.class.getName())) { |
| 569 | + return false; |
| 570 | + } else { |
| 571 | + throw new IllegalStateException("ClassName: " + className + " is not part of NonAuthRecipeStorage"); |
| 572 | + } |
| 573 | + } |
| 574 | + |
| 575 | + @TestOnly |
| 576 | + @Override |
| 577 | + public void addInfoToNonAuthRecipesBasedOnUserId(String className, String userId) throws StorageQueryException { |
| 578 | + // add entries to nonAuthRecipe tables with input userId |
| 579 | + if (className.equals(SessionStorage.class.getName())) { |
| 580 | + try { |
| 581 | + createNewSession("sessionHandle", userId, "refreshTokenHash", new JsonObject(), |
| 582 | + System.currentTimeMillis() + 1000000, new JsonObject(), System.currentTimeMillis()); |
| 583 | + } catch (Exception e) { |
| 584 | + throw new StorageQueryException(e); |
| 585 | + } |
| 586 | + } else if (className.equals(UserRolesStorage.class.getName())) { |
| 587 | + try { |
| 588 | + String role = "testRole"; |
| 589 | + this.startTransaction(con -> { |
| 590 | + createNewRoleOrDoNothingIfExists_Transaction(con, role); |
| 591 | + return null; |
| 592 | + }); |
| 593 | + try { |
| 594 | + addRoleToUser(userId, role); |
| 595 | + } catch (Exception e) { |
| 596 | + throw new StorageTransactionLogicException(e); |
| 597 | + } |
| 598 | + } catch (StorageTransactionLogicException e) { |
| 599 | + throw new StorageQueryException(e.actualException); |
| 600 | + } |
| 601 | + } else if (className.equals(EmailVerificationStorage.class.getName())) { |
| 602 | + try { |
| 603 | + EmailVerificationTokenInfo info = new EmailVerificationTokenInfo(userId, "someToken", 10000, |
| 604 | + |
| 605 | + addEmailVerificationToken(info); |
| 606 | + |
| 607 | + } catch (DuplicateEmailVerificationTokenException e) { |
| 608 | + throw new StorageQueryException(e); |
| 609 | + } |
| 610 | + } else if (className.equals(UserMetadataStorage.class.getName())) { |
| 611 | + JsonObject data = new JsonObject(); |
| 612 | + data.addProperty("test", "testData"); |
| 613 | + try { |
| 614 | + this.startTransaction(con -> { |
| 615 | + setUserMetadata_Transaction(con, userId, data); |
| 616 | + return null; |
| 617 | + }); |
| 618 | + } catch (StorageTransactionLogicException e) { |
| 619 | + throw new StorageQueryException(e); |
| 620 | + } |
| 621 | + } else if (className.equals(JWTRecipeStorage.class.getName())) { |
| 622 | + /* Since JWT recipe tables do not store userId we do not add any data to them */ |
| 623 | + } else { |
| 624 | + throw new IllegalStateException("ClassName: " + className + " is not part of NonAuthRecipeStorage"); |
| 625 | + } |
| 626 | + } |
| 627 | + |
543 | 628 | @Override |
544 | 629 | public void signUp(UserInfo userInfo) |
545 | 630 | throws StorageQueryException, DuplicateUserIdException, DuplicateEmailException { |
@@ -1717,4 +1802,14 @@ public boolean updateOrDeleteExternalUserIdInfo(String userId, boolean isSuperTo |
1717 | 1802 | throw new StorageQueryException(e); |
1718 | 1803 | } |
1719 | 1804 | } |
| 1805 | + |
| 1806 | + @Override |
| 1807 | + public HashMap<String, String> getUserIdMappingForSuperTokensIds(ArrayList<String> userIds) |
| 1808 | + throws StorageQueryException { |
| 1809 | + try { |
| 1810 | + return UserIdMappingQueries.getUserIdMappingWithUserIds(this, userIds); |
| 1811 | + } catch (SQLException e) { |
| 1812 | + throw new StorageQueryException(e); |
| 1813 | + } |
| 1814 | + } |
1720 | 1815 | } |
0 commit comments