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 2021/12/14 14:31:04 UTC

[isis] branch master updated: ISIS-2919: remove the non-API interaction/user refinement stuff

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 9d4e696  ISIS-2919: remove the non-API interaction/user refinement stuff
9d4e696 is described below

commit 9d4e6961ea8977c92edc47fbc7d457aced388ce6
Author: andi-huber <ah...@apache.org>
AuthorDate: Tue Dec 14 15:30:52 2021 +0100

    ISIS-2919: remove the non-API interaction/user refinement stuff
    
    - instead, should work fine with the public API we have
---
 .../services/iactnlayer/InteractionContext.java    | 14 +-------
 .../iactnlayer/InteractionContextUtil.java         | 40 ---------------------
 .../manager/AuthenticationManager.java             | 36 +++++--------------
 .../authentication/manager/UserMementoRefiner.java | 42 ++++++++++------------
 4 files changed, 28 insertions(+), 104 deletions(-)

diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/iactnlayer/InteractionContext.java b/api/applib/src/main/java/org/apache/isis/applib/services/iactnlayer/InteractionContext.java
index 41fcaf7..8c28f1f 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/services/iactnlayer/InteractionContext.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/services/iactnlayer/InteractionContext.java
@@ -77,7 +77,7 @@ public class InteractionContext implements Serializable {
      *
      */
     @With @Getter @Builder.Default
-    @NonNull /*final*/ UserMemento user = UserMemento.system();
+    final @NonNull UserMemento user = UserMemento.system();
 
     /**
      * The (programmatically) simulated (or actual) clock.
@@ -161,16 +161,4 @@ public class InteractionContext implements Serializable {
         return mappers.reduce(t -> t, (a,b) -> a.andThen(b)::apply);
     }
 
-    /**
-     * For internal usage, not API.
-     *
-     * <p>
-     *     Instead, use {@link #withUser(UserMemento)}, which honours the value semantics of this class.
-     * </p>
-     *
-     * @param user
-     */
-    void replaceUser(final UserMemento user) {
-        this.user = user;
-    }
 }
diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/iactnlayer/InteractionContextUtil.java b/api/applib/src/main/java/org/apache/isis/applib/services/iactnlayer/InteractionContextUtil.java
deleted file mode 100644
index a4a5e41..0000000
--- a/api/applib/src/main/java/org/apache/isis/applib/services/iactnlayer/InteractionContextUtil.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package org.apache.isis.applib.services.iactnlayer;
-
-import org.apache.isis.applib.services.user.UserMemento;
-
-import lombok.experimental.UtilityClass;
-
-
-@UtilityClass
-public class InteractionContextUtil{
-
-    /**
-     * For internal usage, not formal API.
-     *
-     * <p>
-     *     Instead, use {@link InteractionContext#withUser(UserMemento)}, which honours the value semantics of this class.
-     * </p>
-     */
-    public static void replaceUserIn(InteractionContext interactionContext, UserMemento userMemento) {
-        interactionContext.replaceUser(userMemento);
-    }
-
-}
diff --git a/core/security/src/main/java/org/apache/isis/core/security/authentication/manager/AuthenticationManager.java b/core/security/src/main/java/org/apache/isis/core/security/authentication/manager/AuthenticationManager.java
index feda531..69a1aa4 100644
--- a/core/security/src/main/java/org/apache/isis/core/security/authentication/manager/AuthenticationManager.java
+++ b/core/security/src/main/java/org/apache/isis/core/security/authentication/manager/AuthenticationManager.java
@@ -33,9 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.apache.isis.applib.annotation.PriorityPrecedence;
 import org.apache.isis.applib.exceptions.unrecoverable.NoAuthenticatorException;
 import org.apache.isis.applib.services.iactnlayer.InteractionContext;
-import org.apache.isis.applib.services.iactnlayer.InteractionContextUtil;
 import org.apache.isis.applib.services.iactnlayer.InteractionService;
-import org.apache.isis.applib.services.user.UserMemento;
 import org.apache.isis.applib.util.ToString;
 import org.apache.isis.commons.collections.Can;
 import org.apache.isis.commons.internal.base._Timing;
@@ -106,11 +104,16 @@ public class AuthenticationManager {
             for (val authenticator : compatibleAuthenticators) {
                 val interactionContext = authenticator.authenticate(request, getUnusedRandomCode());
                 if (interactionContext != null) {
-                    val userMemento = refineUserWithin(interactionContext);
+
+                    val userRefined = UserMementoRefiner.refine(
+                            interactionContext.getUser(),
+                            userMementoRefiners);
+                    val interactionContextRefined = interactionContext.withUser(userRefined);
+
                     userByValidationCode.put(
-                            userMemento.getAuthenticationCode(),
-                            userMemento.getName());
-                    return interactionContext;
+                            userRefined.getAuthenticationCode(),
+                            userRefined.getName());
+                    return interactionContextRefined;
                 }
             }
 
@@ -118,27 +121,6 @@ public class AuthenticationManager {
         });
     }
 
-    /**
-     * Iterates over all available {@link UserMementoRefiner}s; if at the end the {@link UserMemento} has been changed,
-     * then replaces (using a private API) the {@link UserMemento} held within {@link InteractionContext}.
-     *
-     * @param interactionContext
-     * @return
-     */
-    @NonNull
-    private UserMemento refineUserWithin(final InteractionContext interactionContext) {
-        val userMementoOrig = interactionContext.getUser();
-        UserMemento userMemento = userMementoOrig;
-        for (UserMementoRefiner refiner : userMementoRefiners) {
-            final UserMemento refined = refiner.refine(userMemento);
-            userMemento = refined != null ? refined : userMemento;
-        }
-        if(userMemento != userMementoOrig) {
-            InteractionContextUtil.replaceUserIn(interactionContext, userMemento);
-        }
-        return interactionContext.getUser();
-    }
-
     private String getUnusedRandomCode() {
 
         val stopWatch = _Timing.now();
diff --git a/core/security/src/main/java/org/apache/isis/core/security/authentication/manager/UserMementoRefiner.java b/core/security/src/main/java/org/apache/isis/core/security/authentication/manager/UserMementoRefiner.java
index 9432cc0..eb094c2 100644
--- a/core/security/src/main/java/org/apache/isis/core/security/authentication/manager/UserMementoRefiner.java
+++ b/core/security/src/main/java/org/apache/isis/core/security/authentication/manager/UserMementoRefiner.java
@@ -18,36 +18,12 @@
  */
 package org.apache.isis.core.security.authentication.manager;
 
-import java.util.List;
-import java.util.Map;
-
 import org.springframework.lang.Nullable;
-import javax.annotation.Priority;
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.context.annotation.Lazy;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
 
-import org.apache.isis.applib.annotation.PriorityPrecedence;
-import org.apache.isis.applib.exceptions.unrecoverable.NoAuthenticatorException;
 import org.apache.isis.applib.services.iactnlayer.InteractionContext;
-import org.apache.isis.applib.services.iactnlayer.InteractionService;
 import org.apache.isis.applib.services.user.UserMemento;
-import org.apache.isis.applib.util.ToString;
-import org.apache.isis.commons.collections.Can;
-import org.apache.isis.commons.internal.base._Timing;
-import org.apache.isis.commons.internal.collections._Maps;
-import org.apache.isis.core.security.authentication.AuthenticationRequest;
-import org.apache.isis.core.security.authentication.Authenticator;
-import org.apache.isis.core.security.authentication.standard.RandomCodeGenerator;
-import org.apache.isis.core.security.authentication.standard.Registrar;
 
-import lombok.Getter;
 import lombok.NonNull;
-import lombok.val;
 
 /**
  * SPI provided by the internal {@link AuthenticationManager}, allowing the {@link UserMemento} representing an
@@ -74,4 +50,22 @@ public interface UserMementoRefiner {
      */
     UserMemento refine(final UserMemento userMemento);
 
+    // -- UTILITY
+
+    public static UserMemento refine(
+            final @NonNull UserMemento userMemento,
+            final @Nullable Iterable<UserMementoRefiner> refiners) {
+
+        if(refiners==null) {
+            return userMemento;
+        }
+
+        UserMemento refined = userMemento;
+        for (UserMementoRefiner refiner : refiners) {
+            final UserMemento next = refiner.refine(refined);
+            refined = next != null ? next : userMemento;
+        }
+        return refined;
+    }
+
 }