From 6d8a9b85e4a24b168eff3584e55c635c2c2a5d30 Mon Sep 17 00:00:00 2001 From: Denis Sinelnikov Date: Wed, 18 Oct 2023 20:39:21 +0400 Subject: [PATCH 1/3] CB-4099. Create logic for save comfig and user for CB TE. --- .../src/io/cloudbeaver/model/session/WebAuthInfo.java | 4 ++++ .../src/io/cloudbeaver/server/CBApplication.java | 6 +++--- .../src/io/cloudbeaver/server/CBApplicationCE.java | 5 ++--- .../cloudbeaver/service/admin/impl/WebServiceAdmin.java | 9 ++++++++- .../service/security/CBEmbeddedSecurityController.java | 3 +-- .../io/cloudbeaver/service/security/db/CBDatabase.java | 9 ++++----- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebAuthInfo.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebAuthInfo.java index eefd83a59d..9cb02f32ba 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebAuthInfo.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebAuthInfo.java @@ -157,4 +157,8 @@ public String getUserDomain() { public String getUserName() { return user.getUserId(); } + + public String getAuthProviderConfigurationId() { + return authProviderConfigurationId; + } } diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java index c903d3b7e1..1f3ef9c831 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java @@ -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; @@ -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; @@ -825,7 +825,7 @@ public synchronized void finishConfiguration( @NotNull String newServerURL, @NotNull String adminName, @Nullable String adminPassword, - @NotNull List authInfoList, + @NotNull List authInfoList, long sessionExpireTime, @NotNull CBAppConfig appConfig, @Nullable SMCredentialsProvider credentialsProvider @@ -886,7 +886,7 @@ protected Map readRuntimeConfigurationProperties() throws DBExce protected abstract void finishSecurityServiceConfiguration( @NotNull String adminName, @Nullable String adminPassword, - @NotNull List authInfoList + @NotNull List authInfoList ) throws DBException; public synchronized void flushConfiguration(SMCredentialsProvider credentialsProvider) throws DBException { diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplicationCE.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplicationCE.java index 456970f70b..cfb125e488 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplicationCE.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplicationCE.java @@ -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; @@ -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; @@ -94,7 +93,7 @@ protected void shutdown() { protected void finishSecurityServiceConfiguration( @NotNull String adminName, @Nullable String adminPassword, - @NotNull List authInfoList + @NotNull List authInfoList ) throws DBException { if (securityController instanceof CBEmbeddedSecurityController) { ((CBEmbeddedSecurityController) securityController).finishConfiguration(adminName, adminPassword, authInfoList); diff --git a/server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/impl/WebServiceAdmin.java b/server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/impl/WebServiceAdmin.java index 9a903f9364..294fafee5f 100644 --- a/server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/impl/WebServiceAdmin.java +++ b/server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/impl/WebServiceAdmin.java @@ -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.*; @@ -514,6 +515,7 @@ public boolean configureServer(WebSession webSession, Map params adminName = curUser == null ? null : curUser.getUserId(); adminPassword = null; } + List authInfos = new ArrayList<>(); List authInfoList = webSession.getAllAuthInfo(); if (CommonUtils.isEmpty(adminName)) { // Try to get admin name from existing authentications (first one) @@ -524,6 +526,11 @@ public boolean configureServer(WebSession webSession, Map 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)) { @@ -541,7 +548,7 @@ public boolean configureServer(WebSession webSession, Map params serverURL, adminName, adminPassword, - authInfoList, + authInfos, sessionExpireTime, appConfig, webSession diff --git a/server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/CBEmbeddedSecurityController.java b/server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/CBEmbeddedSecurityController.java index ec5407dc53..c8b1cf7f34 100644 --- a/server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/CBEmbeddedSecurityController.java +++ b/server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/CBEmbeddedSecurityController.java @@ -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; @@ -2583,7 +2582,7 @@ public void shutdown() { public void finishConfiguration( @NotNull String adminName, @Nullable String adminPassword, - @NotNull List authInfoList + @NotNull List authInfoList ) throws DBException { database.finishConfiguration(adminName, adminPassword, authInfoList); } diff --git a/server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/db/CBDatabase.java b/server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/db/CBDatabase.java index 83607ab788..13475c8960 100644 --- a/server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/db/CBDatabase.java +++ b/server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/db/CBDatabase.java @@ -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; @@ -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; @@ -246,7 +246,7 @@ protected PoolingDataSource initConnectionPool( public void finishConfiguration( @NotNull String adminName, @Nullable String adminPassword, - @NotNull List authInfoList + @NotNull List authInfoList ) throws DBException { if (!application.isConfigurationMode()) { throw new DBException("Database is already configured"); @@ -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 userCredentials = ai.getUserCredentials(); if (!CommonUtils.isEmpty(userCredentials)) { - adminSecurityController.setUserCredentials(adminName, authProvider.getId(), userCredentials); + adminSecurityController.setUserCredentials(adminName, ai.getAuthProvider(), userCredentials); } } } From 8ff0f4c6e1d8e4e8055e22f20eab832e549bd80a Mon Sep 17 00:00:00 2001 From: Denis Sinelnikov Date: Thu, 19 Oct 2023 13:06:56 +0400 Subject: [PATCH 2/3] CB-4099. Fixed checkstyle --- .../src/io/cloudbeaver/service/admin/impl/WebServiceAdmin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/impl/WebServiceAdmin.java b/server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/impl/WebServiceAdmin.java index 294fafee5f..47df0055d1 100644 --- a/server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/impl/WebServiceAdmin.java +++ b/server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/impl/WebServiceAdmin.java @@ -526,7 +526,7 @@ public boolean configureServer(WebSession webSession, Map params if (CommonUtils.isEmpty(adminName)) { adminName = CBConstants.DEFAULT_ADMIN_NAME; } - for(WebAuthInfo webAuthInfo : authInfoList) { + for (WebAuthInfo webAuthInfo : authInfoList) { authInfos.add(new AuthInfo( webAuthInfo.getAuthProviderDescriptor().getId(), webAuthInfo.getUserCredentials())); From 32ea8535a6e63b3af26a77bde5382da96aa83fcc Mon Sep 17 00:00:00 2001 From: Denis Sinelnikov Date: Fri, 20 Oct 2023 13:00:12 +0400 Subject: [PATCH 3/3] CB-4099. Refactor after review --- .../src/io/cloudbeaver/model/session/WebAuthInfo.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebAuthInfo.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebAuthInfo.java index 9cb02f32ba..eefd83a59d 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebAuthInfo.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebAuthInfo.java @@ -157,8 +157,4 @@ public String getUserDomain() { public String getUserName() { return user.getUserId(); } - - public String getAuthProviderConfigurationId() { - return authProviderConfigurationId; - } }