mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
CB-6102 add event listener filter for a session global project (#3259)
This commit is contained in:
+32
-3
@@ -43,13 +43,17 @@ import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class WebDataSourceRegistryProxy implements DBPDataSourceRegistry, DataSourcePersistentRegistry, DBPDataSourceRegistryCache {
|
||||
/**
|
||||
* Proxy for a global project data source registry.
|
||||
* We need to filter some data sources in case of inaccessibility (not enough permissions).
|
||||
*/
|
||||
public class WebGlobalProjectRegistryProxy implements DBPDataSourceRegistry, DataSourcePersistentRegistry, DBPDataSourceRegistryCache {
|
||||
@NotNull
|
||||
private final DataSourceFilter dataSourceFilter;
|
||||
@NotNull
|
||||
private final DataSourceRegistry<?> dataSourceRegistry;
|
||||
|
||||
public WebDataSourceRegistryProxy(@NotNull DataSourceRegistry<?> dataSourceRegistry, @NotNull DataSourceFilter filter) {
|
||||
public WebGlobalProjectRegistryProxy(@NotNull DataSourceRegistry<?> dataSourceRegistry, @NotNull DataSourceFilter filter) {
|
||||
this.dataSourceRegistry = dataSourceRegistry;
|
||||
this.dataSourceFilter = filter;
|
||||
}
|
||||
@@ -141,7 +145,7 @@ public class WebDataSourceRegistryProxy implements DBPDataSourceRegistry, DataSo
|
||||
|
||||
@Override
|
||||
public void addDataSourceListener(@NotNull DBPEventListener listener) {
|
||||
dataSourceRegistry.addDataSourceListener(listener);
|
||||
dataSourceRegistry.addDataSourceListener(new WebDBPEventListenerProxy(listener));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -387,4 +391,29 @@ public class WebDataSourceRegistryProxy implements DBPDataSourceRegistry, DataSo
|
||||
public void resolveSecrets(DBSSecretController secretController) throws DBException {
|
||||
dataSourceRegistry.resolveSecrets(secretController);
|
||||
}
|
||||
|
||||
/**
|
||||
* Event listener proxy.
|
||||
* For some cases (like creating data source) we should not send event because of accessibility of connection.
|
||||
*/
|
||||
private class WebDBPEventListenerProxy implements DBPEventListener {
|
||||
@NotNull
|
||||
private final DBPEventListener eventListener;
|
||||
|
||||
public WebDBPEventListenerProxy(@NotNull DBPEventListener eventListener) {
|
||||
this.eventListener = eventListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleDataSourceEvent(@NotNull DBPEvent event) {
|
||||
if (event.getAction() == DBPEvent.Action.OBJECT_ADD &&
|
||||
event.getObject() instanceof DBPDataSourceContainer container &&
|
||||
!dataSourceFilter.filter(container)
|
||||
) {
|
||||
// we cannot send event of creating data source connection because it is not accessible for user
|
||||
return;
|
||||
}
|
||||
eventListener.handleDataSourceEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -49,7 +49,7 @@ public class WebSessionGlobalProjectImpl extends WebSessionProjectImpl {
|
||||
@NotNull
|
||||
@Override
|
||||
protected DBPDataSourceRegistry createDataSourceRegistry() {
|
||||
return new WebDataSourceRegistryProxy(
|
||||
return new WebGlobalProjectRegistryProxy(
|
||||
createRegistryWithCredentialsProvider(),
|
||||
this::isDataSourceAccessible
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user