diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 6becf8c6edd..ad5e9e9fdf7 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -1,5 +1,26 @@ = Changelog +== v2022.02.0 (Unrelease) + +=== 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 + +=== New features + +=== Improvements + +=== Bug fixes + + == v2021.12.0 (Unreleased) === Architectural decision records diff --git a/backend/sirius-web-spring-collaborative-diagrams/src/main/java/org/eclipse/sirius/web/spring/collaborative/diagrams/DiagramEventProcessor.java b/backend/sirius-web-spring-collaborative-diagrams/src/main/java/org/eclipse/sirius/web/spring/collaborative/diagrams/DiagramEventProcessor.java index 37b0c42e635..cef2ecbd3bf 100644 --- a/backend/sirius-web-spring-collaborative-diagrams/src/main/java/org/eclipse/sirius/web/spring/collaborative/diagrams/DiagramEventProcessor.java +++ b/backend/sirius-web-spring-collaborative-diagrams/src/main/java/org/eclipse/sirius/web/spring/collaborative/diagrams/DiagramEventProcessor.java @@ -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; @@ -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; @@ -72,8 +68,6 @@ public class DiagramEventProcessor implements IDiagramEventProcessor { private final IRepresentationRefreshPolicyRegistry representationRefreshPolicyRegistry; - private final Many canBeDisposedSink = Sinks.many().unicast().onBackpressureBuffer(); - private final DiagramEventFlux diagramEventFlux; public DiagramEventProcessor(IEditingContext editingContext, IDiagramContext diagramContext, List diagramEventHandlers, ISubscriptionManager subscriptionManager, @@ -182,31 +176,7 @@ public Flux 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 canBeDisposed() { - return this.canBeDisposedSink.asFlux(); + ); } @Override diff --git a/backend/sirius-web-spring-collaborative-forms/src/main/java/org/eclipse/sirius/web/spring/collaborative/forms/FormEventProcessor.java b/backend/sirius-web-spring-collaborative-forms/src/main/java/org/eclipse/sirius/web/spring/collaborative/forms/FormEventProcessor.java index 0ce807ddbb8..6555905286d 100644 --- a/backend/sirius-web-spring-collaborative-forms/src/main/java/org/eclipse/sirius/web/spring/collaborative/forms/FormEventProcessor.java +++ b/backend/sirius-web-spring-collaborative-forms/src/main/java/org/eclipse/sirius/web/spring/collaborative/forms/FormEventProcessor.java @@ -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; @@ -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; @@ -76,8 +74,6 @@ public class FormEventProcessor implements IFormEventProcessor { private final Many sink = Sinks.many().multicast().directBestEffort(); - private final Many canBeDisposedSink = Sinks.many().unicast().onBackpressureBuffer(); - private final AtomicReference
currentForm = new AtomicReference<>(); public FormEventProcessor(FormCreationParameters formCreationParameters, List formEventHandlers, ISubscriptionManager subscriptionManager, @@ -181,33 +177,10 @@ public Flux 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 canBeDisposed() { - return this.canBeDisposedSink.asFlux(); - } - @Override public void dispose() { this.logger.trace("Disposing the form event processor {}", this.formCreationParameters.getId()); //$NON-NLS-1$ diff --git a/backend/sirius-web-spring-collaborative-selection/src/main/java/org/eclipse/sirius/web/spring/collaborative/selection/SelectionEventProcessor.java b/backend/sirius-web-spring-collaborative-selection/src/main/java/org/eclipse/sirius/web/spring/collaborative/selection/SelectionEventProcessor.java index c0016105f74..34a52a289de 100644 --- a/backend/sirius-web-spring-collaborative-selection/src/main/java/org/eclipse/sirius/web/spring/collaborative/selection/SelectionEventProcessor.java +++ b/backend/sirius-web-spring-collaborative-selection/src/main/java/org/eclipse/sirius/web/spring/collaborative/selection/SelectionEventProcessor.java @@ -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; @@ -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; @@ -68,8 +66,6 @@ public class SelectionEventProcessor implements ISelectionEventProcessor { private final Many sink = Sinks.many().multicast().directBestEffort(); - private final Many canBeDisposedSink = Sinks.many().unicast().onBackpressureBuffer(); - private final AtomicReference currentSelection = new AtomicReference<>(); public SelectionEventProcessor(IEditingContext editingContext, SelectionDescription selectionDescription, String id, Object object, ISubscriptionManager subscriptionManager, @@ -151,33 +147,10 @@ public Flux 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 canBeDisposed() { - return this.canBeDisposedSink.asFlux(); - } - @Override public void dispose() { this.logger.trace("Disposing the selection event processor {}", this.id); //$NON-NLS-1$ diff --git a/backend/sirius-web-spring-collaborative-trees/src/main/java/org/eclipse/sirius/web/spring/collaborative/trees/TreeEventProcessor.java b/backend/sirius-web-spring-collaborative-trees/src/main/java/org/eclipse/sirius/web/spring/collaborative/trees/TreeEventProcessor.java index 5d3d5eea852..be82c5e48c2 100644 --- a/backend/sirius-web-spring-collaborative-trees/src/main/java/org/eclipse/sirius/web/spring/collaborative/trees/TreeEventProcessor.java +++ b/backend/sirius-web-spring-collaborative-trees/src/main/java/org/eclipse/sirius/web/spring/collaborative/trees/TreeEventProcessor.java @@ -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; @@ -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; @@ -74,8 +72,6 @@ public class TreeEventProcessor implements ITreeEventProcessor { private final Many sink = Sinks.many().multicast().directBestEffort(); - private final Many canBeDisposedSink = Sinks.many().unicast().onBackpressureBuffer(); - private final AtomicReference currentTree = new AtomicReference<>(); private final Timer timer; @@ -193,33 +189,10 @@ public Flux 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 canBeDisposed() { - return this.canBeDisposedSink.asFlux(); - } - @Override public void dispose() { this.logger.trace("Disposing the tree event processor {}", this.treeCreationParameters.getEditingContext().getId()); //$NON-NLS-1$ diff --git a/backend/sirius-web-spring-collaborative-validation/src/main/java/org/eclipse/sirius/web/spring/collaborative/validation/ValidationEventProcessor.java b/backend/sirius-web-spring-collaborative-validation/src/main/java/org/eclipse/sirius/web/spring/collaborative/validation/ValidationEventProcessor.java index dc5f8a36735..e9cb11fbbcd 100644 --- a/backend/sirius-web-spring-collaborative-validation/src/main/java/org/eclipse/sirius/web/spring/collaborative/validation/ValidationEventProcessor.java +++ b/backend/sirius-web-spring-collaborative-validation/src/main/java/org/eclipse/sirius/web/spring/collaborative/validation/ValidationEventProcessor.java @@ -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; @@ -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; @@ -77,8 +75,6 @@ public class ValidationEventProcessor implements IValidationEventProcessor { private final Many sink = Sinks.many().multicast().directBestEffort(); - private final Many canBeDisposedSink = Sinks.many().unicast().onBackpressureBuffer(); - private final Timer timer; public ValidationEventProcessor(IEditingContext editingContext, ValidationDescription validationDescription, ValidationContext validationContext, @@ -181,33 +177,10 @@ public Flux 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 canBeDisposed() { - return this.canBeDisposedSink.asFlux(); - } - @Override public void dispose() { this.logger.trace("Disposing the validation event processor {}", this.editingContext.getId()); //$NON-NLS-1$ diff --git a/backend/sirius-web-spring-collaborative/src/main/java/org/eclipse/sirius/web/spring/collaborative/api/IRepresentationEventProcessor.java b/backend/sirius-web-spring-collaborative/src/main/java/org/eclipse/sirius/web/spring/collaborative/api/IRepresentationEventProcessor.java index ca0dd093961..d797e1c74db 100644 --- a/backend/sirius-web-spring-collaborative/src/main/java/org/eclipse/sirius/web/spring/collaborative/api/IRepresentationEventProcessor.java +++ b/backend/sirius-web-spring-collaborative/src/main/java/org/eclipse/sirius/web/spring/collaborative/api/IRepresentationEventProcessor.java @@ -35,6 +35,11 @@ public interface IRepresentationEventProcessor extends IDisposablePublisher { ISubscriptionManager getSubscriptionManager(); + @Override + default Flux canBeDisposed() { + return this.getSubscriptionManager().canBeDisposed(); + } + Flux getOutputEvents(IInput input); /** diff --git a/backend/sirius-web-spring-collaborative/src/main/java/org/eclipse/sirius/web/spring/collaborative/api/ISubscriptionManager.java b/backend/sirius-web-spring-collaborative/src/main/java/org/eclipse/sirius/web/spring/collaborative/api/ISubscriptionManager.java index 8277638b753..b67192d4a33 100644 --- a/backend/sirius-web-spring-collaborative/src/main/java/org/eclipse/sirius/web/spring/collaborative/api/ISubscriptionManager.java +++ b/backend/sirius-web-spring-collaborative/src/main/java/org/eclipse/sirius/web/spring/collaborative/api/ISubscriptionManager.java @@ -12,12 +12,8 @@ *******************************************************************************/ package org.eclipse.sirius.web.spring.collaborative.api; -import java.util.List; -import java.util.UUID; - import org.eclipse.sirius.web.core.api.IInput; import org.eclipse.sirius.web.core.api.IPayload; -import org.eclipse.sirius.web.spring.collaborative.dto.Subscriber; import reactor.core.publisher.Flux; @@ -27,16 +23,11 @@ * @author sbegaudeau */ public interface ISubscriptionManager { - void add(IInput input, String username); - - void remove(UUID correlationId, String username); - - boolean isEmpty(); - - List getSubscribers(); Flux getFlux(IInput input); + Flux canBeDisposed(); + void dispose(); /** @@ -47,25 +38,12 @@ public interface ISubscriptionManager { class NoOp implements ISubscriptionManager { @Override - public void add(IInput input, String username) { - } - - @Override - public void remove(UUID correlationId, String username) { - } - - @Override - public boolean isEmpty() { - return false; - } - - @Override - public List getSubscribers() { - return List.of(); + public Flux getFlux(IInput input) { + return Flux.empty(); } @Override - public Flux getFlux(IInput input) { + public Flux canBeDisposed() { return Flux.empty(); } diff --git a/backend/sirius-web-spring-collaborative/src/main/java/org/eclipse/sirius/web/spring/collaborative/representations/SubscriptionManager.java b/backend/sirius-web-spring-collaborative/src/main/java/org/eclipse/sirius/web/spring/collaborative/representations/SubscriptionManager.java index 559f3a1120e..90bea2a1d1d 100644 --- a/backend/sirius-web-spring-collaborative/src/main/java/org/eclipse/sirius/web/spring/collaborative/representations/SubscriptionManager.java +++ b/backend/sirius-web-spring-collaborative/src/main/java/org/eclipse/sirius/web/spring/collaborative/representations/SubscriptionManager.java @@ -12,18 +12,11 @@ *******************************************************************************/ package org.eclipse.sirius.web.spring.collaborative.representations; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; import org.eclipse.sirius.web.core.api.IInput; import org.eclipse.sirius.web.core.api.IPayload; import org.eclipse.sirius.web.spring.collaborative.api.ISubscriptionManager; -import org.eclipse.sirius.web.spring.collaborative.dto.Subscriber; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,39 +36,32 @@ public class SubscriptionManager implements ISubscriptionManager { private final Many sink = Sinks.many().multicast().directBestEffort(); - private final Map username2subscriptionCount = new ConcurrentHashMap<>(); + private final AtomicInteger subscriptionCount = new AtomicInteger(); - @Override - public void add(IInput input, String username) { - var subscriptionCount = this.username2subscriptionCount.computeIfAbsent(username, name -> new AtomicInteger()); - subscriptionCount.getAndIncrement(); - } - - @Override - public void remove(UUID correlationId, String username) { - var subscriptionCount = this.username2subscriptionCount.computeIfAbsent(username, name -> new AtomicInteger()); - subscriptionCount.updateAndGet(current -> Math.max(0, current - 1)); - } + private final Many canBeDisposedSink = Sinks.many().unicast().onBackpressureBuffer(); @Override - public boolean isEmpty() { - return this.getSubscribers().isEmpty(); - } + public Flux getFlux(IInput input) { + return this.sink.asFlux().doOnSubscribe(subscription -> { + this.subscriptionCount.getAndIncrement(); + this.logger.trace("A new subscription to the representation has occurred {}", this.subscriptionCount.intValue()); //$NON-NLS-1$ + }).doOnCancel(() -> { + this.subscriptionCount.updateAndGet(current -> Math.max(0, current - 1)); + this.logger.trace("A new cancellation to the representation has occurred {}", this.subscriptionCount.intValue()); //$NON-NLS-1$ - @Override - public List getSubscribers() { - // @formatter:off - return this.username2subscriptionCount.entrySet().stream() - .filter(entry -> entry.getValue().intValue() > 0) - .map(Entry::getKey) - .map(Subscriber::new) - .collect(Collectors.toUnmodifiableList()); - // @formatter:on + if (this.subscriptionCount.get() == 0) { + 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); + } + } + }); } @Override - public Flux getFlux(IInput input) { - return this.sink.asFlux(); + public Flux canBeDisposed() { + return this.canBeDisposedSink.asFlux(); } @Override @@ -87,8 +73,4 @@ public void dispose() { } } - @Override - public String toString() { - return this.username2subscriptionCount.toString(); - } }