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 4, 2021
1 parent d374546 commit dbdca91
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 207 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
@@ -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
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 dbdca91

Please sign in to comment.