Compare commits

...
Author SHA1 Message Date
Aleksandr Skoblikov a5a0e422cd CB-4161 validate custom config status 2023-10-25 15:49:48 +02:00
Aleksandr Skoblikov 5332b954e6 CB-4161 auth fix 2023-10-25 15:49:45 +02:00
AlexeyandDaria Marutkina db101b326c Fix/cb-4141/localization (#2071)
* CB-4141 fix: localization

* CB-4141 fix: omit edition in the product full name

---------

Co-authored-by: Daria Marutkina <125263541+dariamarutkina@users.noreply.github.com>
2023-10-20 19:47:55 +03:00
DenisSinelnikov ac3b15ab32 CB-4144. Hot fix blob generate name (#2073) 2023-10-20 15:53:53 +03:00
10 changed files with 76 additions and 16 deletions
@@ -17,7 +17,6 @@
package io.cloudbeaver.model.session;
import io.cloudbeaver.DBWConstants;
import io.cloudbeaver.DBWUserIdentity;
import io.cloudbeaver.DBWebException;
import io.cloudbeaver.auth.SMAuthProviderExternal;
@@ -38,7 +37,6 @@ import org.jkiss.utils.CommonUtils;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -114,15 +112,6 @@ public class WebSessionAuthProcessor {
SMAuthProviderExternal<?> authProviderExternal = authProviderInstance instanceof SMAuthProviderExternal<?> ?
(SMAuthProviderExternal<?>) authProviderInstance : null;
boolean providerDisabled = !isProviderEnabled(providerId);
if (configMode || webSession.hasPermission(DBWConstants.PERMISSION_ADMIN)) {
// 1. Admin can authorize in any providers
// 2. When it authorizes in non-local provider for the first time we force linkUser flag
if (providerDisabled && webSession.getUser() != null) {
linkWithActiveUser = true;
}
}
SMSession authSession;
if (authProviderExternal != null && !configMode && !alreadyLoggedIn) {
@@ -53,7 +53,7 @@ public class WebSQLFileLoaderServlet extends WebServiceServletBase {
private static final String FILE_ID = "fileId";
private static final String FORBIDDEN_CHARACTERS_FILE_REGEX = "(?U)[\\w.$()@ -]+";
private static final String FORBIDDEN_CHARACTERS_FILE_REGEX = "(?U)[$()@ /]+";
private static final Gson gson = new GsonBuilder()
.serializeNulls()
@@ -90,7 +90,7 @@ public class WebSQLFileLoaderServlet extends WebServiceServletBase {
String fileId = JSONUtils.getString(variables, FILE_ID);
if (fileId != null && !fileId.matches(FORBIDDEN_CHARACTERS_FILE_REGEX)) {
if (fileId != null && !fileId.matches(FORBIDDEN_CHARACTERS_FILE_REGEX) && !fileId.startsWith(".")) {
Path file = tempFolder.resolve(fileId);
try {
Files.write(file, request.getPart("fileData").getInputStream().readAllBytes());
@@ -68,6 +68,11 @@ public class WebServiceAuthImpl implements DBWServiceAuth {
if (CommonUtils.isEmpty(providerId)) {
throw new DBWebException("Missing auth provider parameter");
}
WebAuthProviderDescriptor authProviderDescriptor = WebAuthProviderRegistry.getInstance()
.getAuthProvider(providerId);
if (authProviderDescriptor.isTrusted()) {
throw new DBWebException(authProviderDescriptor.getLabel() + " not allowed for authorization via GQL API");
}
if (authParameters == null) {
authParameters = Map.of();
}
@@ -1242,6 +1242,9 @@ public class CBEmbeddedSecurityController<T extends WebAuthApplication>
@Override
public SMAuthInfo authenticateAnonymousUser(@NotNull String appSessionId, @NotNull Map<String, Object> sessionParameters, @NotNull SMSessionType sessionType) throws DBException {
if (!application.getAppConfiguration().isAnonymousAccessEnabled()) {
throw new SMException("Anonymous access restricted");
}
try (Connection dbCon = database.openConnection()) {
try (JDBCTransaction txn = new JDBCTransaction(dbCon)) {
var smSessionId = createSmSession(appSessionId, null, sessionParameters, sessionType, dbCon);
@@ -1277,6 +1280,9 @@ public class CBEmbeddedSecurityController<T extends WebAuthApplication>
@Nullable String authProviderConfigurationId,
@NotNull Map<String, Object> userCredentials
) throws DBException {
if (isProviderDisabled(authProviderId, authProviderConfigurationId)) {
throw new SMException("Unsupported authentication provider: " + authProviderId);
}
var authProgressMonitor = new LoggingProgressMonitor(log);
try (Connection dbCon = database.openConnection()) {
try (JDBCTransaction txn = new JDBCTransaction(dbCon)) {
@@ -2727,9 +2733,17 @@ public class CBEmbeddedSecurityController<T extends WebAuthApplication>
return activeUserCredentials.getUserId();
}
private boolean isProviderEnabled(@NotNull String providerId) {
private boolean isProviderDisabled(@NotNull String providerId, @Nullable String authConfigurationId) {
WebAuthConfiguration appConfiguration = application.getAuthConfiguration();
return appConfiguration.isAuthProviderEnabled(providerId);
if (!appConfiguration.isAuthProviderEnabled(providerId)) {
return true;
}
if (authConfigurationId != null) {
SMAuthProviderCustomConfiguration configuration =
appConfiguration.getAuthProviderConfiguration(authConfigurationId);
return configuration == null || configuration.isDisabled();
}
return false;
}
public void clearOldAuthAttemptInfo() throws DBException {
@@ -0,0 +1,35 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2023 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { Bootstrap, injectable } from '@cloudbeaver/core-di';
import { LocalizationService } from '@cloudbeaver/core-localization';
@injectable()
export class LocaleService extends Bootstrap {
constructor(private readonly localizationService: LocalizationService) {
super();
}
register(): void | Promise<void> {
this.localizationService.addProvider(this.provider.bind(this));
}
load(): void | Promise<void> {}
private async provider(locale: string) {
switch (locale) {
case 'ru':
return (await import('./locales/ru')).default;
case 'it':
return (await import('./locales/it')).default;
case 'zh':
return (await import('./locales/zh')).default;
default:
return (await import('./locales/en')).default;
}
}
}
@@ -0,0 +1,4 @@
export default [
['product_name', 'CE'],
['product_full_name', 'CloudBeaver Community'],
];
@@ -0,0 +1,4 @@
export default [
['product_name', 'CE'],
['product_full_name', 'CloudBeaver Community'],
];
@@ -0,0 +1,4 @@
export default [
['product_name', 'CE'],
['product_full_name', 'CloudBeaver Community'],
];
@@ -0,0 +1,4 @@
export default [
['product_name', 'CE'],
['product_full_name', 'CloudBeaver Community'],
];
@@ -7,6 +7,7 @@
*/
import type { PluginManifest } from '@cloudbeaver/core-di';
import { LocaleService } from './LocaleService';
import { ProductBootstrap } from './ProductBootstrap';
import { ProductConfigService } from './ProductConfigService';
@@ -15,5 +16,5 @@ export const defaultProductManifest: PluginManifest = {
name: 'Default Product',
},
providers: [ProductBootstrap, ProductConfigService],
providers: [ProductBootstrap, ProductConfigService, LocaleService],
};