Skip to content

Commit

Permalink
fix: add new booleans for core config
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed May 2, 2024
1 parent ed7360a commit 0eda7fe
Show file tree
Hide file tree
Showing 64 changed files with 3,129 additions and 1,108 deletions.
3 changes: 2 additions & 1 deletion coreDriverInterfaceSupported.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"2.21",
"3.0",
"4.0",
"5.0"
"5.0",
"5.1"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,27 @@ public void testPaidStatsIsSentForAllAppsInMultitenancy() throws Exception {
Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(
new TenantIdentifier("127.0.0.1", null, null),
new EmailPasswordConfig(true),
new ThirdPartyConfig(true, null),
new ThirdPartyConfig(true, true, null),
new PasswordlessConfig(true),
null, null,
null, true, null,
config
), false);

Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(
new TenantIdentifier("127.0.0.1", "a1", null),
new EmailPasswordConfig(true),
new ThirdPartyConfig(true, null),
new ThirdPartyConfig(true, true, null),
new PasswordlessConfig(true),
null, null,
null, true, null,
config
), false);

Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(
new TenantIdentifier("127.0.0.1", "a1", "t1"),
new EmailPasswordConfig(true),
new ThirdPartyConfig(true, null),
new ThirdPartyConfig(true, true, null),
new PasswordlessConfig(true),
null, null,
null, true, null,
config
), false);
}
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/io/supertokens/config/CoreConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import io.supertokens.pluginInterface.ConfigFieldInfo;
import io.supertokens.pluginInterface.LOG_LEVEL;
import io.supertokens.pluginInterface.exceptions.InvalidConfigException;
import io.supertokens.pluginInterface.multitenancy.TenantConfig;
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
import io.supertokens.utils.SemVer;
Expand All @@ -44,8 +43,6 @@
import org.apache.catalina.filters.RemoteAddrFilter;
import org.jetbrains.annotations.TestOnly;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -644,7 +641,7 @@ void normalizeAndValidate(Main main, boolean includeConfigFilePath) throws Inval
String[] allowedValues = field.getAnnotation(EnumProperty.class).value();
try {
String value = field.get(this) != null ? field.get(this).toString() : null;
if (!Arrays.asList(allowedValues).contains(value)) {
if (!Arrays.asList(Arrays.stream(allowedValues).map(str -> str.toLowerCase()).toArray()).contains(value.toLowerCase())) {
throw new InvalidConfigException(
fieldId + " property is not set correctly. It must be one of "
+ Arrays.toString(allowedValues));
Expand Down Expand Up @@ -815,7 +812,7 @@ public static ArrayList<ConfigFieldInfo> getConfigFieldsInfo(Main main, TenantId
// or is annotated with ConfigYamlOnly, then skip
if ( !field.isAnnotationPresent(JsonProperty.class)
|| field.isAnnotationPresent(ConfigYamlOnly.class)
|| fieldId == "core_config_version") {
|| fieldId.equals("core_config_version")) {
continue;
}

Expand Down Expand Up @@ -855,8 +852,8 @@ public static ArrayList<ConfigFieldInfo> getConfigFieldsInfo(Main main, TenantId
boolean isNullable = defaultValue == null;

result.add(new ConfigFieldInfo(
key, valueType, value, description, isSaasProtected, isDifferentAcrossTenants,
isConfigYamlOnly, possibleValues, isNullable, defaultValue, false, false));
key, valueType, value, description, isDifferentAcrossTenants,
possibleValues, isNullable, defaultValue, false, false));

} catch (NoSuchFieldException e) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ static String getQueryToCreateTenantConfigsTable(Start start) {
+ "email_password_enabled BOOLEAN,"
+ "passwordless_enabled BOOLEAN,"
+ "third_party_enabled BOOLEAN,"
+ "use_first_factors_from_static_if_empty BOOLEAN,"
+ "use_third_party_providers_from_static_if_empty BOOLEAN,"
+ "PRIMARY KEY (connection_uri_domain, app_id, tenant_id)"
+ ");";
// @formatter:on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ public TenantConfig map(ResultSet result) throws StorageQueryException {
return new TenantConfig(
new TenantIdentifier(result.getString("connection_uri_domain"), result.getString("app_id"), result.getString("tenant_id")),
new EmailPasswordConfig(result.getBoolean("email_password_enabled")),
new ThirdPartyConfig(result.getBoolean("third_party_enabled"), this.providers),
new ThirdPartyConfig(
result.getBoolean("third_party_enabled"),
result.getBoolean("use_third_party_providers_from_static_if_empty"),
this.providers),
new PasswordlessConfig(result.getBoolean("passwordless_enabled")),
firstFactors.length == 0 ? null : firstFactors,
result.getBoolean("use_first_factors_from_static_if_empty"),
requiredSecondaryFactors.length == 0 ? null : requiredSecondaryFactors,
JsonUtils.stringToJsonObject(result.getString("core_config"))
);
Expand All @@ -69,7 +73,9 @@ public TenantConfig map(ResultSet result) throws StorageQueryException {

public static TenantConfig[] selectAll(Start start, HashMap<TenantIdentifier, HashMap<String, ThirdPartyConfig.Provider>> providerMap, HashMap<TenantIdentifier, String[]> firstFactorsMap, HashMap<TenantIdentifier, String[]> requiredSecondaryFactorsMap)
throws SQLException, StorageQueryException {
String QUERY = "SELECT connection_uri_domain, app_id, tenant_id, core_config, email_password_enabled, passwordless_enabled, third_party_enabled FROM "
String QUERY = "SELECT connection_uri_domain, app_id, tenant_id, core_config, "
+ " email_password_enabled, passwordless_enabled, third_party_enabled, "
+ " use_first_factors_from_static_if_empty, use_third_party_providers_from_static_if_empty FROM "
+ Config.getConfig(start).getTenantConfigsTable() + ";";

TenantConfig[] tenantConfigs = execute(start, QUERY, pst -> {}, result -> {
Expand Down Expand Up @@ -98,8 +104,10 @@ public static TenantConfig[] selectAll(Start start, HashMap<TenantIdentifier, Ha
public static void create(Start start, Connection sqlCon, TenantConfig tenantConfig)
throws SQLException, StorageQueryException {
String QUERY = "INSERT INTO " + Config.getConfig(start).getTenantConfigsTable()
+ "(connection_uri_domain, app_id, tenant_id, core_config, email_password_enabled, passwordless_enabled, third_party_enabled)"
+ " VALUES(?, ?, ?, ?, ?, ?, ?)";
+ "(connection_uri_domain, app_id, tenant_id, core_config,"
+ " email_password_enabled, passwordless_enabled, third_party_enabled,"
+ " use_first_factors_from_static_if_empty, use_third_party_providers_from_static_if_empty)"
+ " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)";

update(sqlCon, QUERY, pst -> {
pst.setString(1, tenantConfig.tenantIdentifier.getConnectionUriDomain());
Expand All @@ -109,6 +117,8 @@ public static void create(Start start, Connection sqlCon, TenantConfig tenantCon
pst.setBoolean(5, tenantConfig.emailPasswordConfig.enabled);
pst.setBoolean(6, tenantConfig.passwordlessConfig.enabled);
pst.setBoolean(7, tenantConfig.thirdPartyConfig.enabled);
pst.setBoolean(8, tenantConfig.useFirstFactorsFromStaticConfigIfEmpty);
pst.setBoolean(9, tenantConfig.thirdPartyConfig.useThirdPartyProvidersFromStaticConfigIfEmpty);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ public static void init(Main main) throws StorageQueryException, IOException {
Multitenancy.addNewOrUpdateAppOrTenant(main,
new TenantConfig(
new TenantIdentifier(null, null, null),
new EmailPasswordConfig(true), new ThirdPartyConfig(true, null),
new EmailPasswordConfig(true),
new ThirdPartyConfig(true, true, null),
new PasswordlessConfig(true),
null, null, new JsonObject()), false, false, false);
null, true, null, new JsonObject()), false, false, false);
// Not force reloading all resources here (the last boolean in the function above)
// because the ucl for the FeatureFlag is not yet loaded and results in an empty
// instance of eeFeatureFlag. This is applicable only when the core is starting on
Expand All @@ -105,9 +106,9 @@ private TenantConfig[] getAllTenantsFromDb() throws StorageQueryException {
new TenantConfig(
TenantIdentifier.BASE_TENANT,
new EmailPasswordConfig(true),
new ThirdPartyConfig(true, null),
new ThirdPartyConfig(true, true, null),
new PasswordlessConfig(true),
null, null, new JsonObject()
null, true, null, new JsonObject()
)
};
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/supertokens/utils/SemVer.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class SemVer implements Comparable<SemVer> {
public static final SemVer v3_0 = new SemVer("3.0");
public static final SemVer v4_0 = new SemVer("4.0");
public static final SemVer v5_0 = new SemVer("5.0");
public static final SemVer v5_1 = new SemVer("5.1");

final private String version;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/supertokens/webserver/Webserver.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private void setupRoutes() {
addAPI(new ConsumeResetPasswordAPI(main));

addAPI(new RequestStatsAPI(main));
addAPI(new CoreConfigListAPI(main));
addAPI(new GetTenantCoreConfigAPI(main));

StandardContext context = tomcatReference.getContext();
Tomcat tomcat = tomcatReference.getTomcat();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/supertokens/webserver/WebserverAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ public abstract class WebserverAPI extends HttpServlet {
supportedVersions.add(SemVer.v3_0);
supportedVersions.add(SemVer.v4_0);
supportedVersions.add(SemVer.v5_0);
supportedVersions.add(SemVer.v5_1);
}

public static SemVer getLatestCDIVersion() {
return SemVer.v5_0;
return SemVer.v5_1;
}

public SemVer getLatestCDIVersionForRequest(HttpServletRequest req)
Expand Down
Loading

0 comments on commit 0eda7fe

Please sign in to comment.