Skip to content

Commit

Permalink
fix mysql error (apache#4951)
Browse files Browse the repository at this point in the history
  • Loading branch information
aiceflower authored Oct 27, 2023
1 parent 2b6bb26 commit a66ec80
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())));
}
}
});
Expand All @@ -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())));
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ public SqlConnection(
Map<String, Object> 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());
}
Expand Down Expand Up @@ -136,6 +133,16 @@ public List<MetaColumnInfo> 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);
Expand Down

0 comments on commit a66ec80

Please sign in to comment.