fix: 校验数据库名称

This commit is contained in:
taojinlong 2023-05-25 16:27:01 +08:00
parent db016e2c5e
commit 162a70c8f0

View File

@ -781,6 +781,9 @@ public class JdbcProvider extends DefaultJdbcProvider {
case StarRocks: case StarRocks:
MysqlConfiguration mysqlConfiguration = new Gson().fromJson(datasource.getConfiguration(), MysqlConfiguration.class); MysqlConfiguration mysqlConfiguration = new Gson().fromJson(datasource.getConfiguration(), MysqlConfiguration.class);
mysqlConfiguration.getJdbc(); mysqlConfiguration.getJdbc();
if(!mysqlConfiguration.getDataBase().matches("^[0-9a-zA-Z_]{1,}$")){
throw new Exception("Invalid database name");
}
break; break;
case redshift: case redshift:
RedshiftConfiguration redshiftConfiguration = new Gson().fromJson(datasource.getConfiguration(), RedshiftConfiguration.class); RedshiftConfiguration redshiftConfiguration = new Gson().fromJson(datasource.getConfiguration(), RedshiftConfiguration.class);
@ -791,6 +794,48 @@ public class JdbcProvider extends DefaultJdbcProvider {
throw new Exception("Invalid database name"); throw new Exception("Invalid database name");
} }
break; break;
case sqlServer:
SqlServerConfiguration sqlServerConfiguration = new Gson().fromJson(datasource.getConfiguration(), SqlServerConfiguration.class);
if(!sqlServerConfiguration.getDataBase().matches("^[0-9a-zA-Z_]{1,}$")){
throw new Exception("Invalid database name");
}
break;
case pg:
PgConfiguration pgConfiguration = new Gson().fromJson(datasource.getConfiguration(), PgConfiguration.class);
if(!pgConfiguration.getDataBase().matches("^[0-9a-zA-Z_]{1,}$")){
throw new Exception("Invalid database name");
}
break;
case oracle:
OracleConfiguration oracleConfiguration = new Gson().fromJson(datasource.getConfiguration(), OracleConfiguration.class);
if(!oracleConfiguration.getDataBase().matches("^[0-9a-zA-Z_]{1,}$")){
throw new Exception("Invalid database name");
}
break;
case mongo:
MongodbConfiguration mongodbConfiguration = new Gson().fromJson(datasource.getConfiguration(), MongodbConfiguration.class);
if(!mongodbConfiguration.getDataBase().matches("^[0-9a-zA-Z_]{1,}$")){
throw new Exception("Invalid database name");
}
break;
case impala:
ImpalaConfiguration impalaConfiguration = new Gson().fromJson(datasource.getConfiguration(), ImpalaConfiguration.class);
if(!impalaConfiguration.getDataBase().matches("^[0-9a-zA-Z_]{1,}$")){
throw new Exception("Invalid database name");
}
break;
case hive:
HiveConfiguration hiveConfiguration = new Gson().fromJson(datasource.getConfiguration(), HiveConfiguration.class);
if(!hiveConfiguration.getDataBase().matches("^[0-9a-zA-Z_]{1,}$")){
throw new Exception("Invalid database name");
}
break;
case db2:
Db2Configuration db2Configuration = new Gson().fromJson(datasource.getConfiguration(), Db2Configuration.class);
if(!db2Configuration.getDataBase().matches("^[0-9a-zA-Z_]{1,}$")){
throw new Exception("Invalid database name");
}
break;
default: default:
break; break;
} }