Skip to content

Commit 59bfe96

Browse files
authored
fix: get user by accountinfo tenant (#262)
* fix: remove unnecessary dependency * fix: getUserByAccountInfo fix to consider tenantId instead of appId * fix: review fix: remove onemillionusers test
1 parent 4e6ef41 commit 59bfe96

File tree

6 files changed

+42
-1236
lines changed

6 files changed

+42
-1236
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+
## [9.0.2]
11+
12+
- Fixes `AuthRecipe#getUserByAccountInfo` to consider the tenantId instead of the appId when fetching the webauthn user
13+
- Changes dependency structure to avoid multiple dependency declarations for the same library
14+
1015
## [9.0.1]
1116

1217
- Upgrades the embedded tomcat 11.0.6 and logback classic to 1.5.13 because of security vulnerabilities

build.gradle

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
id 'java-library'
33
}
44

5-
version = "9.0.1"
5+
version = "9.0.2"
66

77
repositories {
88
mavenCentral()
@@ -19,14 +19,11 @@ dependencies {
1919
// https://mvnrepository.com/artifact/org.postgresql/postgresql
2020
implementation group: 'org.postgresql', name: 'postgresql', version: '42.7.2'
2121

22-
// https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-core
23-
implementation group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '11.0.6'
24-
2522
// https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml
26-
compileOnly group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.16.1'
23+
compileOnly group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.18.2'
2724

2825
// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
29-
compileOnly group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.16.1'
26+
compileOnly group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.18.2'
3027

3128
// https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
3229
compileOnly group: 'ch.qos.logback', name: 'logback-classic', version: '1.5.13'

src/main/java/io/supertokens/storage/postgresql/Start.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ public <T> T startTransaction(TransactionLogic<T> logic, TransactionIsolationLev
329329
// PSQL error class 40 is transaction rollback. See:
330330
// https://www.postgresql.org/docs/12/errcodes-appendix.html
331331
boolean isPSQLRollbackException = psqlException != null
332+
&& psqlException.getServerErrorMessage() != null
332333
&& psqlException.getServerErrorMessage().getSQLState().startsWith("40");
333334

334335
// We keep the old exception detection logic to ensure backwards compatibility.

src/main/java/io/supertokens/storage/postgresql/queries/GeneralQueries.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,8 @@ public static AuthRecipeUserInfo[] listPrimaryUsersByEmail_Transaction(Start sta
15431543

15441544
userIds.addAll(ThirdPartyQueries.getPrimaryUserIdUsingEmail_Transaction(start, sqlCon, appIdentifier, email));
15451545

1546-
String webauthnUserId = WebAuthNQueries.getPrimaryUserIdUsingEmail_Transaction(start, sqlCon, appIdentifier, email);
1546+
String webauthnUserId = WebAuthNQueries.getPrimaryUserIdForAppUsingEmail_Transaction(start, sqlCon,
1547+
appIdentifier, email);
15471548
if(webauthnUserId != null) {
15481549
userIds.add(webauthnUserId);
15491550
}
@@ -1608,7 +1609,7 @@ public static AuthRecipeUserInfo[] listPrimaryUsersByEmail(Start start, TenantId
16081609

16091610
userIds.addAll(ThirdPartyQueries.getPrimaryUserIdUsingEmail(start, tenantIdentifier, email));
16101611

1611-
String webauthnUserId = WebAuthNQueries.getPrimaryUserIdUsingEmail(start, tenantIdentifier.toAppIdentifier(), email);
1612+
String webauthnUserId = WebAuthNQueries.getPrimaryUserIdUsingEmail(start, tenantIdentifier, email);
16121613
if(webauthnUserId != null) {
16131614
userIds.add(webauthnUserId);
16141615
}

src/main/java/io/supertokens/storage/postgresql/queries/WebAuthNQueries.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,13 +392,14 @@ private static AuthRecipeUserInfo getAuthRecipeUserInfo(Start start, Connection
392392
return userInfo;
393393
}
394394

395-
public static String getPrimaryUserIdUsingEmail(Start start, AppIdentifier appIdentifier, String email)
395+
public static String getPrimaryUserIdUsingEmail(Start start, TenantIdentifier tenantIdentifier, String email)
396396
throws StorageQueryException {
397397
try {
398398
return start.startTransaction(con -> {
399399
try {
400400
Connection sqlConnection = (Connection) con.getConnection();
401-
return getPrimaryUserIdUsingEmail_Transaction(start, sqlConnection, appIdentifier, email);
401+
return getPrimaryUserIdForTenantUsingEmail_Transaction(start, sqlConnection, tenantIdentifier,
402+
email);
402403
} catch (SQLException e) {
403404
throw new StorageQueryException(e);
404405
}
@@ -408,12 +409,37 @@ public static String getPrimaryUserIdUsingEmail(Start start, AppIdentifier appId
408409
}
409410
}
410411

411-
public static String getPrimaryUserIdUsingEmail_Transaction(Start start, Connection sqlConnection, AppIdentifier appIdentifier, String email)
412+
public static String getPrimaryUserIdForTenantUsingEmail_Transaction(Start start, Connection sqlConnection,
413+
TenantIdentifier tenantIdentifier,
414+
String email)
412415
throws SQLException, StorageQueryException {
413416
String QUERY = "SELECT DISTINCT all_users.primary_or_recipe_user_id AS user_id "
414417
+ "FROM " + getConfig(start).getWebAuthNUserToTenantTable() + " AS webauthn" +
415418
" JOIN " + getConfig(start).getUsersTable() + " AS all_users" +
416-
" ON webauthn.app_id = all_users.app_id AND webauthn.user_id = all_users.user_id" +
419+
" ON webauthn.tenant_id = all_users.tenant_id " +
420+
" AND webauthn.app_id = all_users.app_id" +
421+
" AND webauthn.user_id = all_users.user_id" +
422+
" WHERE webauthn.tenant_id = ? AND webauthn.app_id = ? AND webauthn.email = ?";
423+
424+
return execute(sqlConnection, QUERY, pst -> {
425+
pst.setString(1, tenantIdentifier.getTenantId());
426+
pst.setString(2, tenantIdentifier.getAppId());
427+
pst.setString(3, email);
428+
}, result -> {
429+
if (result.next()) {
430+
return result.getString("user_id");
431+
}
432+
return null;
433+
});
434+
}
435+
436+
public static String getPrimaryUserIdForAppUsingEmail_Transaction(Start start, Connection sqlConnection,
437+
AppIdentifier appIdentifier, String email)
438+
throws SQLException, StorageQueryException {
439+
String QUERY = "SELECT DISTINCT all_users.primary_or_recipe_user_id AS user_id " +
440+
" FROM " + getConfig(start).getWebAuthNUserToTenantTable() + " AS webauthn" +
441+
" JOIN " + getConfig(start).getUsersTable() + " AS all_users" +
442+
" ON webauthn.user_id = all_users.user_id" +
417443
" WHERE webauthn.app_id = ? AND webauthn.email = ?";
418444

419445
return execute(sqlConnection, QUERY, pst -> {

0 commit comments

Comments
 (0)