Skip to content

Commit f371665

Browse files
committed
fix: update config
1 parent 94dc87b commit f371665

File tree

11 files changed

+151
-120
lines changed

11 files changed

+151
-120
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2023, VRAI Labs and/or its affiliates. All rights reserved.
3+
*
4+
* This software is licensed under the Apache License, Version 2.0 (the
5+
* "License") as published by the Apache Software Foundation.
6+
*
7+
* You may not use this file except in compliance with the License. You may
8+
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
package io.supertokens.storage.postgresql.annotations;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
@Retention(RetentionPolicy.RUNTIME)
25+
@Target(ElementType.FIELD)
26+
public @interface EditableInDashboard {
27+
}

src/main/java/io/supertokens/storage/postgresql/config/PostgreSQLConfig.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@
2727
import io.supertokens.pluginInterface.ConfigFieldInfo;
2828
import io.supertokens.pluginInterface.exceptions.InvalidConfigException;
2929
import io.supertokens.storage.postgresql.Start;
30-
import io.supertokens.storage.postgresql.annotations.ConnectionPoolProperty;
31-
import io.supertokens.storage.postgresql.annotations.IgnoreForAnnotationCheck;
32-
import io.supertokens.storage.postgresql.annotations.NotConflictingWithinUserPool;
33-
import io.supertokens.storage.postgresql.annotations.ConfigDescription;
34-
import io.supertokens.storage.postgresql.annotations.UserPoolProperty;
30+
import io.supertokens.storage.postgresql.annotations.*;
3531

3632
import java.lang.reflect.Field;
3733
import java.net.URI;
@@ -52,6 +48,7 @@ public class PostgreSQLConfig {
5248
@JsonProperty
5349
@ConnectionPoolProperty
5450
@ConfigDescription("Defines the connection pool size to PostgreSQL. (Default: 10)")
51+
@EditableInDashboard
5552
private int postgresql_connection_pool_size = 10;
5653

5754
@JsonProperty
@@ -62,6 +59,7 @@ public class PostgreSQLConfig {
6259
@JsonProperty
6360
@UserPoolProperty
6461
@ConfigDescription("Specify the port to use when connecting to PostgreSQL instance. (Default: 5432)")
62+
@EditableInDashboard
6563
private int postgresql_port = -1;
6664

6765
@JsonProperty
@@ -140,11 +138,13 @@ public class PostgreSQLConfig {
140138
@JsonProperty
141139
@ConnectionPoolProperty
142140
@ConfigDescription("Timeout in milliseconds for the idle connections to be closed. (Default: 60000)")
141+
@EditableInDashboard
143142
private long postgresql_idle_connection_timeout = 60000;
144143

145144
@JsonProperty
146145
@ConnectionPoolProperty
147146
@ConfigDescription("Minimum number of idle connections to be kept active. If not set, minimum idle connections will be same as the connection pool size. (Default: null)")
147+
@EditableInDashboard
148148
private Integer postgresql_minimum_idle_connections = null;
149149

150150
@IgnoreForAnnotationCheck
@@ -204,11 +204,11 @@ public static ArrayList<ConfigFieldInfo> getConfigFieldsInfo(Start start) {
204204
JsonElement defaultValue = defaultConfig.get(field.getName());
205205
boolean isNullable = defaultValue == null;
206206

207-
boolean isEditable = field.isAnnotationPresent(ConnectionPoolProperty.class);
207+
boolean isEditable = field.isAnnotationPresent(EditableInDashboard.class);
208208

209209
result.add(new ConfigFieldInfo(
210-
key, valueType, value, description, isSaasProtected, isDifferentAcrossTenants,
211-
isConfigYamlOnly, possibleValues, isNullable, defaultValue, true, isEditable));
210+
key, valueType, value, description, isDifferentAcrossTenants,
211+
possibleValues, isNullable, defaultValue, true, isEditable));
212212

213213
} catch (NoSuchFieldException e) {
214214
continue;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ static String getQueryToCreateTenantConfigsTable(Start start) {
5151
+ "email_password_enabled BOOLEAN,"
5252
+ "passwordless_enabled BOOLEAN,"
5353
+ "third_party_enabled BOOLEAN,"
54+
+ "use_first_factors_from_static_if_empty BOOLEAN,"
55+
+ "use_third_party_providers_from_static_if_empty BOOLEAN,"
5456
+ "CONSTRAINT " + Utils.getConstraintName(schema, tenantConfigsTable, null, "pkey") + " PRIMARY KEY (connection_uri_domain, app_id, tenant_id)"
5557
+ ");";
5658
// @formatter:on

src/main/java/io/supertokens/storage/postgresql/queries/multitenancy/TenantConfigSQLHelper.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@
1616

1717
package io.supertokens.storage.postgresql.queries.multitenancy;
1818

19-
import com.google.gson.Gson;
20-
import com.google.gson.GsonBuilder;
21-
import com.google.gson.JsonArray;
2219
import io.supertokens.pluginInterface.RowMapper;
2320
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
2421
import io.supertokens.pluginInterface.multitenancy.*;
2522
import io.supertokens.storage.postgresql.Start;
2623
import io.supertokens.storage.postgresql.queries.utils.JsonUtils;
27-
import io.supertokens.storage.postgresql.utils.Utils;
2824

2925
import java.sql.Connection;
3026
import java.sql.ResultSet;
@@ -59,9 +55,13 @@ public TenantConfig map(ResultSet result) throws StorageQueryException {
5955
return new TenantConfig(
6056
new TenantIdentifier(result.getString("connection_uri_domain"), result.getString("app_id"), result.getString("tenant_id")),
6157
new EmailPasswordConfig(result.getBoolean("email_password_enabled")),
62-
new ThirdPartyConfig(result.getBoolean("third_party_enabled"), this.providers),
58+
new ThirdPartyConfig(
59+
result.getBoolean("third_party_enabled"),
60+
result.getBoolean("use_third_party_providers_from_static_if_empty"),
61+
this.providers),
6362
new PasswordlessConfig(result.getBoolean("passwordless_enabled")),
6463
firstFactors.length == 0 ? null : firstFactors,
64+
result.getBoolean("use_first_factors_from_static_if_empty"),
6565
requiredSecondaryFactors.length == 0 ? null : requiredSecondaryFactors,
6666
JsonUtils.stringToJsonObject(result.getString("core_config"))
6767
);
@@ -74,7 +74,8 @@ public TenantConfig map(ResultSet result) throws StorageQueryException {
7474
public static TenantConfig[] selectAll(Start start, HashMap<TenantIdentifier, HashMap<String, ThirdPartyConfig.Provider>> providerMap, HashMap<TenantIdentifier, String[]> firstFactorsMap, HashMap<TenantIdentifier, String[]> requiredSecondaryFactorsMap)
7575
throws SQLException, StorageQueryException {
7676
String QUERY = "SELECT connection_uri_domain, app_id, tenant_id, core_config,"
77-
+ " email_password_enabled, passwordless_enabled, third_party_enabled FROM "
77+
+ " email_password_enabled, passwordless_enabled, third_party_enabled, "
78+
+ " use_first_factors_from_static_if_empty, use_third_party_providers_from_static_if_empty FROM "
7879
+ getConfig(start).getTenantConfigsTable() + ";";
7980

8081
TenantConfig[] tenantConfigs = execute(start, QUERY, pst -> {}, result -> {
@@ -104,8 +105,9 @@ public static void create(Start start, Connection sqlCon, TenantConfig tenantCon
104105
throws SQLException, StorageQueryException {
105106
String QUERY = "INSERT INTO " + getConfig(start).getTenantConfigsTable()
106107
+ "(connection_uri_domain, app_id, tenant_id, core_config,"
107-
+ " email_password_enabled, passwordless_enabled, third_party_enabled)"
108-
+ " VALUES(?, ?, ?, ?, ?, ?, ?)";
108+
+ " email_password_enabled, passwordless_enabled, third_party_enabled,"
109+
+ " use_first_factors_from_static_if_empty, use_third_party_providers_from_static_if_empty)"
110+
+ " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)";
109111

110112
update(sqlCon, QUERY, pst -> {
111113
pst.setString(1, tenantConfig.tenantIdentifier.getConnectionUriDomain());
@@ -115,6 +117,8 @@ public static void create(Start start, Connection sqlCon, TenantConfig tenantCon
115117
pst.setBoolean(5, tenantConfig.emailPasswordConfig.enabled);
116118
pst.setBoolean(6, tenantConfig.passwordlessConfig.enabled);
117119
pst.setBoolean(7, tenantConfig.thirdPartyConfig.enabled);
120+
pst.setBoolean(8, tenantConfig.useFirstFactorsFromStaticConfigIfEmpty);
121+
pst.setBoolean(9, tenantConfig.thirdPartyConfig.useThirdPartyProvidersFromStaticConfigIfEmpty);
118122
});
119123
}
120124

src/test/java/io/supertokens/storage/postgresql/test/AccountLinkingTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ public void canLinkFailsIfTryingToLinkUsersAcrossDifferentStorageLayers() throws
8686
new TenantConfig(
8787
tenantIdentifier,
8888
new EmailPasswordConfig(true),
89-
new ThirdPartyConfig(true, null),
89+
new ThirdPartyConfig(true, true, null),
9090
new PasswordlessConfig(true),
91-
null, null,
91+
null, true, null,
9292
coreConfig
9393
)
9494
);
@@ -129,9 +129,9 @@ public void canLinkFailsIfTryingToLinkUsersAcrossDifferentStorageLayers() throws
129129
new TenantConfig(
130130
tenantIdentifier,
131131
new EmailPasswordConfig(true),
132-
new ThirdPartyConfig(true, null),
132+
new ThirdPartyConfig(true, true, null),
133133
new PasswordlessConfig(true),
134-
null, null,
134+
null, true, null,
135135
coreConfig
136136
)
137137
);

src/test/java/io/supertokens/storage/postgresql/test/DbConnectionPoolTest.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ public void testActiveConnectionsWithTenants() throws Exception {
7979
Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(
8080
new TenantIdentifier(null, null, "t1"),
8181
new EmailPasswordConfig(true),
82-
new ThirdPartyConfig(true, null),
82+
new ThirdPartyConfig(true, true, null),
8383
new PasswordlessConfig(true),
84-
null, null, config
84+
null, true, null, config
8585
), false);
8686

8787
Thread.sleep(1000); // let the new tenant be ready
@@ -94,9 +94,9 @@ public void testActiveConnectionsWithTenants() throws Exception {
9494
Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(
9595
new TenantIdentifier(null, null, "t1"),
9696
new EmailPasswordConfig(true),
97-
new ThirdPartyConfig(true, null),
97+
new ThirdPartyConfig(true, true, null),
9898
new PasswordlessConfig(true),
99-
null, null, config
99+
null, true, null, config
100100
), false);
101101

102102
Thread.sleep(2000); // let the new tenant be ready
@@ -137,9 +137,9 @@ public void testDownTimeWhenChangingConnectionPoolSize() throws Exception {
137137
Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(
138138
new TenantIdentifier(null, null, "t1"),
139139
new EmailPasswordConfig(true),
140-
new ThirdPartyConfig(true, null),
140+
new ThirdPartyConfig(true, true, null),
141141
new PasswordlessConfig(true),
142-
null, null, config
142+
null, true, null, config
143143
), false);
144144

145145
Thread.sleep(5000); // let the new tenant be ready
@@ -197,9 +197,9 @@ public void testDownTimeWhenChangingConnectionPoolSize() throws Exception {
197197
Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(
198198
new TenantIdentifier(null, null, "t1"),
199199
new EmailPasswordConfig(true),
200-
new ThirdPartyConfig(true, null),
200+
new ThirdPartyConfig(true, true, null),
201201
new PasswordlessConfig(true),
202-
null, null, config
202+
null, true, null, config
203203
), false);
204204

205205
Thread.sleep(3000); // let the new tenant be ready
@@ -279,9 +279,9 @@ public void testMinimumIdleConnectionForTenants() throws Exception {
279279
Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(
280280
new TenantIdentifier(null, null, "t1"),
281281
new EmailPasswordConfig(true),
282-
new ThirdPartyConfig(true, null),
282+
new ThirdPartyConfig(true, true, null),
283283
new PasswordlessConfig(true),
284-
null, null, config
284+
null, true, null, config
285285
), false);
286286

287287
Thread.sleep(1000); // let the new tenant be ready
@@ -295,9 +295,9 @@ public void testMinimumIdleConnectionForTenants() throws Exception {
295295
Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(
296296
new TenantIdentifier(null, null, "t1"),
297297
new EmailPasswordConfig(true),
298-
new ThirdPartyConfig(true, null),
298+
new ThirdPartyConfig(true, true, null),
299299
new PasswordlessConfig(true),
300-
null, null, config
300+
null, true, null, config
301301
), false);
302302

303303
Thread.sleep(2000); // let the new tenant be ready
@@ -338,9 +338,9 @@ public void testIdleConnectionTimeout() throws Exception {
338338
Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(
339339
new TenantIdentifier(null, null, "t1"),
340340
new EmailPasswordConfig(true),
341-
new ThirdPartyConfig(true, null),
341+
new ThirdPartyConfig(true, true, null),
342342
new PasswordlessConfig(true),
343-
null, null, config
343+
null, true, null, config
344344
), false);
345345

346346
Thread.sleep(3000); // let the new tenant be ready

src/test/java/io/supertokens/storage/postgresql/test/LoggingTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import java.io.*;
4545
import java.nio.charset.StandardCharsets;
4646
import java.util.Iterator;
47-
import java.util.List;
4847
import java.util.Scanner;
4948

5049
import static org.junit.Assert.*;
@@ -285,9 +284,9 @@ public void confirmHikariLoggerClosedOnlyWhenProcessEnds() throws Exception {
285284
Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(
286285
tenant,
287286
new EmailPasswordConfig(true),
288-
new ThirdPartyConfig(true, null),
287+
new ThirdPartyConfig(true, true, null),
289288
new PasswordlessConfig(true),
290-
null, null,
289+
null, true, null,
291290
config
292291
), false);
293292

@@ -517,9 +516,9 @@ public void testDBPasswordIsNotLoggedWhenTenantIsCreated() throws Exception {
517516
new TenantConfig(
518517
tenantIdentifier,
519518
new EmailPasswordConfig(true),
520-
new ThirdPartyConfig(true, null),
519+
new ThirdPartyConfig(true, true, null),
521520
new PasswordlessConfig(true),
522-
null, null, config
521+
null, true, null, config
523522
));
524523

525524
process.kill();
@@ -562,9 +561,9 @@ public void testDBPasswordIsNotLoggedWhenTenantIsCreated() throws Exception {
562561
new TenantConfig(
563562
tenantIdentifier,
564563
new EmailPasswordConfig(true),
565-
new ThirdPartyConfig(true, null),
564+
new ThirdPartyConfig(true, true, null),
566565
new PasswordlessConfig(true),
567-
null, null,
566+
null, true, null,
568567
new JsonObject()));
569568

570569
} catch (Exception e) {

src/test/java/io/supertokens/storage/postgresql/test/SuperTokensSaaSSecretTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ public void testThatTenantCannotSetDatabaseRelatedConfigIfSuperTokensSaaSSecretI
8787
JsonObject j = new JsonObject();
8888
j.addProperty(PROTECTED_DB_CONFIG[i], "");
8989
Multitenancy.addNewOrUpdateAppOrTenant(process.main, new TenantConfig(new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(false),
90-
new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]),
90+
new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]),
9191
new PasswordlessConfig(false),
92-
null, null,
92+
null, true, null,
9393
j), true);
9494
fail();
9595
} catch (BadPermissionException e) {
@@ -164,9 +164,9 @@ public void testThatTenantCanSetDatabaseRelatedConfigIfSuperTokensSaaSSecretIsNo
164164
}
165165
Multitenancy.addNewOrUpdateAppOrTenant(process.main, new TenantConfig(new TenantIdentifier(null, null, "t1"),
166166
new EmailPasswordConfig(false),
167-
new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]),
167+
new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]),
168168
new PasswordlessConfig(false),
169-
null, null,
169+
null, true, null,
170170
j), false);
171171
}
172172

@@ -217,9 +217,9 @@ public void testThatTenantCannotGetDatabaseRelatedConfigIfSuperTokensSaaSSecretI
217217
}
218218
Multitenancy.addNewOrUpdateAppOrTenant(process.main, new TenantIdentifier(null, null, null),
219219
new TenantConfig(new TenantIdentifier(null, null, "t" + i), new EmailPasswordConfig(false),
220-
new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]),
220+
new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]),
221221
new PasswordlessConfig(false),
222-
null, null,
222+
null, true, null,
223223
j));
224224

225225
{

0 commit comments

Comments
 (0)