You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/12/06 07:59:35 UTC

[isis] branch master updated: ISIS-2464: more mig. notes; also move ThrowingRunnable to commons

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 45711a2  ISIS-2464: more mig. notes; also move ThrowingRunnable to commons
45711a2 is described below

commit 45711a23ab21ca61a298998dd8c350f8f0f0d485
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sun Dec 6 08:59:20 2020 +0100

    ISIS-2464: more mig. notes; also move ThrowingRunnable to commons
---
 .../modules/ROOT/pages/2020/2.0.0-M5/mignotes.adoc |  3 ++
 .../isis/applib/services/sudo/SudoService.java     |  5 ++--
 .../isis/commons/functional/ThrowingRunnable.java  | 34 +++++++++++-----------
 .../core/runtime/iactn/InteractionFactory.java     |  9 ++----
 .../core/runtime/iactn/InteractionTracker.java     |  2 +-
 .../session/InteractionFactoryDefault.java         |  3 +-
 .../runtimeservices/sudo/SudoServiceDefault.java   |  2 +-
 .../wrapper/WrapperFactoryDefault.java             |  2 +-
 .../authentication/AuthenticationContext.java      |  9 ++++++
 .../ui/auth/VaadinAuthenticationHandler.java       |  2 +-
 ...uthenticatedWebSessionForIsis_Authenticate.java |  2 +-
 .../AuthenticatedWebSessionForIsis_SignIn.java     |  2 +-
 ...uthenticatedWebSessionForIsis_TestAbstract.java |  2 +-
 13 files changed, 43 insertions(+), 34 deletions(-)

diff --git a/antora/components/relnotes/modules/ROOT/pages/2020/2.0.0-M5/mignotes.adoc b/antora/components/relnotes/modules/ROOT/pages/2020/2.0.0-M5/mignotes.adoc
index fec17c8..5add8b3 100644
--- a/antora/components/relnotes/modules/ROOT/pages/2020/2.0.0-M5/mignotes.adoc
+++ b/antora/components/relnotes/modules/ROOT/pages/2020/2.0.0-M5/mignotes.adoc
@@ -201,6 +201,9 @@ CommandServiceInternal -> CommandPublisher
 | AuthenticationSessionStrategyDefault (*1*) 
 | AuthenticationStrategyDefault
 
+| AuthenticationSessionTracker
+| AuthenticationContext
+
 | Clock (moved from applib module to fixture-applib module)
 | VirtualClock (introduced)
 
diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/sudo/SudoService.java b/api/applib/src/main/java/org/apache/isis/applib/services/sudo/SudoService.java
index edff67b..ce3817b 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/services/sudo/SudoService.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/services/sudo/SudoService.java
@@ -24,6 +24,7 @@ import java.util.function.UnaryOperator;
 import org.apache.isis.applib.services.iactn.ExecutionContext;
 import org.apache.isis.applib.services.user.RoleMemento;
 import org.apache.isis.applib.services.user.UserService;
+import org.apache.isis.commons.functional.ThrowingRunnable;
 
 import lombok.NonNull;
 
@@ -66,8 +67,8 @@ public interface SudoService {
     // tag::refguide[]
     default void run(                                        // <.>
             final @NonNull UnaryOperator<ExecutionContext> sudoMapper,
-            final @NonNull Runnable runnable) {
-        call(sudoMapper, ()->{runnable.run(); return null;});
+            final @NonNull ThrowingRunnable runnable) {
+        call(sudoMapper, ThrowingRunnable.toCallable(runnable));
     }
 
     // end::refguide[]
diff --git a/core/security/src/main/java/org/apache/isis/core/security/authentication/AuthenticationContext.java b/commons/src/main/java/org/apache/isis/commons/functional/ThrowingRunnable.java
similarity index 57%
copy from core/security/src/main/java/org/apache/isis/core/security/authentication/AuthenticationContext.java
copy to commons/src/main/java/org/apache/isis/commons/functional/ThrowingRunnable.java
index ad0fb21..d52b6d9 100644
--- a/core/security/src/main/java/org/apache/isis/core/security/authentication/AuthenticationContext.java
+++ b/commons/src/main/java/org/apache/isis/commons/functional/ThrowingRunnable.java
@@ -16,27 +16,27 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
+package org.apache.isis.commons.functional;
 
-package org.apache.isis.core.security.authentication;
+import java.util.concurrent.Callable;
 
-import java.util.Optional;
+import lombok.NonNull;
 
-import org.apache.isis.commons.internal.debug._Probe;
-import org.apache.isis.commons.internal.exceptions._Exceptions;
-
-/**
- * @since 2.0
- */
-public interface AuthenticationContext {
-
-    Optional<Authentication> currentAuthentication();
+@FunctionalInterface
+public interface ThrowingRunnable {
+    
+    // -- INTERFACE
+    
+    void run() throws Exception;
+    
+    // -- UTILITY
     
-    default Authentication getAuthenticationElseFail() {
-        return currentAuthentication()
-                .orElseThrow(()->
-                    _Exceptions.illegalState(
-                            "no InteractionSession available on current %s", 
-                            _Probe.currentThreadId()));
+    static Callable<Void> toCallable(final @NonNull ThrowingRunnable runnable) {
+        final Callable<Void> callable = ()->{
+            runnable.run(); 
+            return null;
+        };
+        return callable;
     }
     
 }
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/iactn/InteractionFactory.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/iactn/InteractionFactory.java
index 99d72d2..9b06067 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/iactn/InteractionFactory.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/iactn/InteractionFactory.java
@@ -21,6 +21,7 @@ package org.apache.isis.core.runtime.iactn;
 
 import java.util.concurrent.Callable;
 
+import org.apache.isis.commons.functional.ThrowingRunnable;
 import org.apache.isis.core.security.authentication.Authentication;
 
 import lombok.NonNull;
@@ -34,11 +35,6 @@ import lombok.NonNull;
  */
 public interface InteractionFactory {
 
-    @FunctionalInterface
-    interface ThrowingRunnable {
-        void run() throws Exception;
-    }
-
     /**
      * If present, reuses the current top level {@link AuthenticationLayer}, otherwise creates a new 
      * anonymous one.
@@ -90,8 +86,7 @@ public interface InteractionFactory {
      * @param runnable (non-null)
      */
     default void runAuthenticated(@NonNull Authentication authentication, @NonNull ThrowingRunnable runnable) {
-        final Callable<Void> callable = ()->{runnable.run(); return null;};
-        callAuthenticated(authentication, callable);
+        callAuthenticated(authentication, ThrowingRunnable.toCallable(runnable));
     }
 
     /**
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/iactn/InteractionTracker.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/iactn/InteractionTracker.java
index c6650a8..c4b777a 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/iactn/InteractionTracker.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/iactn/InteractionTracker.java
@@ -46,7 +46,7 @@ extends InteractionContext, AuthenticationContext {
      * request- or test-scoped InteractionSession's stack*/
     Optional<AuthenticationLayer> currentAuthenticationLayer();
     
-    default AuthenticationLayer currentInteractionLayerElseFail() {
+    default AuthenticationLayer currentAuthenticationLayerElseFail() {
         return currentAuthenticationLayer()
         .orElseThrow(()->_Exceptions.illegalState("No InteractionSession available on current thread"));
     }
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 2f3ba67..4dd98ba 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
@@ -43,6 +43,7 @@ import org.apache.isis.applib.services.inject.ServiceInjector;
 import org.apache.isis.applib.util.schema.ChangesDtoUtils;
 import org.apache.isis.applib.util.schema.CommandDtoUtils;
 import org.apache.isis.applib.util.schema.InteractionDtoUtils;
+import org.apache.isis.commons.functional.ThrowingRunnable;
 import org.apache.isis.commons.internal.concurrent._ConcurrentContext;
 import org.apache.isis.commons.internal.concurrent._ConcurrentTaskList;
 import org.apache.isis.commons.internal.debug._Probe;
@@ -52,8 +53,8 @@ import org.apache.isis.core.metamodel.context.MetaModelContext;
 import org.apache.isis.core.metamodel.services.publishing.CommandPublisher;
 import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
 import org.apache.isis.core.runtime.events.RuntimeEventService;
-import org.apache.isis.core.runtime.iactn.InteractionFactory;
 import org.apache.isis.core.runtime.iactn.AuthenticationLayer;
+import org.apache.isis.core.runtime.iactn.InteractionFactory;
 import org.apache.isis.core.runtime.iactn.InteractionSession;
 import org.apache.isis.core.runtime.iactn.InteractionTracker;
 import org.apache.isis.core.runtime.iactn.IsisInteraction;
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 2fa1274..04ec920 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
@@ -71,7 +71,7 @@ public class SudoServiceDefault implements SudoService {
             final @NonNull UnaryOperator<ExecutionContext> sudoMapper, 
             final @NonNull Callable<T> callable) {
 
-        val currentInteractionLayer = interactionTracker.currentInteractionLayerElseFail();
+        val currentInteractionLayer = interactionTracker.currentAuthenticationLayerElseFail();
         val currentExecutionContext = currentInteractionLayer.getExecutionContext();
         val sudoExecutionContext = sudoMapper.apply(currentExecutionContext);
         
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 e2d2cd8..4f5b3fd 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
@@ -546,7 +546,7 @@ public class WrapperFactoryDefault implements WrapperFactory {
     }
 
     private AuthenticationLayer currentInteractionLayer() {
-        return interactionTracker.currentInteractionLayerElseFail();
+        return interactionTracker.currentAuthenticationLayerElseFail();
     }
 
     private ObjectManager currentObjectManager() {
diff --git a/core/security/src/main/java/org/apache/isis/core/security/authentication/AuthenticationContext.java b/core/security/src/main/java/org/apache/isis/core/security/authentication/AuthenticationContext.java
index ad0fb21..3209ec6 100644
--- a/core/security/src/main/java/org/apache/isis/core/security/authentication/AuthenticationContext.java
+++ b/core/security/src/main/java/org/apache/isis/core/security/authentication/AuthenticationContext.java
@@ -25,10 +25,19 @@ import org.apache.isis.commons.internal.debug._Probe;
 import org.apache.isis.commons.internal.exceptions._Exceptions;
 
 /**
+ * Provides the current thread's {@link Authentication}.  
  * @since 2.0
  */
 public interface AuthenticationContext {
 
+    /**
+     * Optionally provides the current thread's {@link Authentication}, based
+     * on whether there is an open {@link InteractionSession}.
+     * <p>
+     * That is the {@link Authentication} that sits at the top of 
+     * the current thread's {@link InteractionSession}'s 
+     * authentication layer stack.  
+     */
     Optional<Authentication> currentAuthentication();
     
     default Authentication getAuthenticationElseFail() {
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 92b6fe5..f6bd430 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
@@ -29,9 +29,9 @@ import com.vaadin.flow.server.VaadinServiceInitListener;
 
 import org.springframework.stereotype.Component;
 
+import org.apache.isis.commons.functional.ThrowingRunnable;
 import org.apache.isis.core.metamodel.context.MetaModelContext;
 import org.apache.isis.core.runtime.iactn.InteractionFactory;
-import org.apache.isis.core.runtime.iactn.InteractionFactory.ThrowingRunnable;
 import org.apache.isis.core.security.authentication.AuthenticationRequest;
 import org.apache.isis.incubator.viewer.vaadin.ui.pages.login.VaadinLoginView;
 
diff --git a/viewers/wicket/viewer/src/test/java/org/apache/isis/viewer/wicket/viewer/integration/AuthenticatedWebSessionForIsis_Authenticate.java b/viewers/wicket/viewer/src/test/java/org/apache/isis/viewer/wicket/viewer/integration/AuthenticatedWebSessionForIsis_Authenticate.java
index 22ef670..977e7a3 100644
--- a/viewers/wicket/viewer/src/test/java/org/apache/isis/viewer/wicket/viewer/integration/AuthenticatedWebSessionForIsis_Authenticate.java
+++ b/viewers/wicket/viewer/src/test/java/org/apache/isis/viewer/wicket/viewer/integration/AuthenticatedWebSessionForIsis_Authenticate.java
@@ -37,10 +37,10 @@ import static org.hamcrest.Matchers.nullValue;
 import org.apache.isis.applib.services.registry.ServiceRegistry;
 import org.apache.isis.applib.services.session.SessionLoggingService;
 import org.apache.isis.commons.collections.Can;
+import org.apache.isis.commons.functional.ThrowingRunnable;
 import org.apache.isis.core.internaltestsupport.jmocking.JUnitRuleMockery2;
 import org.apache.isis.core.runtime.context.IsisAppCommonContext;
 import org.apache.isis.core.runtime.iactn.InteractionFactory;
-import org.apache.isis.core.runtime.iactn.InteractionFactory.ThrowingRunnable;
 import org.apache.isis.core.runtime.iactn.InteractionTracker;
 import org.apache.isis.core.security.authentication.AuthenticationRequest;
 import org.apache.isis.core.security.authentication.AuthenticationRequestPassword;
diff --git a/viewers/wicket/viewer/src/test/java/org/apache/isis/viewer/wicket/viewer/integration/AuthenticatedWebSessionForIsis_SignIn.java b/viewers/wicket/viewer/src/test/java/org/apache/isis/viewer/wicket/viewer/integration/AuthenticatedWebSessionForIsis_SignIn.java
index 6c43314..0c87816 100644
--- a/viewers/wicket/viewer/src/test/java/org/apache/isis/viewer/wicket/viewer/integration/AuthenticatedWebSessionForIsis_SignIn.java
+++ b/viewers/wicket/viewer/src/test/java/org/apache/isis/viewer/wicket/viewer/integration/AuthenticatedWebSessionForIsis_SignIn.java
@@ -35,10 +35,10 @@ import static org.hamcrest.Matchers.is;
 import org.apache.isis.applib.services.registry.ServiceRegistry;
 import org.apache.isis.applib.services.session.SessionLoggingService;
 import org.apache.isis.commons.collections.Can;
+import org.apache.isis.commons.functional.ThrowingRunnable;
 import org.apache.isis.core.internaltestsupport.jmocking.JUnitRuleMockery2;
 import org.apache.isis.core.runtime.context.IsisAppCommonContext;
 import org.apache.isis.core.runtime.iactn.InteractionFactory;
-import org.apache.isis.core.runtime.iactn.InteractionFactory.ThrowingRunnable;
 import org.apache.isis.core.security.authentication.AuthenticationRequest;
 import org.apache.isis.core.security.authentication.AuthenticationRequestPassword;
 import org.apache.isis.core.security.authentication.manager.AuthenticationManager;
diff --git a/viewers/wicket/viewer/src/test/java/org/apache/isis/viewer/wicket/viewer/integration/AuthenticatedWebSessionForIsis_TestAbstract.java b/viewers/wicket/viewer/src/test/java/org/apache/isis/viewer/wicket/viewer/integration/AuthenticatedWebSessionForIsis_TestAbstract.java
index 7a14e45..a168d5c 100644
--- a/viewers/wicket/viewer/src/test/java/org/apache/isis/viewer/wicket/viewer/integration/AuthenticatedWebSessionForIsis_TestAbstract.java
+++ b/viewers/wicket/viewer/src/test/java/org/apache/isis/viewer/wicket/viewer/integration/AuthenticatedWebSessionForIsis_TestAbstract.java
@@ -29,11 +29,11 @@ import org.junit.Rule;
 
 import org.apache.isis.applib.services.registry.ServiceRegistry;
 import org.apache.isis.applib.services.session.SessionLoggingService;
+import org.apache.isis.commons.functional.ThrowingRunnable;
 import org.apache.isis.core.internaltestsupport.jmocking.JUnitRuleMockery2;
 import org.apache.isis.core.internaltestsupport.jmocking.JUnitRuleMockery2.Mode;
 import org.apache.isis.core.runtime.context.IsisAppCommonContext;
 import org.apache.isis.core.runtime.iactn.InteractionFactory;
-import org.apache.isis.core.runtime.iactn.InteractionFactory.ThrowingRunnable;
 import org.apache.isis.core.security.authentication.manager.AuthenticationManager;
 import org.apache.isis.core.security.authentication.singleuser.SingleUserAuthentication;