CB-5152 fix data source config if credentials were saved for current session (#3191)

Co-authored-by: Daria Marutkina <125263541+dariamarutkina@users.noreply.github.com>
This commit is contained in:
Ainur
2025-01-20 10:18:06 +01:00
committed by GitHub
co-authored by Daria Marutkina
parent e708c1b810
commit 6514cbe66f
4 changed files with 24 additions and 10 deletions
@@ -25,6 +25,7 @@ import io.cloudbeaver.utils.CBModelConstants;
import io.cloudbeaver.utils.ServletAppUtils;
import io.cloudbeaver.utils.WebCommonUtils;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.*;
@@ -76,6 +77,8 @@ public class WebConnectionInfo {
private String connectTime;
private String serverVersion;
private String clientVersion;
@Nullable
private Boolean credentialsSavedInSession;
private transient Map<String, Object> savedAuthProperties;
private transient List<WebNetworkHandlerConfigInput> savedNetworkCredentials;
@@ -195,7 +198,8 @@ public class WebConnectionInfo {
@Property
public boolean isCredentialsSaved() throws DBException {
return dataSourceContainer.isCredentialsSaved();
// isCredentialsSaved can be true if credentials were saved during connection init for global project
return dataSourceContainer.isCredentialsSaved() && !(credentialsSavedInSession != null && credentialsSavedInSession);
}
@Property
@@ -514,4 +518,10 @@ public class WebConnectionInfo {
return tools;
}
/**
* Updates param that checks whether credentials were saved only in session.
*/
public void setCredentialsSavedInSession(@Nullable Boolean credentialsSavedInSession) {
this.credentialsSavedInSession = credentialsSavedInSession;
}
}
@@ -121,8 +121,8 @@ public interface DBWServiceCore extends DBWService {
@NotNull String connectionId,
@NotNull Map<String, Object> authProperties,
@Nullable List<WebNetworkHandlerConfigInput> networkCredentials,
@Nullable Boolean saveCredentials,
@Nullable Boolean sharedCredentials,
boolean saveCredentials,
boolean sharedCredentials,
@Nullable String selectedCredentials
) throws DBWebException;
@@ -24,7 +24,6 @@ import io.cloudbeaver.WebServiceUtils;
import io.cloudbeaver.model.WebConnectionConfig;
import io.cloudbeaver.model.WebNetworkHandlerConfigInput;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.server.BaseWebPlatform;
import io.cloudbeaver.server.WebAppSessionManager;
import io.cloudbeaver.server.WebAppUtils;
import io.cloudbeaver.server.graphql.GraphQLEndpoint;
@@ -33,6 +32,7 @@ import io.cloudbeaver.service.WebServiceBindingBase;
import io.cloudbeaver.service.core.impl.WebServiceCore;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jkiss.utils.CommonUtils;
import java.util.Collections;
import java.util.List;
@@ -134,8 +134,8 @@ public class WebServiceBindingCore extends WebServiceBindingBase<DBWServiceCore>
env.getArgument("id"),
env.getArgument("credentials"),
nhc,
env.getArgument("saveCredentials"),
env.getArgument("sharedCredentials"),
CommonUtils.toBoolean(env.getArgument("saveCredentials")),
CommonUtils.toBoolean(env.getArgument("sharedCredentials")),
env.getArgument("selectedSecretId")
);
}
@@ -339,8 +339,8 @@ public class WebServiceCore implements DBWServiceCore {
@NotNull String connectionId,
@NotNull Map<String, Object> authProperties,
@Nullable List<WebNetworkHandlerConfigInput> networkCredentials,
@Nullable Boolean saveCredentials,
@Nullable Boolean sharedCredentials,
boolean saveCredentials,
boolean sharedCredentials,
@Nullable String selectedSecretId
) throws DBWebException {
WebConnectionInfo connectionInfo = WebDataSourceUtils.getWebConnectionInfo(webSession, projectId, connectionId);
@@ -408,14 +408,14 @@ public class WebServiceCore implements DBWServiceCore {
}
});
}
if (saveCredentials != null && saveCredentials) {
if (saveCredentials) {
// Save all passed credentials in the datasource container
WebServiceUtils.saveAuthProperties(
dataSourceContainer,
dataSourceContainer.getConnectionConfiguration(),
authProperties,
true,
sharedCredentials == null ? false : sharedCredentials
sharedCredentials
);
var project = dataSourceContainer.getProject();
@@ -436,6 +436,9 @@ public class WebServiceCore implements DBWServiceCore {
}
if (WebServiceUtils.isGlobalProject(dataSourceContainer.getProject())) {
// Do not flush config for global project (only admin can do it - CB-2415)
if (saveCredentials) {
connectionInfo.setCredentialsSavedInSession(true);
}
saveConfig[0] = false;
}
if (saveConfig[0]) {
@@ -556,6 +559,7 @@ public class WebServiceCore implements DBWServiceCore {
config.isSharedCredentials()
);
}
connectionInfo.setCredentialsSavedInSession(null);
WSDataSourceProperty property = getDatasourceEventProperty(oldDataSource, dataSource);