Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,78 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [1.23.0] - 2023-04-05

- Adds support for plugin inteface version 2.21
- Adds `use_static_key` into `session_info`

### Migration


- If using `access_token_signing_key_dynamic` false:
- ```
db.session_info.update({},
{
"$set": {
"use_static_key": true
}
});
```
- ```
db.key_value.aggregate([
{
"$match": {
_id: "access_token_signing_key_list"
}
},
{
$unwind: "$keys"
},
{
$addFields: {
_id: {
"$concat": [
"s-",
{
$convert: {
input: "$keys.created_at_time",
to: "string"
}
}
]
},
"key_string": "$keys.value",
"algorithm": "RS256",
"created_at": "$keys.created_at_time",

}
},
{
"$project": {
"keys": 0,

}
},
{
"$merge": {
"into": "jwt_signing_keys",

}
}
]);
```

- If using `access_token_signing_key_dynamic` true:
- ```
db.session_info.update({},
{
"$set": {
"use_static_key": false
}
});
```
- Fixed an issue when adding new access token signing key to an empty list

## [1.22.0] - 2023-03-30

- New plugin version (v2.22)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'java-library'
}

version = "1.22.0"
version = "1.23.0"

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion pluginInterfaceSupported.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"_comment": "contains a list of plugin interfaces branch names that this core supports",
"versions": [
"2.22"
"2.23"
]
}
18 changes: 12 additions & 6 deletions src/main/java/io/supertokens/storage/mongodb/Queries.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,15 @@ static boolean addArrayKeyValue_Transaction(Start start, String key, KeyValueInf

return result.getModifiedCount() == 1;
} else {

try {
collection.insertOne(new Document("_id", key).append("keys", keyList));
UpdateResult result = collection.updateOne(
Filters.and(Filters.eq("_id", key), Filters.size("keys", 0)),
// We have to use a pushEach with here, because it allows us to set where we push the value
Updates.pushEach("keys", keyList, new PushOptions().position(0)),
new UpdateOptions().upsert(true));

// TODO: supposed to call this only if result.wasAcknowledged() is true. Why?
return true;
return result.getModifiedCount() == 1;
} catch (MongoException e) {
if (!isDuplicateKeyException(e)) {
throw e;
Expand All @@ -235,14 +238,15 @@ static boolean addArrayKeyValue_Transaction(Start start, String key, KeyValueInf

@SuppressWarnings("unchecked")
static void createNewSession(Start start, String sessionHandle, String userId, String refreshTokenHash2,
JsonObject userDataInDatabase, long expiry, JsonObject userDataInJWT, long createdAtTime) {
JsonObject userDataInDatabase, long expiry, JsonObject userDataInJWT, long createdAtTime, boolean useStaticKey) {
MongoDatabase client = ConnectionPool.getClientConnectedToDatabase(start);
MongoCollection collection = client.getCollection(Config.getConfig(start).getSessionInfoCollection());

collection.insertOne(new Document("_id", sessionHandle).append("user_id", userId)
.append("refresh_token_hash_2", refreshTokenHash2).append("session_data", userDataInDatabase.toString())
.append("expires_at", expiry).append("jwt_user_payload", userDataInJWT.toString())
.append("created_at_time", createdAtTime).append("last_updated_sign", Utils.getUUID()));
.append("created_at_time", createdAtTime).append("last_updated_sign", Utils.getUUID())
.append("use_static_key", useStaticKey));
}

static SessionInfoWithLastUpdated getSessionInfo_Transaction(Start start, String sessionHandle)
Expand Down Expand Up @@ -381,7 +385,8 @@ public SessionInfo map(Document result) throws Exception {
result.getString("refresh_token_hash_2"),
jp.parse(result.getString("session_data")).getAsJsonObject(), result.getLong("expires_at"),
jp.parse(result.getString("jwt_user_payload")).getAsJsonObject(),
result.getLong("created_at_time"));
result.getLong("created_at_time"),
Boolean.TRUE.equals(result.getBoolean("use_static_key")));
}
}

Expand Down Expand Up @@ -419,6 +424,7 @@ public SessionInfoWithLastUpdated map(Document result) throws Exception {
result.getString("refresh_token_hash_2"),
jp.parse(result.getString("session_data")).getAsJsonObject(), result.getLong("expires_at"),
jp.parse(result.getString("jwt_user_payload")).getAsJsonObject(), result.getLong("created_at_time"),
Boolean.TRUE.equals(result.getBoolean("use_static_key")),
result.getString("last_updated_sign"));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/supertokens/storage/mongodb/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ public SessionInfoWithLastUpdated getSessionInfo_Transaction(String sessionHandl

@Override
public void createNewSession(String sessionHandle, String userId, String refreshTokenHash2,
JsonObject userDataInDatabase, long expiry, JsonObject userDataInJWT, long createdAtTime)
JsonObject userDataInDatabase, long expiry, JsonObject userDataInJWT, long createdAtTime, boolean useStaticKey)
throws StorageQueryException {
try {
Queries.createNewSession(this, sessionHandle, userId, refreshTokenHash2, userDataInDatabase, expiry,
userDataInJWT, createdAtTime);
userDataInJWT, createdAtTime, useStaticKey);
} catch (MongoException e) {
throw new StorageQueryException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public JWTSigningKeyInfo map(Document result) throws Exception {
long createdAt = result.getLong("created_at");
String algorithm = result.getString("algorithm");

if (keyString.contains("|")) {
if (keyString.contains("|") || keyString.contains(";")) {
return new JWTAsymmetricSigningKeyInfo(keyId, createdAt, algorithm, keyString);
} else {
return new JWTSymmetricSigningKeyInfo(keyId, createdAt, algorithm, keyString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
import org.junit.rules.TestRule;

import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.*;

public class KeyValueInfoArrayTest {
@Rule
Expand Down Expand Up @@ -153,4 +152,28 @@ public void checkRemoveAccessTokenSigningKeysBefore() throws InterruptedExceptio
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
}

@Test
public void checkThatAddWorksWorksWithEmptyList() throws InterruptedException, StorageQueryException {
String[] args = { "../" };
TestingProcessManager.TestingProcess process = TestingProcessManager.start(args);
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));

SessionStorage sessionStorage = StorageLayer.getSessionStorage(process.getProcess());
if (sessionStorage.getType() != STORAGE_TYPE.NOSQL_1) {
return;
}
SessionNoSQLStorage_1 noSQLSessionStorage_1 = (SessionNoSQLStorage_1) sessionStorage;

noSQLSessionStorage_1.addAccessTokenSigningKey_Transaction(new KeyValueInfo("key1", 100), null);

noSQLSessionStorage_1.removeAccessTokenSigningKeysBefore(199);

assert noSQLSessionStorage_1.addAccessTokenSigningKey_Transaction(new KeyValueInfo("key3", 200), null);

KeyValueInfo[] allKeys = noSQLSessionStorage_1.getAccessTokenSigningKeys_Transaction();
assertEquals(allKeys.length, 1);

process.kill();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
}
}