Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/devel' into CB-5570-do-not-read-…
Browse files Browse the repository at this point in the history
…all-project-datasources-on-login

# Conflicts:
#	server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java
  • Loading branch information
yagudin10 committed Sep 30, 2024
2 parents 6a5f8a7 + c3c15bf commit b4b8403
Show file tree
Hide file tree
Showing 64 changed files with 393 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,11 @@ public WebSession(
@NotNull WebAuthApplication application,
@NotNull Map<String, DBWSessionHandler> sessionHandlers
) throws DBException {
super(requestInfo.getId(), application);
this.lastAccessTime = this.createTime;
setLocale(CommonUtils.toString(requestInfo.getLocale(), 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();
this(requestInfo.getId(),
CommonUtils.toString(requestInfo.getLocale()),
application,
sessionHandlers
);
updateSessionParameters(requestInfo);
}

Expand All @@ -138,7 +133,7 @@ protected WebSession(
super(id, application);
this.lastAccessTime = this.createTime;
this.sessionHandlers = sessionHandlers;
setLocale(locale);
setLocale(CommonUtils.toString(locale, this.locale));
//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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package io.cloudbeaver.server;

import io.cloudbeaver.WebProjectImpl;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.utils.WebAppUtils;
import org.eclipse.core.runtime.Platform;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.Log;
Expand All @@ -28,8 +28,6 @@
import org.jkiss.dbeaver.model.impl.app.BaseWorkspaceImpl;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
Expand All @@ -48,17 +46,7 @@ public class WebGlobalWorkspace extends BaseWorkspaceImpl {
private WebGlobalProject globalProject;

public WebGlobalWorkspace(DBPPlatform platform) {
super(platform, Path.of(getWorkspaceURI()));
}

@NotNull
private static URI getWorkspaceURI() {
String workspacePath = Platform.getInstanceLocation().getURL().toString();
try {
return new URI(workspacePath);
} catch (URISyntaxException e) {
throw new IllegalStateException("Workspace path is invalid: " + workspacePath, e);
}
super(platform, ((WebApplication) platform.getApplication()).getWorkspaceDirectory());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@
import io.cloudbeaver.model.config.CBAppConfig;
import io.cloudbeaver.model.utils.ConfigurationUtils;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.utils.WebAppUtils;
import org.jkiss.dbeaver.model.connection.DBPDriver;

//TODO move to a separate CBApplication plugin
public class WebDatasourceAccessCheckHandler extends BaseDatasourceAccessCheckHandler {
@Override
protected boolean isDriverDisabled(DBPDriver driver) {
if (!WebAppUtils.getWebApplication().isMultiuser()) {
return false;
}
CBAppConfig config = CBApplication.getInstance().getAppConfiguration();
return !ConfigurationUtils.isDriverEnabled(
driver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ protected void startServer() {

Location instanceLoc = Platform.getInstanceLocation();
try {
if (!instanceLoc.isSet()) {
if (!instanceLoc.isSet()) { // always false?
URL wsLocationURL = new URL(
"file", //$NON-NLS-1$
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class CBPlatformActivator extends WebPlatformActivator {
protected void shutdownPlatform() {
try {
// Dispose core
if (DBWorkbench.getPlatform() instanceof CBPlatform cbPlatform) {
if (DBWorkbench.isPlatformStarted() && DBWorkbench.getPlatform() instanceof CBPlatform cbPlatform) {
cbPlatform.dispose();
}
} catch (Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import io.cloudbeaver.WebServiceUtils;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.registry.WebServiceRegistry;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.server.HttpConstants;
import io.cloudbeaver.service.DBWBindingContext;
import io.cloudbeaver.service.DBWServiceBindingGraphQL;
Expand Down Expand Up @@ -63,6 +61,8 @@ public class GraphQLEndpoint extends HttpServlet {

private static final Log log = Log.getLog(GraphQLEndpoint.class);

private static final boolean DEBUG = true;

private static final String HEADER_ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin";
private static final String HEADER_ACCESS_CONTROL_ALLOW_HEADERS = "Access-Control-Allow-Headers";
private static final String HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS = "Access-Control-Allow-Credentials";
Expand Down Expand Up @@ -255,6 +255,8 @@ private void executeQuery(HttpServletRequest request, HttpServletResponse respon
// }
if (apiCall != null) {
log.debug("API > " + apiCall);
} else if (DEBUG) {
log.debug("API > " + query);
}
}
ExecutionInput executionInput = contextBuilder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
*/
package io.cloudbeaver.service.navigator;

import io.cloudbeaver.WebProjectImpl;
import io.cloudbeaver.WebServiceUtils;
import io.cloudbeaver.model.WebPropertyInfo;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.service.security.SMUtils;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.*;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.navigator.DBNDataSource;
import org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor;
import org.jkiss.dbeaver.model.rm.RMProjectPermission;
import org.jkiss.dbeaver.model.struct.*;
import org.jkiss.dbeaver.model.struct.rdb.DBSCatalog;
import org.jkiss.dbeaver.model.struct.rdb.DBSSchema;
Expand Down Expand Up @@ -91,9 +93,22 @@ public WebPropertyInfo[] getProperties() {

@Property
public WebPropertyInfo[] filterProperties(@Nullable WebPropertyFilter filter) {
if (object instanceof DBPDataSourceContainer container && !isDataSourceEditable(container)) {
// If user cannot edit a connection, then return only name
filter = new WebPropertyFilter();
filter.setFeatures(List.of(DBConstants.PROP_FEATURE_NAME));
}
return WebServiceUtils.getObjectFilteredProperties(session, object, filter);
}

private boolean isDataSourceEditable(@NotNull DBPDataSourceContainer container) {
WebProjectImpl project = session.getProjectById(container.getProject().getId());
if (project == null) {
return false;
}
return SMUtils.hasProjectPermission(session, project.getRMProject(), RMProjectPermission.DATA_SOURCES_EDIT);
}

///////////////////////////////////
// Advanced

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package io.cloudbeaver.service.sql;

import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.utils.WebAppUtils;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
Expand Down Expand Up @@ -58,7 +58,9 @@ class WebSQLQueryDataReceiver implements DBDDataReceiver {
this.contextInfo = contextInfo;
this.dataContainer = dataContainer;
this.dataFormat = dataFormat;
rowLimit = CBApplication.getInstance().getAppConfiguration().getResourceQuota(WebSQLConstants.QUOTA_PROP_ROW_LIMIT);
rowLimit = WebAppUtils.getWebApplication()
.getAppConfiguration()
.getResourceQuota(WebSQLConstants.QUOTA_PROP_ROW_LIMIT);
}

public WebSQLQueryResultSet getResultSet() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
*/
package io.cloudbeaver.service.sql;

import io.cloudbeaver.model.config.CBAppConfig;
import io.cloudbeaver.model.app.WebAppConfiguration;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.registry.WebServiceRegistry;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.utils.CBModelConstants;
import io.cloudbeaver.utils.WebAppUtils;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.data.*;
Expand Down Expand Up @@ -151,9 +151,11 @@ private static Object serializeContentValue(WebSession session, DBDContent value
if (ContentUtils.isTextContent(value)) {
String stringValue = ContentUtils.getContentStringValue(session.getProgressMonitor(), value);
int textPreviewMaxLength = CommonUtils.toInt(
CBApplication.getInstance().getAppConfiguration().getResourceQuota(
WebSQLConstants.QUOTA_PROP_TEXT_PREVIEW_MAX_LENGTH,
WebSQLConstants.TEXT_PREVIEW_MAX_LENGTH));
WebAppUtils.getWebApplication()
.getAppConfiguration()
.getResourceQuota(WebSQLConstants.QUOTA_PROP_TEXT_PREVIEW_MAX_LENGTH),
WebSQLConstants.TEXT_PREVIEW_MAX_LENGTH
);
if (stringValue != null && stringValue.length() > textPreviewMaxLength) {
stringValue = stringValue.substring(0, textPreviewMaxLength);
}
Expand All @@ -164,21 +166,20 @@ private static Object serializeContentValue(WebSession session, DBDContent value
if (binaryValue != null) {
byte[] previewValue = binaryValue;
// gets parameters from the configuration file
CBAppConfig config = CBApplication.getInstance().getAppConfiguration();
WebAppConfiguration config = WebAppUtils.getWebApplication().getAppConfiguration();
// the max length of the text preview
int textPreviewMaxLength = CommonUtils.toInt(
config.getResourceQuota(
WebSQLConstants.QUOTA_PROP_TEXT_PREVIEW_MAX_LENGTH,
WebSQLConstants.TEXT_PREVIEW_MAX_LENGTH));
WebSQLConstants.QUOTA_PROP_TEXT_PREVIEW_MAX_LENGTH), WebSQLConstants.TEXT_PREVIEW_MAX_LENGTH);
if (previewValue.length > textPreviewMaxLength) {
previewValue = Arrays.copyOf(previewValue, textPreviewMaxLength);
}
map.put(WebSQLConstants.ATTR_TEXT, GeneralUtils.convertToString(previewValue, 0, previewValue.length));
// the max length of the binary preview
int binaryPreviewMaxLength = CommonUtils.toInt(
config.getResourceQuota(
WebSQLConstants.QUOTA_PROP_BINARY_PREVIEW_MAX_LENGTH,
WebSQLConstants.BINARY_PREVIEW_MAX_LENGTH));
WebSQLConstants.QUOTA_PROP_BINARY_PREVIEW_MAX_LENGTH),
WebSQLConstants.BINARY_PREVIEW_MAX_LENGTH);
byte[] inlineValue = binaryValue;
if (inlineValue.length > binaryPreviewMaxLength) {
inlineValue = Arrays.copyOf(inlineValue, textPreviewMaxLength);
Expand Down Expand Up @@ -214,9 +215,11 @@ private static Object serializeGeometryValue(DBGeometry value) {
*/
public static Object serializeStringValue(Object value) {
int textPreviewMaxLength = CommonUtils.toInt(
CBApplication.getInstance().getAppConfiguration().getResourceQuota(
WebSQLConstants.QUOTA_PROP_TEXT_PREVIEW_MAX_LENGTH,
WebSQLConstants.TEXT_PREVIEW_MAX_LENGTH));
WebAppUtils.getWebApplication()
.getAppConfiguration()
.getResourceQuota(WebSQLConstants.QUOTA_PROP_TEXT_PREVIEW_MAX_LENGTH),
WebSQLConstants.TEXT_PREVIEW_MAX_LENGTH
);
String stringValue = value.toString();
if (stringValue.length() < textPreviewMaxLength) {
return value.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void migrateConfiguration(
smReverseProxyProviderConfiguration.setProvider(RPAuthProvider.AUTH_PROVIDER);
smReverseProxyProviderConfiguration.setDisplayName("Reverse Proxy");
smReverseProxyProviderConfiguration.setDescription(
"Automatically created provider after changing Reverse Proxy configuration way in 23.3.4 version"
"This provider was created automatically"
);
smReverseProxyProviderConfiguration .setIconURL("");
Map<String, Object> parameters = new HashMap<>();
Expand Down
11 changes: 8 additions & 3 deletions webapp/packages/core-authentication/src/AuthProvidersResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import {
} from '@cloudbeaver/core-resource';
import { ServerConfigResource } from '@cloudbeaver/core-root';
import { type AuthProviderConfigurationInfoFragment, type AuthProviderInfoFragment, GraphQLService } from '@cloudbeaver/core-sdk';
import { isNotNullDefined } from '@cloudbeaver/core-utils';

import { AuthConfigurationsResource } from './AuthConfigurationsResource.js';
import { AuthSettingsService } from './AuthSettingsService.js';

export type AuthProvider = NonNullable<AuthProviderInfoFragment>;
export type AuthProviderConfiguration = NonNullable<AuthProviderConfigurationInfoFragment>;
Expand All @@ -31,8 +31,13 @@ export class AuthProvidersResource extends CachedMapResource<string, AuthProvide
return this.values.filter(provider => provider.configurable);
}

get enabledConfigurableAuthProviders(): AuthProvider[] {
const enabledProviders = new Set(this.serverConfigResource.data?.enabledAuthProviders);

return this.configurable.filter(provider => enabledProviders.has(provider.id));
}

constructor(
private readonly authSettingsService: AuthSettingsService,
private readonly graphQLService: GraphQLService,
private readonly serverConfigResource: ServerConfigResource,
private readonly authConfigurationsResource: AuthConfigurationsResource,
Expand Down Expand Up @@ -64,7 +69,7 @@ export class AuthProvidersResource extends CachedMapResource<string, AuthProvide
}

getEnabledProviders(): AuthProvider[] {
return this.get(resourceKeyList(this.serverConfigResource.enabledAuthProviders)) as AuthProvider[];
return this.get(resourceKeyList(this.serverConfigResource.enabledAuthProviders)).filter(isNotNullDefined);
}

isEnabled(id: string): boolean {
Expand Down
2 changes: 1 addition & 1 deletion webapp/packages/core-blocks/src/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const IconButton: React.FC<IconButtonProps> = observer(function IconButto
const Button = tag ?? ReakitButton;

return (
<Button {...rest} className={s(styles, { iconButton: true }, className)}>
<Button tabIndex={0} {...rest} className={s(styles, { iconButton: true }, className)}>
<div className={s(styles, { iconBox: true })}>
{img && <StaticImage className={s(styles, { staticImage: true })} icon={name} />}
{!img && <Icon className={s(styles, { icon: true })} name={name} viewBox={viewBox} />}
Expand Down
2 changes: 2 additions & 0 deletions webapp/packages/core-blocks/src/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export const Menu = observer<IMenuProps, HTMLButtonElement>(
<MenuButton
key={relativePosition ? 'link' : 'main'}
ref={combinedRef}
tabIndex={0}
className={s(styles, { menuButton: true }, className)}
{...menu}
visible={menuVisible}
Expand Down Expand Up @@ -168,6 +169,7 @@ export const Menu = observer<IMenuProps, HTMLButtonElement>(
<MenuButton
key={relativePosition ? 'link' : 'main'}
ref={combinedRef}
tabIndex={0}
className={s(styles, { menuButton: true }, className)}
{...menu}
visible={menuVisible}
Expand Down
4 changes: 2 additions & 2 deletions webapp/packages/core-blocks/src/Slide/SlideElement.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
display: inline-block;
vertical-align: top;
white-space: normal;
transition: transform cubic-bezier(0.4, 0, 0.2, 1) 0.6s;
transition: transform ease-in-out 0.4s;
transform: translateX(-100%);

&:first-child {
transition: width cubic-bezier(0.4, 0, 0.2, 1) 0.6s;
transition: width ease-in-out 0.4s;
width: 100%;
}
}
Expand Down
7 changes: 4 additions & 3 deletions webapp/packages/core-blocks/src/TextPlaceholder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
* you may not use this file except in compliance with the License.
*/
import { observer } from 'mobx-react-lite';
import type { HTMLAttributes } from 'react';

import { s } from './s.js';
import style from './TextPlaceholder.module.css';
import { useS } from './useS.js';

interface Props {
interface Props extends HTMLAttributes<HTMLDivElement> {
className?: string;
children?: React.ReactNode;
}

export const TextPlaceholder = observer<Props>(function TextPlaceholder({ className, children }) {
export const TextPlaceholder = observer<Props>(function TextPlaceholder({ className, children, ...rest }) {
const styles = useS(style);

return (
<div className={s(styles, { container: true })}>
<div {...rest} className={s(styles, { container: true })}>
<span className={s(styles, { content: true }, className)}>{children}</span>
</div>
);
Expand Down
Loading

0 comments on commit b4b8403

Please sign in to comment.