You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2021/06/09 10:50:23 UTC
[isis] branch ISIS-2727 updated: ISIS-2727: adds InteractionContext
as parameter to InteractionFactory#openInteraction(Authentication)
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch ISIS-2727
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/ISIS-2727 by this push:
new 795b410 ISIS-2727: adds InteractionContext as parameter to InteractionFactory#openInteraction(Authentication)
795b410 is described below
commit 795b41043a7df11096c07e8186808f7637e0fd68
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Wed Jun 9 11:49:59 2021 +0100
ISIS-2727: adds InteractionContext as parameter to InteractionFactory#openInteraction(Authentication)
... on the way to replacing Authentication with a more abstract concept
---
.../interaction/integration/IsisRequestCycle.java | 2 +-
.../interaction/session/InteractionFactory.java | 8 +++--
.../core/interaction/session/InteractionLayer.java | 8 +++--
.../interaction/session/InteractionTracker.java | 2 +-
.../session/InteractionFactoryDefault.java | 32 +++++++++++---------
.../isis/core/runtimeservices/session/_Xray.java | 2 +-
.../runtimeservices/sudo/SudoServiceDefault.java | 2 +-
.../wrapper/WrapperFactoryDefault.java | 34 +++++++++++-----------
.../ui/auth/VaadinAuthenticationHandler.java | 2 +-
9 files changed, 53 insertions(+), 39 deletions(-)
diff --git a/core/interaction/src/main/java/org/apache/isis/core/interaction/integration/IsisRequestCycle.java b/core/interaction/src/main/java/org/apache/isis/core/interaction/integration/IsisRequestCycle.java
index 01e6a8f..532ac89 100644
--- a/core/interaction/src/main/java/org/apache/isis/core/interaction/integration/IsisRequestCycle.java
+++ b/core/interaction/src/main/java/org/apache/isis/core/interaction/integration/IsisRequestCycle.java
@@ -47,7 +47,7 @@ public class IsisRequestCycle {
authentication.getValidationCode()))
.orElse(authentication);
- isisInteractionFactory.openInteraction(authenticationToUse);
+ isisInteractionFactory.openInteraction(authenticationToUse, authenticationToUse.getInteractionContext());
}
public void onRequestHandlerExecuted() {
diff --git a/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionFactory.java b/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionFactory.java
index d724e20..fa883e3 100644
--- a/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionFactory.java
+++ b/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionFactory.java
@@ -21,6 +21,7 @@ package org.apache.isis.core.interaction.session;
import java.util.concurrent.Callable;
+import org.apache.isis.applib.services.iactnlayer.InteractionContext;
import org.apache.isis.commons.functional.ThrowingRunnable;
import org.apache.isis.core.security.authentication.Authentication;
import org.apache.isis.core.security.authentication.manager.AnonymousInteractionFactory;
@@ -46,7 +47,7 @@ extends AnonymousInteractionFactory {
* If present, reuses the current top level {@link InteractionLayer}, otherwise creates a new
* anonymous one.
*
- * @see #openInteraction(Authentication)
+ * @see #openInteraction(Authentication, InteractionContext)
*/
InteractionLayer openInteraction();
@@ -61,12 +62,15 @@ extends AnonymousInteractionFactory {
*
* @param authentication - the {@link Authentication} to associate with the new top of
* the stack (non-null)
+ * @param interactionContext
*
* @apiNote if the current {@link InteractionLayer} (if any) has an {@link Authentication} that
* equals that of the given one, as an optimization, no new layer is pushed onto the stack;
* instead the current one is returned
*/
- InteractionLayer openInteraction(@NonNull Authentication authentication);
+ InteractionLayer openInteraction(
+ @NonNull Authentication authentication,
+ @NonNull InteractionContext interactionContext);
/**
* @return whether the calling thread is within the context of an open {@link InteractionLayer}
diff --git a/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionLayer.java b/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionLayer.java
index d84f9ac..4c1d706 100644
--- a/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionLayer.java
+++ b/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionLayer.java
@@ -35,7 +35,11 @@ import lombok.NonNull;
public class InteractionLayer {
@Getter private final IsisInteraction interaction;
- @Getter private final Authentication authentication;
+ private final Authentication authentication;
+
+ public Authentication getAuthentication() {
+ return authentication;
+ }
public InteractionLayer(
final @NonNull IsisInteraction interaction,
@@ -49,7 +53,7 @@ public class InteractionLayer {
this.authentication = authentication;
}
- public InteractionContext getExecutionContext() {
+ public InteractionContext getInteractionContext() {
return authentication.getInteractionContext();
}
diff --git a/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionTracker.java b/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionTracker.java
index e9546a4..89c0bef 100644
--- a/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionTracker.java
+++ b/core/interaction/src/main/java/org/apache/isis/core/interaction/session/InteractionTracker.java
@@ -47,7 +47,7 @@ extends InteractionProvider, AuthenticationProvider {
* Returns the {@link InteractionContext} wrapped by the {@link #currentInteractionLayer()} (if within an interaction layer).
*/
default Optional<InteractionContext> currentExecutionContext() {
- return currentInteractionLayer().map(InteractionLayer::getExecutionContext);
+ return currentInteractionLayer().map(InteractionLayer::getInteractionContext);
}
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/session/InteractionFactoryDefault.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/session/InteractionFactoryDefault.java
index 815280a..f767f3f 100644
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/session/InteractionFactoryDefault.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/session/InteractionFactoryDefault.java
@@ -45,6 +45,7 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
import org.apache.isis.applib.annotation.OrderPrecedence;
import org.apache.isis.applib.services.clock.ClockService;
import org.apache.isis.applib.services.iactn.Interaction;
+import org.apache.isis.applib.services.iactnlayer.InteractionContext;
import org.apache.isis.applib.services.inject.ServiceInjector;
import org.apache.isis.applib.util.schema.ChangesDtoUtils;
import org.apache.isis.applib.util.schema.CommandDtoUtils;
@@ -158,19 +159,24 @@ implements
public InteractionLayer openInteraction() {
return currentInteractionLayer()
// or else create an anonymous authentication layer
- .orElseGet(()-> openInteraction(new AnonymousSession()));
+ .orElseGet(()-> {
+ final AnonymousSession authToUse = new AnonymousSession();
+ return openInteraction(authToUse, authToUse.getInteractionContext());
+ });
}
@Override
- public InteractionLayer openInteraction(final @NonNull Authentication authToUse) {
+ public InteractionLayer openInteraction(
+ final @NonNull Authentication authToUse,
+ final @NonNull InteractionContext interactionContextToUse) {
val isisInteraction = getOrCreateIsisInteraction();
// check whether we should reuse any current authenticationLayer,
// that is, if current authentication and authToUse are equal
- val reuseCurrentLayer = currentAuthentication()
- .map(currentAuthentication->Objects.equals(currentAuthentication, authToUse))
+ val reuseCurrentLayer = currentInteraction()
+ .map(currentInteraction -> Objects.equals(currentInteraction, interactionContextToUse))
.orElse(false);
if(reuseCurrentLayer) {
@@ -178,12 +184,12 @@ implements
return interactionLayerStack.get().peek();
}
- val authenticationLayer = new InteractionLayer(isisInteraction, authToUse);
+ val interactionLayer = new InteractionLayer(isisInteraction, authToUse);
- interactionLayerStack.get().push(authenticationLayer);
+ interactionLayerStack.get().push(interactionLayer);
if(isInBaseLayer()) {
- postSessionOpened(isisInteraction);
+ postInteractionOpened(isisInteraction);
}
if(log.isDebugEnabled()) {
@@ -197,7 +203,7 @@ implements
_Xray.newInteractionLayer(interactionLayerStack.get());
}
- return authenticationLayer;
+ return interactionLayer;
}
private IsisInteraction getOrCreateIsisInteraction() {
@@ -209,7 +215,7 @@ implements
@Override
public void closeInteractionLayers() {
- log.debug("about to close the authentication stack (conversation-id={}, total-layers-on-stack={}, {})",
+ log.debug("about to close the interaction stack (conversation-id={}, total-layers-on-stack={}, {})",
interactionId.get(),
interactionLayerStack.get().size(),
_Probe.currentThreadId());
@@ -239,7 +245,7 @@ implements
@NonNull final Callable<R> callable) {
final int stackSizeWhenEntering = interactionLayerStack.get().size();
- openInteraction(authentication);
+ openInteraction(authentication, authentication.getInteractionContext());
try {
serviceInjector.injectServicesInto(callable);
@@ -257,7 +263,7 @@ implements
@NonNull final ThrowingRunnable runnable) {
final int stackSizeWhenEntering = interactionLayerStack.get().size();
- openInteraction(authentication);
+ openInteraction(authentication, authentication.getInteractionContext());
try {
serviceInjector.injectServicesInto(runnable);
@@ -265,9 +271,9 @@ implements
} finally {
closeInteractionLayerStackDownToStackSize(stackSizeWhenEntering);
}
-
}
+
// -- ANONYMOUS EXECUTION
@Override
@@ -310,7 +316,7 @@ implements
return interactionLayerStack.get().size()==1;
}
- private void postSessionOpened(IsisInteraction interaction) {
+ private void postInteractionOpened(IsisInteraction interaction) {
interactionId.set(interaction.getInteractionId());
interactionScopeAwareBeans.forEach(bean->bean.beforeEnteringTransactionalBoundary(interaction));
txBoundaryHandler.onOpen(interaction);
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/session/_Xray.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/session/_Xray.java
index f32cbfc..1da5483 100644
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/session/_Xray.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/session/_Xray.java
@@ -39,7 +39,7 @@ final class _Xray {
// make defensive copies, so can use in another thread
final int authStackSize = afterEnter.size();
val interactionId = afterEnter.peek().getInteraction().getInteractionId();
- val executionContext = afterEnter.peek().getExecutionContext();
+ val executionContext = afterEnter.peek().getInteractionContext();
val threadId = XrayUtil.currentThreadAsMemento();
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/sudo/SudoServiceDefault.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/sudo/SudoServiceDefault.java
index 3cb2aae..2ca9d9d 100644
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/sudo/SudoServiceDefault.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/sudo/SudoServiceDefault.java
@@ -73,7 +73,7 @@ public class SudoServiceDefault implements SudoService {
final @NonNull Callable<T> callable) {
val currentInteractionLayer = interactionTracker.currentInteractionLayerElseFail();
- val currentExecutionContext = currentInteractionLayer.getExecutionContext();
+ val currentExecutionContext = currentInteractionLayer.getInteractionContext();
val sudoExecutionContext = sudoMapper.apply(currentExecutionContext);
val sodoSession = currentInteractionLayer
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/wrapper/WrapperFactoryDefault.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/wrapper/WrapperFactoryDefault.java
index 1cb080a..1b8edc9 100644
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/wrapper/WrapperFactoryDefault.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/wrapper/WrapperFactoryDefault.java
@@ -358,7 +358,12 @@ public class WrapperFactoryDefault implements WrapperFactory {
final AsyncControl<R> asyncControl) {
val interactionLayer = currentInteractionLayer();
- val asyncAuth = authFrom(asyncControl, interactionLayer.getAuthentication());
+ val interactionContext = interactionLayer.getInteractionContext();
+ val asyncInteractionContext = interactionContextFrom(asyncControl, interactionContext);
+
+ val auth = interactionLayer.getAuthentication();
+ val asyncAuth = auth.withInteractionContext(asyncInteractionContext);
+
val command = interactionProviderProvider.get().currentInteractionElseFail().getCommand();
val commandInteractionId = command.getInteractionId();
@@ -393,6 +398,7 @@ public class WrapperFactoryDefault implements WrapperFactory {
val future = executorService.submit(
new ExecCommand<R>(
asyncAuth,
+ asyncInteractionContext,
Propagation.REQUIRES_NEW,
commandDto,
asyncControl.getReturnType(),
@@ -456,23 +462,16 @@ public class WrapperFactoryDefault implements WrapperFactory {
return MemberAndTarget.foundAction(targetAction, currentObjectManager().adapt(mixedIn), method);
}
- private static <R> Authentication authFrom(AsyncControl<R> asyncControl, Authentication auth) {
-
- val executionContext = auth.getInteractionContext();
-
- val newExecutionContext = InteractionContext.builder()
- .clock(Optional.ofNullable(asyncControl.getClock())
- .orElseGet(executionContext::getClock))
- .locale(Optional.ofNullable(asyncControl.getLocale())
- .orElseGet(executionContext::getLocale))
- .timeZone(Optional.ofNullable(asyncControl.getTimeZone())
- .orElseGet(executionContext::getTimeZone))
- .user(Optional.ofNullable(asyncControl.getUser())
- .orElseGet(executionContext::getUser))
- .build();
-
- return auth.withInteractionContext(newExecutionContext);
+ private static <R> InteractionContext interactionContextFrom(
+ final AsyncControl<R> asyncControl,
+ final InteractionContext interactionContext) {
+ return InteractionContext.builder()
+ .clock(Optional.ofNullable(asyncControl.getClock()).orElseGet(interactionContext::getClock))
+ .locale(Optional.ofNullable(asyncControl.getLocale()).orElseGet(interactionContext::getLocale))
+ .timeZone(Optional.ofNullable(asyncControl.getTimeZone()).orElseGet(interactionContext::getTimeZone))
+ .user(Optional.ofNullable(asyncControl.getUser()).orElseGet(interactionContext::getUser))
+ .build();
}
@Data
@@ -588,6 +587,7 @@ public class WrapperFactoryDefault implements WrapperFactory {
private static class ExecCommand<R> implements Callable<R> {
private final Authentication authentication;
+ private final InteractionContext interactionContext;
private final Propagation propagation;
private final CommandDto commandDto;
private final Class<R> returnType;
diff --git a/incubator/viewers/vaadin/ui/src/main/java/org/apache/isis/incubator/viewer/vaadin/ui/auth/VaadinAuthenticationHandler.java b/incubator/viewers/vaadin/ui/src/main/java/org/apache/isis/incubator/viewer/vaadin/ui/auth/VaadinAuthenticationHandler.java
index 9531f68..d942201 100644
--- a/incubator/viewers/vaadin/ui/src/main/java/org/apache/isis/incubator/viewer/vaadin/ui/auth/VaadinAuthenticationHandler.java
+++ b/incubator/viewers/vaadin/ui/src/main/java/org/apache/isis/incubator/viewer/vaadin/ui/auth/VaadinAuthenticationHandler.java
@@ -121,7 +121,7 @@ implements
val authentication = AuthSessionStoreUtil.get().orElse(null);
if(authentication!=null) {
- isisInteractionFactory.openInteraction(authentication);
+ isisInteractionFactory.openInteraction(authentication, authentication.getInteractionContext());
return; // access granted
}
// otherwise redirect to login page