RED-5293: jdbcUrl is checked for protocol and sql

This commit is contained in:
Ali Oezyetimoglu 2022-11-10 16:19:27 +01:00
parent 6b63468148
commit f09c7e4318

View File

@ -36,6 +36,7 @@ import lombok.extern.slf4j.Slf4j;
@EnableConfigurationProperties(LiquibaseProperties.class)
public class TenantManagementService {
private static final Set<String> SUPPORTED_DATABASES = Set.of("postgresql");
private static final Set<String> SQL_CONNECTION_ERROR_CODES = Set.of(
// connection_exception
"08000",
@ -132,13 +133,14 @@ public class TenantManagementService {
@SneakyThrows
private void validateJdbcUrl(String jdbcUrl) {
String startExpr = "jdbc:postgresql://";
if (!jdbcUrl.startsWith(startExpr)) {
throw new IllegalArgumentException("Your jdbcUrl is not URL conform.");
// just create a URI object to check if the string is a valid URI
var uri = new URI(jdbcUrl);
var subUri = new URI(uri.getSchemeSpecificPart());
if (!uri.getScheme().startsWith("jdbc") || !SUPPORTED_DATABASES.contains(subUri.getScheme())) {
throw new IllegalArgumentException("Your jdbcUrl is not valid.");
}
// just create a URI object to check if the string is a valid URI
new URI(jdbcUrl);
}