Skip to content

Commit

Permalink
Merge branch 'devel' into CB-4779-grid-perfomance
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgeniaBzzz authored Feb 29, 2024
2 parents a41737f + 62510fe commit 5f77c8e
Show file tree
Hide file tree
Showing 189 changed files with 1,241 additions and 564 deletions.
4 changes: 2 additions & 2 deletions server/bundles/io.cloudbeaver.model/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Bundle-ManifestVersion: 2
Bundle-Vendor: DBeaver Corp
Bundle-Name: Cloudbeaver Web Model
Bundle-SymbolicName: io.cloudbeaver.model;singleton:=true
Bundle-Version: 1.0.47.qualifier
Bundle-Release-Date: 20240219
Bundle-Version: 1.0.48.qualifier
Bundle-Release-Date: 20240304
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Expand Down
2 changes: 1 addition & 1 deletion server/bundles/io.cloudbeaver.model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<relativePath>../</relativePath>
</parent>
<artifactId>io.cloudbeaver.model</artifactId>
<version>1.0.47-SNAPSHOT</version>
<version>1.0.48-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ public synchronized boolean updateSMSession(SMAuthInfo smAuthInfo) throws DBExce
public synchronized void refreshUserData() {
try {
userContext.refreshPermissions();
userContext.refreshAccessibleProjects();
if (userContext.isAuthorizedInSecurityManager()) {
userContext.refreshAccessibleProjects();
}
} catch (DBException e) {
addSessionError(e);
log.error("Error refreshing accessible projects", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ public WebSession(
this.lastAccessTime = this.createTime;
setLocale(CommonUtils.toString(httpSession.getAttribute(ATTR_LOCALE), this.locale));
this.sessionHandlers = sessionHandlers;
//force authorization of anonymous session to avoid access error,
//because before authorization could be called by any request,
//but now 'updateInfo' is called only in special requests,
//and the order of requests is not guaranteed.
//look at CB-4747
refreshSessionAuth();
}

@Override
Expand Down Expand Up @@ -521,6 +527,7 @@ public synchronized void updateInfo(
HttpServletRequest request,
HttpServletResponse response
) throws DBWebException {
log.debug("Update session lifetime " + getSessionId() + " for user " + getUserId());
touchSession();
HttpSession httpSession = request.getSession();
this.lastRemoteAddr = request.getRemoteAddr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@
import org.jkiss.utils.CommonUtils;

import java.nio.file.Path;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;

public class WebAppUtils {
private static final Log log = Log.getLog(WebAppUtils.class);
Expand Down Expand Up @@ -224,4 +221,40 @@ public static WebProjectImpl getProjectById(WebSession webSession, String projec
return project;
}

public static Map<String, Object> flattenMap(Map<String, Object> nestedMap) {
Map<String, Object> result = new LinkedHashMap<>();
flattenMapHelper(nestedMap, result, "");
return result;
}

private static void flattenMapHelper(Map<String, Object> nestedMap, Map<String, Object> result, String prefix) {
for (Map.Entry<String, Object> entry : nestedMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
flattenResult(result, prefix, key, value);
}
}

private static void flattenResult(Map<String, Object> result, String prefix, String key, Object value) {
if (value instanceof Map) {
flattenMapHelper((Map<String, Object>) value, result, prefix + key + ".");
} else if (value instanceof Object[]) {
flattenArray((Object[]) value, result, prefix + key + ".");
} else {
String fullKey = prefix + key;
if (!result.containsKey(fullKey)) {
result.put(fullKey, value);
}
}
}

private static void flattenArray(Object[] array, Map<String, Object> result, String prefix) {
for (int i = 0; i < array.length; i++) {
String key = String.valueOf(i);
Object value = array[i];

flattenResult(result, prefix, key, value);
}
}

}
4 changes: 2 additions & 2 deletions server/bundles/io.cloudbeaver.product.ce/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Bundle-ManifestVersion: 2
Bundle-Vendor: DBeaver Corp
Bundle-Name: Cloudbeaver Community Product
Bundle-SymbolicName: io.cloudbeaver.product.ce;singleton:=true
Bundle-Version: 23.3.5.qualifier
Bundle-Release-Date: 20240219
Bundle-Version: 24.0.0.qualifier
Bundle-Release-Date: 20240304
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Expand Down
2 changes: 1 addition & 1 deletion server/bundles/io.cloudbeaver.product.ce/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<relativePath>../</relativePath>
</parent>
<artifactId>io.cloudbeaver.product.ce</artifactId>
<version>23.3.5-SNAPSHOT</version>
<version>24.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Base JDBC drivers
Bundle-SymbolicName: io.cloudbeaver.resources.drivers.base;singleton:=true
Bundle-Version: 1.0.92.qualifier
Bundle-Release-Date: 20240219
Bundle-Version: 1.0.93.qualifier
Bundle-Release-Date: 20240304
Bundle-Vendor: DBeaver Corp
Bundle-ActivationPolicy: lazy
Automatic-Module-Name: io.cloudbeaver.resources.drivers.base
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
<relativePath>../</relativePath>
</parent>
<artifactId>io.cloudbeaver.resources.drivers.base</artifactId>
<version>1.0.92-SNAPSHOT</version>
<version>1.0.93-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
4 changes: 2 additions & 2 deletions server/bundles/io.cloudbeaver.server/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Bundle-ManifestVersion: 2
Bundle-Vendor: DBeaver Corp
Bundle-Name: Cloudbeaver Web Server
Bundle-SymbolicName: io.cloudbeaver.server;singleton:=true
Bundle-Version: 23.3.5.qualifier
Bundle-Release-Date: 20240219
Bundle-Version: 24.0.0.qualifier
Bundle-Release-Date: 20240304
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Bundle-Activator: io.cloudbeaver.server.CBPlatformActivator
Expand Down
2 changes: 1 addition & 1 deletion server/bundles/io.cloudbeaver.server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<relativePath>../</relativePath>
</parent>
<artifactId>io.cloudbeaver.server</artifactId>
<version>23.3.5-SNAPSHOT</version>
<version>24.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,9 @@ extend type Mutation {
closeSession: Boolean

# Refreshes session on server and returns its state
touchSession: Boolean
touchSession: Boolean @deprecated(reason: "use updateSession instead")
# Refreshes session on server and returns session state
updateSession: SessionInfo! @since(version: "24.0.0")

# Refresh session connection list
refreshSessionConnections: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,9 @@ protected void readProductConfiguration(Map<String, Object> serverConfig, Gson g
log.debug("Load product runtime configuration from '" + rtConfig.getAbsolutePath() + "'");
try (Reader reader = new InputStreamReader(new FileInputStream(rtConfig), StandardCharsets.UTF_8)) {
productConfiguration.putAll(JSONUtils.parseMap(gson, reader));
Map<String, Object> flattenConfig = WebAppUtils.flattenMap(this.productConfiguration);
this.productConfiguration.clear();
this.productConfiguration.putAll(flattenConfig);
} catch (Exception e) {
throw new DBException("Error reading product runtime configuration", e);
}
Expand Down Expand Up @@ -1213,6 +1216,11 @@ public boolean isLicenseValid() {
return false;
}

@Nullable
public String getLicenseStatus() {
return null;
}

/**
*
*/
Expand Down Expand Up @@ -1318,7 +1326,8 @@ public Class<? extends DBPPlatformUI> getPlatformUIClass() {
public void saveProductConfiguration(SMCredentialsProvider credentialsProvider, Map<String, Object> productConfiguration) throws DBException {
Map<String, Object> mergedConfig = WebAppUtils.mergeConfigurations(this.productConfiguration, productConfiguration);
writeRuntimeConfig(getRuntimeProductConfigFilePath().toFile(), mergedConfig);
this.productConfiguration.putAll(mergedConfig);
this.productConfiguration.clear();
this.productConfiguration.putAll(WebAppUtils.flattenMap(mergedConfig));
sendConfigChangedEvent(credentialsProvider);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,13 @@ private void checkActionPermissions(@NotNull Method method, @NotNull WebAction w
// Check license
if (application.isLicenseRequired() && !application.isLicenseValid()) {
if (!ArrayUtils.contains(reqPermissions, DBWConstants.PERMISSION_ADMIN)) {
String errorMessage = "Invalid server license";
String licenseStatus = application.getLicenseStatus();
if (licenseStatus != null) {
errorMessage = errorMessage + ": " + licenseStatus;
}
// Only admin permissions are allowed
throw new DBWebExceptionLicenseRequired("Invalid server license");
throw new DBWebExceptionLicenseRequired(errorMessage);
}
}
// Check permissions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,14 @@ WebSession openSession(
@WebAction(authRequired = false)
boolean closeSession(HttpServletRequest request) throws DBWebException;

@Deprecated
@WebAction(authRequired = false)
boolean touchSession(@NotNull HttpServletRequest request, @NotNull HttpServletResponse servletResponse) throws DBWebException;

@WebAction(authRequired = false)
WebSession updateSession(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response)
throws DBWebException;

@WebAction(authRequired = false)
boolean refreshSessionConnections(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response) throws DBWebException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public void bindWiring(DBWBindingContext model) throws DBWebException {
.dataFetcher("closeSession", env -> getService(env).closeSession(GraphQLEndpoint.getServletRequest(env)))
.dataFetcher("touchSession", env -> getService(env).touchSession(
GraphQLEndpoint.getServletRequest(env), GraphQLEndpoint.getServletResponse(env)))
.dataFetcher("updateSession", env -> getService(env).updateSession(
GraphQLEndpoint.getServletRequest(env), GraphQLEndpoint.getServletResponse(env)))
.dataFetcher("refreshSessionConnections", env -> getService(env).refreshSessionConnections(
GraphQLEndpoint.getServletRequest(env), GraphQLEndpoint.getServletResponse(env)))
.dataFetcher("changeSessionLanguage", env -> getService(env).changeSessionLanguage(getWebSession(env), env.getArgument("locale")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.service.core.DBWServiceCore;
import io.cloudbeaver.service.security.SMUtils;
import io.cloudbeaver.service.session.WebSessionManager;
import io.cloudbeaver.utils.WebConnectionFolderUtils;
import io.cloudbeaver.utils.WebDataSourceUtils;
import io.cloudbeaver.utils.WebEventUtils;
Expand Down Expand Up @@ -285,6 +286,14 @@ public boolean touchSession(@NotNull HttpServletRequest request, @NotNull HttpSe
return CBPlatform.getInstance().getSessionManager().touchSession(request, response);
}

@Override
public WebSession updateSession(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response)
throws DBWebException {
WebSessionManager sessionManager = CBPlatform.getInstance().getSessionManager();
sessionManager.touchSession(request, response);
return sessionManager.getWebSession(request, response, true);
}

@Override
public boolean refreshSessionConnections(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response) throws DBWebException {
WebSession session = CBPlatform.getInstance().getSessionManager().getWebSession(request, response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,11 @@ public WebSession getWebSession(@NotNull HttpServletRequest request,
}

@NotNull
public WebSession getWebSession(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, boolean errorOnNoFound) throws DBWebException {
return getWebSession(request, response, true, errorOnNoFound);
}

@NotNull
public WebSession getWebSession(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, boolean updateInfo, boolean errorOnNoFound) throws DBWebException {
public WebSession getWebSession(
@NotNull HttpServletRequest request,
@NotNull HttpServletResponse response,
boolean errorOnNoFound
) throws DBWebException {
HttpSession httpSession = request.getSession(true);
String sessionId = httpSession.getId();
WebSession webSession;
Expand Down Expand Up @@ -139,13 +138,6 @@ public WebSession getWebSession(@NotNull HttpServletRequest request, @NotNull Ht
throw new DBWebException("Unexpected session type: " + baseWebSession.getClass().getName());
}
webSession = (WebSession) baseWebSession;
if (updateInfo) {
// Update only once per request
if (!CommonUtils.toBoolean(request.getAttribute("sessionUpdated"))) {
webSession.updateInfo(request, response);
request.setAttribute("sessionUpdated", true);
}
}
}
}

Expand Down Expand Up @@ -328,16 +320,21 @@ public WebHeadlessSession getHeadlessSession(HttpServletRequest request, boolean
*/
public void sendSessionsStates() {
synchronized (sessionMap) {
for (var session : sessionMap.values()) {
if (session instanceof WebHeadlessSession) {
continue;
}
try {
session.addSessionEvent(new WSSessionStateEvent(session.getRemainingTime(), session.isValid()));
} catch (Exception e) {
log.error("Failed to refresh session state: " + session.getSessionId(), e);
}
}
sessionMap.values()
.parallelStream()
.filter(session -> {
if (session instanceof WebSession webSession) {
return webSession.isAuthorizedInSecurityManager();
}
return false;
})
.forEach(session -> {
try {
session.addSessionEvent(new WSSessionStateEvent(session.getRemainingTime(), session.isValid()));
} catch (Exception e) {
log.error("Failed to refresh session state: " + session.getSessionId(), e);
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Bundle-ManifestVersion: 2
Bundle-Vendor: DBeaver Corp
Bundle-Name: Cloudbeaver Web Service - Administration
Bundle-SymbolicName: io.cloudbeaver.service.admin;singleton:=true
Bundle-Version: 1.0.91.qualifier
Bundle-Release-Date: 20240219
Bundle-Version: 1.0.92.qualifier
Bundle-Release-Date: 20240304
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Expand Down
2 changes: 1 addition & 1 deletion server/bundles/io.cloudbeaver.service.admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<relativePath>../</relativePath>
</parent>
<artifactId>io.cloudbeaver.service.admin</artifactId>
<version>1.0.91-SNAPSHOT</version>
<version>1.0.92-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import io.cloudbeaver.service.DBWServiceServerConfigurator;
import io.cloudbeaver.service.admin.*;
import io.cloudbeaver.service.security.SMUtils;
import io.cloudbeaver.utils.WebAppUtils;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
Expand Down Expand Up @@ -257,7 +258,9 @@ public boolean grantUserTeam(@NotNull WebSession webSession, String user, String
if (grantor == null) {
throw new DBWebException("Cannot grant team in anonymous mode");
}
if (CommonUtils.equalObjects(user, webSession.getUser().getUserId())) {
if (!WebAppUtils.getWebApplication().isDistributed()
&& CommonUtils.equalObjects(user, webSession.getUser().getUserId())
) {
throw new DBWebException("You cannot edit your own permissions");
}
try {
Expand All @@ -281,7 +284,9 @@ public boolean revokeUserTeam(@NotNull WebSession webSession, String user, Strin
if (grantor == null) {
throw new DBWebException("Cannot revoke team in anonymous mode");
}
if (CommonUtils.equalObjects(user, webSession.getUser().getUserId())) {
if (!WebAppUtils.getWebApplication().isDistributed() &&
CommonUtils.equalObjects(user, webSession.getUser().getUserId())
) {
throw new DBWebException("You cannot edit your own permissions");
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Bundle-ManifestVersion: 2
Bundle-Vendor: DBeaver Corp
Bundle-Name: Cloudbeaver Web Service - Authentication
Bundle-SymbolicName: io.cloudbeaver.service.auth;singleton:=true
Bundle-Version: 1.0.91.qualifier
Bundle-Release-Date: 20240219
Bundle-Version: 1.0.92.qualifier
Bundle-Release-Date: 20240304
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Expand Down
Loading

0 comments on commit 5f77c8e

Please sign in to comment.