From a66ec807e63633a984acf93d813186579ea4ac04 Mon Sep 17 00:00:00 2001 From: aiceflower Date: Fri, 27 Oct 2023 14:25:35 +0800 Subject: [PATCH] fix mysql error (#4951) --- .../core/restful/RestfulApiHelper.java | 9 ++++++--- .../metadata/query/service/mysql/SqlConnection.java | 13 ++++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/linkis-public-enhancements/linkis-datasource/linkis-datasource-manager/server/src/main/java/org/apache/linkis/datasourcemanager/core/restful/RestfulApiHelper.java b/linkis-public-enhancements/linkis-datasource/linkis-datasource-manager/server/src/main/java/org/apache/linkis/datasourcemanager/core/restful/RestfulApiHelper.java index 0bf1a91b22..9651bb265b 100644 --- a/linkis-public-enhancements/linkis-datasource/linkis-datasource-manager/server/src/main/java/org/apache/linkis/datasourcemanager/core/restful/RestfulApiHelper.java +++ b/linkis-public-enhancements/linkis-datasource/linkis-datasource-manager/server/src/main/java/org/apache/linkis/datasourcemanager/core/restful/RestfulApiHelper.java @@ -20,11 +20,12 @@ import org.apache.linkis.common.exception.WarnException; import org.apache.linkis.datasourcemanager.common.auth.AuthContext; import org.apache.linkis.datasourcemanager.common.domain.DataSourceParamKeyDefinition; -import org.apache.linkis.datasourcemanager.common.util.CryptoUtils; import org.apache.linkis.datasourcemanager.core.restful.exception.BeanValidationExceptionMapper; import org.apache.linkis.datasourcemanager.core.validate.ParameterValidateException; import org.apache.linkis.server.Message; +import org.apache.commons.codec.binary.Base64; + import javax.validation.ConstraintViolationException; import java.util.Arrays; @@ -67,7 +68,8 @@ public static void encryptPasswordKey( if (keyDefinition.getValueType() == DataSourceParamKeyDefinition.ValueType.PASSWORD) { String password = String.valueOf(connectParams.get(keyDefinition.getKey())); if (null != password) { - connectParams.put(keyDefinition.getKey(), CryptoUtils.object2String(password)); + connectParams.put( + keyDefinition.getKey(), new String(new Base64().encode(password.getBytes()))); } } }); @@ -86,7 +88,8 @@ public static void decryptPasswordKey( if (keyDefinition.getValueType() == DataSourceParamKeyDefinition.ValueType.PASSWORD) { String password = String.valueOf(connectParams.get(keyDefinition.getKey())); if (null != password) { - connectParams.put(keyDefinition.getKey(), CryptoUtils.string2Object(password)); + connectParams.put( + keyDefinition.getKey(), new String(new Base64().decode(password.getBytes()))); } } }); diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/jdbc/src/main/java/org/apache/linkis/metadata/query/service/mysql/SqlConnection.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/jdbc/src/main/java/org/apache/linkis/metadata/query/service/mysql/SqlConnection.java index c329ab59fd..d7559aa5cf 100644 --- a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/jdbc/src/main/java/org/apache/linkis/metadata/query/service/mysql/SqlConnection.java +++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/jdbc/src/main/java/org/apache/linkis/metadata/query/service/mysql/SqlConnection.java @@ -57,9 +57,6 @@ public SqlConnection( Map extraParams) throws ClassNotFoundException, SQLException { super(host, port, username, password, database, extraParams); - // security check - SecurityUtils.checkJdbcConnParams(host, port, username, password, database, extraParams); - SecurityUtils.appendMysqlForceParams(extraParams); connectMessage.extraParams.put("connectTimeout", SQL_CONNECT_TIMEOUT.getValue()); connectMessage.extraParams.put("socketTimeout", SQL_SOCKET_TIMEOUT.getValue()); } @@ -136,6 +133,16 @@ public List getColumns(String database, String table) public Connection getDBConnection(ConnectMessage connectMessage, String database) throws ClassNotFoundException, SQLException { Class.forName(SQL_DRIVER_CLASS.getValue()); + // security check + SecurityUtils.checkJdbcConnParams( + connectMessage.host, + connectMessage.port, + connectMessage.username, + connectMessage.password, + database, + connectMessage.extraParams); + SecurityUtils.appendMysqlForceParams(connectMessage.extraParams); + String url = String.format( SQL_CONNECT_URL.getValue(), connectMessage.host, connectMessage.port, database);