RED-5293: jdbcUrl is checked for protocol and sql
This commit is contained in:
parent
6b63468148
commit
f09c7e4318
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user