Skip to content

Commit

Permalink
CB-4099. Create logic for save comfig and user for CB TE. (#2067)
Browse files Browse the repository at this point in the history
* CB-4099. Create logic for save comfig and user for CB TE.

* CB-4099. Fixed checkstyle

* CB-4099. Refactor after review

---------

Co-authored-by: EvgeniaBzzz <[email protected]>
  • Loading branch information
DenisSinelnikov and EvgeniaBzzz authored Oct 24, 2023
1 parent 9979363 commit 98197c8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package io.cloudbeaver.server;

import org.jkiss.dbeaver.model.auth.AuthInfo;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.InstanceCreator;
Expand All @@ -24,7 +25,6 @@
import io.cloudbeaver.model.app.BaseWebApplication;
import io.cloudbeaver.model.app.WebAuthApplication;
import io.cloudbeaver.model.app.WebAuthConfiguration;
import io.cloudbeaver.model.session.WebAuthInfo;
import io.cloudbeaver.registry.WebDriverRegistry;
import io.cloudbeaver.registry.WebServiceRegistry;
import io.cloudbeaver.server.jetty.CBJettyServer;
Expand Down Expand Up @@ -825,7 +825,7 @@ public synchronized void finishConfiguration(
@NotNull String newServerURL,
@NotNull String adminName,
@Nullable String adminPassword,
@NotNull List<WebAuthInfo> authInfoList,
@NotNull List<AuthInfo> authInfoList,
long sessionExpireTime,
@NotNull CBAppConfig appConfig,
@Nullable SMCredentialsProvider credentialsProvider
Expand Down Expand Up @@ -886,7 +886,7 @@ protected Map<String, Object> readRuntimeConfigurationProperties() throws DBExce
protected abstract void finishSecurityServiceConfiguration(
@NotNull String adminName,
@Nullable String adminPassword,
@NotNull List<WebAuthInfo> authInfoList
@NotNull List<AuthInfo> authInfoList
) throws DBException;

public synchronized void flushConfiguration(SMCredentialsProvider credentialsProvider) throws DBException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/
package io.cloudbeaver.server;

import org.jkiss.dbeaver.model.auth.AuthInfo;
import io.cloudbeaver.auth.NoAuthCredentialsProvider;
import io.cloudbeaver.model.rm.local.LocalResourceController;
import io.cloudbeaver.model.session.WebAuthInfo;
import io.cloudbeaver.service.security.CBEmbeddedSecurityController;
import io.cloudbeaver.service.security.EmbeddedSecurityControllerFactory;
import org.jkiss.code.NotNull;
Expand All @@ -31,7 +31,6 @@
import org.jkiss.dbeaver.model.rm.RMController;
import org.jkiss.dbeaver.model.security.SMAdminController;
import org.jkiss.dbeaver.model.security.SMController;
import org.jkiss.dbeaver.registry.BasePlatformImpl;
import org.jkiss.dbeaver.registry.LocalFileController;
import org.jkiss.dbeaver.runtime.DBWorkbench;

Expand Down Expand Up @@ -94,7 +93,7 @@ protected void shutdown() {
protected void finishSecurityServiceConfiguration(
@NotNull String adminName,
@Nullable String adminPassword,
@NotNull List<WebAuthInfo> authInfoList
@NotNull List<AuthInfo> authInfoList
) throws DBException {
if (securityController instanceof CBEmbeddedSecurityController) {
((CBEmbeddedSecurityController) securityController).finishConfiguration(adminName, adminPassword, authInfoList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.app.DBPDataSourceRegistry;
import org.jkiss.dbeaver.model.app.DBPProject;
import org.jkiss.dbeaver.model.auth.AuthInfo;
import org.jkiss.dbeaver.model.navigator.DBNBrowseSettings;
import org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor;
import org.jkiss.dbeaver.model.security.*;
Expand Down Expand Up @@ -514,6 +515,7 @@ public boolean configureServer(WebSession webSession, Map<String, Object> params
adminName = curUser == null ? null : curUser.getUserId();
adminPassword = null;
}
List<AuthInfo> authInfos = new ArrayList<>();
List<WebAuthInfo> authInfoList = webSession.getAllAuthInfo();
if (CommonUtils.isEmpty(adminName)) {
// Try to get admin name from existing authentications (first one)
Expand All @@ -524,6 +526,11 @@ public boolean configureServer(WebSession webSession, Map<String, Object> params
if (CommonUtils.isEmpty(adminName)) {
adminName = CBConstants.DEFAULT_ADMIN_NAME;
}
for (WebAuthInfo webAuthInfo : authInfoList) {
authInfos.add(new AuthInfo(
webAuthInfo.getAuthProviderDescriptor().getId(),
webAuthInfo.getUserCredentials()));
}

// Patch configuration by services
for (DBWServiceServerConfigurator wsc : WebServiceRegistry.getInstance().getWebServices(DBWServiceServerConfigurator.class)) {
Expand All @@ -541,7 +548,7 @@ public boolean configureServer(WebSession webSession, Map<String, Object> params
serverURL,
adminName,
adminPassword,
authInfoList,
authInfos,
sessionExpireTime,
appConfig,
webSession
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import io.cloudbeaver.model.app.WebAppConfiguration;
import io.cloudbeaver.model.app.WebAuthApplication;
import io.cloudbeaver.model.app.WebAuthConfiguration;
import io.cloudbeaver.model.session.WebAuthInfo;
import io.cloudbeaver.registry.WebAuthProviderDescriptor;
import io.cloudbeaver.registry.WebAuthProviderRegistry;
import io.cloudbeaver.registry.WebMetaParametersRegistry;
Expand Down Expand Up @@ -2625,7 +2624,7 @@ public void shutdown() {
public void finishConfiguration(
@NotNull String adminName,
@Nullable String adminPassword,
@NotNull List<WebAuthInfo> authInfoList
@NotNull List<AuthInfo> authInfoList
) throws DBException {
database.finishConfiguration(adminName, adminPassword, authInfoList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.gson.GsonBuilder;
import io.cloudbeaver.auth.provider.local.LocalAuthProviderConstants;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.model.session.WebAuthInfo;
import io.cloudbeaver.registry.WebAuthProviderDescriptor;
import io.cloudbeaver.registry.WebAuthProviderRegistry;
import io.cloudbeaver.utils.WebAppUtils;
Expand All @@ -32,6 +31,7 @@
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBConstants;
import org.jkiss.dbeaver.model.auth.AuthInfo;
import org.jkiss.dbeaver.model.connection.DBPDriver;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCTransaction;
Expand Down Expand Up @@ -246,7 +246,7 @@ protected PoolingDataSource<PoolableConnection> initConnectionPool(
public void finishConfiguration(
@NotNull String adminName,
@Nullable String adminPassword,
@NotNull List<WebAuthInfo> authInfoList
@NotNull List<AuthInfo> authInfoList
) throws DBException {
if (!application.isConfigurationMode()) {
throw new DBException("Database is already configured");
Expand All @@ -264,12 +264,11 @@ public void finishConfiguration(
createAdminUser(adminName, adminPassword);

// Associate all auth credentials with admin user
for (WebAuthInfo ai : authInfoList) {
for (AuthInfo ai : authInfoList) {
if (!ai.getAuthProvider().equals(LocalAuthProviderConstants.PROVIDER_ID)) {
WebAuthProviderDescriptor authProvider = ai.getAuthProviderDescriptor();
Map<String, Object> userCredentials = ai.getUserCredentials();
if (!CommonUtils.isEmpty(userCredentials)) {
adminSecurityController.setUserCredentials(adminName, authProvider.getId(), userCredentials);
adminSecurityController.setUserCredentials(adminName, ai.getAuthProvider(), userCredentials);
}
}
}
Expand Down

0 comments on commit 98197c8

Please sign in to comment.