Skip to content

Commit

Permalink
[858] Remove dependencies to Spring Security from the event processors
Browse files Browse the repository at this point in the history
All our representation event processor are connected to Spring Security
while we have no reason to do so. All those dependencies have now been
removed and the code has been simplified.

The SubscriptionManager is now in charge of the canBeDisposedSink of all
the representation event processor which removes both a field and a method
from all the representation event processor

Bug: #858
Signed-off-by: Stéphane Bégaudeau <[email protected]>
  • Loading branch information
sbegaudeau committed Dec 7, 2021
1 parent 3e94423 commit 8f89522
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 211 deletions.
11 changes: 7 additions & 4 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
=== Architectural decision records

=== Deprecation warning
- https://github.com/eclipse-sirius/sirius-components/issues/858[#858] Our dependency to Spring Security will be reduced or eliminated soon. Sirius Components will now longer have any opinion on matters of authentication, authorization, principal management, etc. All those concerns will be out of the scope of the project. It will also be way easier to integrate Sirius Components in a Spring based application since it won't come with this additional requirement

=== Breaking changes
- https://github.com/eclipse-sirius/sirius-components/issues/858[#858] Remove most of the methods of `ISubscriptionManager` since they were not really useful

=== Dependency Update
=== Dependency update

- [core] Switch to Spring Boot 2.6.1
- [core] Switch to GraphQL Java 17.3
Expand All @@ -19,7 +21,8 @@

=== Bug fixes

== v2021.12.0 (Unreleased)

== v2021.12.0

=== Architectural decision records

Expand All @@ -33,13 +36,13 @@
- https://github.com/eclipse-sirius/sirius-components/issues/818[#818] [workbench] The concept of `Selection` will be restructured, as described in the ADR-036. Every part of the code involved in the manipulation of the selection of the workbench will be impacted. This includes concepts as remote as the representation descriptions which are used to computed fields like `kind`. For example, the behavior of the `TreeDescription#getKindProvider` and `NodeDescription#getTargetObjectKindProvider` will have to be updated for all the providers. Failure to update to the new behavior will make the selection fail in the workbench
- [core] The Success parameterless contructor will be removed soon.

=== Breaking Changes
=== Breaking changes

- https://github.com/eclipse-sirius/sirius-components/issues/804[#804] [core] Update the name of our configuration properties. The configuration property `sirius.web.graphql.websocket.allowed.origins` will now be `sirius.components.cors.allowedOriginPatterns` and it will support complex patterns on top of regular origins. The default value will be restored to nothing since it has temporarily been set to `*`. In a development environment, the recommended value would be both patterns `https://localhost:[*]` and `http://localhost:[*]` in order to accept requests from any application hosted on the same machine. The configuration property `org.eclipse.sirius.web.editingContextEventProcessorRegistry.disposeDelay` will now be `sirius.components.editingContext.disposeDelay`. Its default value will be 1s since it is the only realistic option with domain and view support.
- https://github.com/eclipse-sirius/sirius-components/issues/692[#692] [explorer] The explorer view is now more generic and extensible. It can represent arbitrary kinds of tree items, but the tree items supported must be configured for each application.
- https://github.com/eclipse-sirius/sirius-components/issues/700[#700] [core] editingContextId and representationId are no longer UUID but String. Products that rely on sirius-components will be able to have their own ID policy for the editingContextId and representationId.

=== Dependency Update
=== Dependency update

- [core] Switch to Spring Boot 2.5.6

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;

import org.eclipse.sirius.web.core.api.IEditingContext;
import org.eclipse.sirius.web.core.api.IInput;
Expand All @@ -39,11 +38,8 @@
import org.eclipse.sirius.web.spring.collaborative.dto.RenameRepresentationInput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.context.SecurityContextHolder;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Sinks;
import reactor.core.publisher.Sinks.EmitResult;
import reactor.core.publisher.Sinks.Many;
import reactor.core.publisher.Sinks.One;

Expand Down Expand Up @@ -72,8 +68,6 @@ public class DiagramEventProcessor implements IDiagramEventProcessor {

private final IRepresentationRefreshPolicyRegistry representationRefreshPolicyRegistry;

private final Many<Boolean> canBeDisposedSink = Sinks.many().unicast().onBackpressureBuffer();

private final DiagramEventFlux diagramEventFlux;

public DiagramEventProcessor(IEditingContext editingContext, IDiagramContext diagramContext, List<IDiagramEventHandler> diagramEventHandlers, ISubscriptionManager subscriptionManager,
Expand Down Expand Up @@ -182,31 +176,7 @@ public Flux<IPayload> getOutputEvents(IInput input) {
return Flux.merge(
this.diagramEventFlux.getFlux(input),
this.subscriptionManager.getFlux(input)
)
.doOnSubscribe(subscription -> {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
this.subscriptionManager.add(input, username);
this.logger.trace("{} has subscribed to the diagram {} {}", username, this.diagramContext.getDiagram().getId(), this.subscriptionManager); //$NON-NLS-1$
})
.doOnCancel(() -> {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
this.subscriptionManager.remove(UUID.randomUUID(), username);
this.logger.trace("{} has unsubscribed from the diagram {} {}", username, this.diagramContext.getDiagram().getId(), this.subscriptionManager); //$NON-NLS-1$

if (this.subscriptionManager.isEmpty()) {
EmitResult emitResult = this.canBeDisposedSink.tryEmitNext(Boolean.TRUE);
if (emitResult.isFailure()) {
String pattern = "An error has occurred while emitting that the processor can be disposed: {}"; //$NON-NLS-1$
this.logger.warn(pattern, emitResult);
}
}
});
// @formatter:on
}

@Override
public Flux<Boolean> canBeDisposed() {
return this.canBeDisposedSink.asFlux();
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;

import org.eclipse.sirius.web.components.Element;
Expand Down Expand Up @@ -45,7 +44,6 @@
import org.eclipse.sirius.web.spring.collaborative.forms.dto.UpdateWidgetFocusSuccessPayload;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.context.SecurityContextHolder;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -76,8 +74,6 @@ public class FormEventProcessor implements IFormEventProcessor {

private final Many<IPayload> sink = Sinks.many().multicast().directBestEffort();

private final Many<Boolean> canBeDisposedSink = Sinks.many().unicast().onBackpressureBuffer();

private final AtomicReference<Form> currentForm = new AtomicReference<>();

public FormEventProcessor(FormCreationParameters formCreationParameters, List<IFormEventHandler> formEventHandlers, ISubscriptionManager subscriptionManager,
Expand Down Expand Up @@ -181,33 +177,10 @@ public Flux<IPayload> getOutputEvents(IInput input) {
refreshEventFlux,
this.widgetSubscriptionManager.getFlux(input),
this.subscriptionManager.getFlux(input)
)
.doOnSubscribe(subscription -> {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
this.subscriptionManager.add(input, username);
this.logger.trace("{} has subscribed to the form {} {}", username, this.formCreationParameters.getId(), this.subscriptionManager); //$NON-NLS-1$
})
.doOnCancel(() -> {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
this.subscriptionManager.remove(UUID.randomUUID(), username);
this.logger.trace("{} has unsubscribed from the form {} {}", username, this.formCreationParameters.getId(), this.subscriptionManager); //$NON-NLS-1$

if (this.subscriptionManager.isEmpty()) {
EmitResult emitResult = this.canBeDisposedSink.tryEmitNext(Boolean.TRUE);
if (emitResult.isFailure()) {
String pattern = "An error has occurred while emitting that the processor can be disposed: {}"; //$NON-NLS-1$
this.logger.warn(pattern, emitResult);
}
}
});
);
// @formatter:on
}

@Override
public Flux<Boolean> canBeDisposed() {
return this.canBeDisposedSink.asFlux();
}

@Override
public void dispose() {
this.logger.trace("Disposing the form event processor {}", this.formCreationParameters.getId()); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package org.eclipse.sirius.web.spring.collaborative.selection;

import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;

import org.eclipse.sirius.web.core.api.IEditingContext;
Expand All @@ -35,7 +34,6 @@
import org.eclipse.sirius.web.spring.collaborative.selection.dto.SelectionRefreshedEventPayload;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.context.SecurityContextHolder;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -68,8 +66,6 @@ public class SelectionEventProcessor implements ISelectionEventProcessor {

private final Many<IPayload> sink = Sinks.many().multicast().directBestEffort();

private final Many<Boolean> canBeDisposedSink = Sinks.many().unicast().onBackpressureBuffer();

private final AtomicReference<Selection> currentSelection = new AtomicReference<>();

public SelectionEventProcessor(IEditingContext editingContext, SelectionDescription selectionDescription, String id, Object object, ISubscriptionManager subscriptionManager,
Expand Down Expand Up @@ -151,33 +147,10 @@ public Flux<IPayload> getOutputEvents(IInput input) {
return Flux.merge(
refreshEventFlux,
this.subscriptionManager.getFlux(input)
)
.doOnSubscribe(subscription -> {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
this.subscriptionManager.add(input, username);
this.logger.trace("{} has subscribed to the selection {} {}", username, this.id, this.subscriptionManager); //$NON-NLS-1$
})
.doOnCancel(() -> {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
this.subscriptionManager.remove(UUID.randomUUID(), username);
this.logger.trace("{} has unsubscribed from the selection {} {}", username, this.id, this.subscriptionManager); //$NON-NLS-1$

if (this.subscriptionManager.isEmpty()) {
EmitResult emitResult = this.canBeDisposedSink.tryEmitNext(Boolean.TRUE);
if (emitResult.isFailure()) {
String pattern = "An error has occurred while emitting that the processor can be disposed: {}"; //$NON-NLS-1$
this.logger.warn(pattern, emitResult);
}
}
});
);
// @formatter:on
}

@Override
public Flux<Boolean> canBeDisposed() {
return this.canBeDisposedSink.asFlux();
}

@Override
public void dispose() {
this.logger.trace("Disposing the selection event processor {}", this.id); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

Expand All @@ -39,7 +38,6 @@
import org.eclipse.sirius.web.trees.Tree;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.context.SecurityContextHolder;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer;
Expand Down Expand Up @@ -74,8 +72,6 @@ public class TreeEventProcessor implements ITreeEventProcessor {

private final Many<IPayload> sink = Sinks.many().multicast().directBestEffort();

private final Many<Boolean> canBeDisposedSink = Sinks.many().unicast().onBackpressureBuffer();

private final AtomicReference<Tree> currentTree = new AtomicReference<>();

private final Timer timer;
Expand Down Expand Up @@ -193,33 +189,10 @@ public Flux<IPayload> getOutputEvents(IInput input) {
return Flux.merge(
refreshEventFlux,
this.subscriptionManager.getFlux(input)
)
.doOnSubscribe(subscription -> {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
this.subscriptionManager.add(input, username);
this.logger.trace("{} has subscribed to the tree {} {}", username, this.treeCreationParameters.getEditingContext().getId(), this.subscriptionManager); //$NON-NLS-1$
})
.doOnCancel(() -> {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
this.subscriptionManager.remove(UUID.randomUUID(), username);
this.logger.trace("{} has unsubscribed from the tree {} {}", username, this.treeCreationParameters.getEditingContext().getId(), this.subscriptionManager); //$NON-NLS-1$

if (this.subscriptionManager.isEmpty()) {
EmitResult emitResult = this.canBeDisposedSink.tryEmitNext(Boolean.TRUE);
if (emitResult.isFailure()) {
String pattern = "An error has occurred while emitting that the processor can be disposed: {}"; //$NON-NLS-1$
this.logger.warn(pattern, emitResult);
}
}
});
);
// @formatter:on
}

@Override
public Flux<Boolean> canBeDisposed() {
return this.canBeDisposedSink.asFlux();
}

@Override
public void dispose() {
this.logger.trace("Disposing the tree event processor {}", this.treeCreationParameters.getEditingContext().getId()); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import org.eclipse.sirius.web.components.Element;
Expand All @@ -42,7 +41,6 @@
import org.eclipse.sirius.web.validation.render.ValidationRenderer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.context.SecurityContextHolder;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer;
Expand Down Expand Up @@ -77,8 +75,6 @@ public class ValidationEventProcessor implements IValidationEventProcessor {

private final Many<IPayload> sink = Sinks.many().multicast().directBestEffort();

private final Many<Boolean> canBeDisposedSink = Sinks.many().unicast().onBackpressureBuffer();

private final Timer timer;

public ValidationEventProcessor(IEditingContext editingContext, ValidationDescription validationDescription, ValidationContext validationContext,
Expand Down Expand Up @@ -181,33 +177,10 @@ public Flux<IPayload> getOutputEvents(IInput input) {
return Flux.merge(
refreshEventFlux,
this.subscriptionManager.getFlux(input)
)
.doOnSubscribe(subscription -> {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
this.subscriptionManager.add(input, username);
this.logger.trace("{} has subscribed to the validation {} {}", username, this.editingContext.getId(), this.subscriptionManager); //$NON-NLS-1$
})
.doOnCancel(() -> {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
this.subscriptionManager.remove(UUID.randomUUID(), username);
this.logger.trace("{} has unsubscribed from the validation {} {}", username, this.editingContext.getId(), this.subscriptionManager); //$NON-NLS-1$

if (this.subscriptionManager.isEmpty()) {
EmitResult emitResult = this.canBeDisposedSink.tryEmitNext(Boolean.TRUE);
if (emitResult.isFailure()) {
String pattern = "An error has occurred while emitting that the processor can be disposed: {}"; //$NON-NLS-1$
this.logger.warn(pattern, emitResult);
}
}
});
);
// @formatter:on
}

@Override
public Flux<Boolean> canBeDisposed() {
return this.canBeDisposedSink.asFlux();
}

@Override
public void dispose() {
this.logger.trace("Disposing the validation event processor {}", this.editingContext.getId()); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public interface IRepresentationEventProcessor extends IDisposablePublisher {

ISubscriptionManager getSubscriptionManager();

@Override
default Flux<Boolean> canBeDisposed() {
return this.getSubscriptionManager().canBeDisposed();
}

Flux<IPayload> getOutputEvents(IInput input);

/**
Expand Down
Loading

0 comments on commit 8f89522

Please sign in to comment.