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/08/05 22:48:35 UTC
[isis] 01/05: ISIS-2794: fixes entity change property to access
values directly
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch ISIS-2728
in repository https://gitbox.apache.org/repos/asf/isis.git
commit af246519fef7b9b2b2c2fa02883c0fb2b2ec7896
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Thu Aug 5 22:40:25 2021 +0100
ISIS-2794: fixes entity change property to access values directly
... rather than being evaluated as if a user.
This only showed up as a defect while testing with secman, where invoking with InteractionInitiatedBy.USER results in the filter visibility check, in turn causing a query flush. EclipseLink complains of a flush within a flush (RepeatableWriteUnitOfWork#writeChanges). Using InteractionInitiatedBy.FRAMEWORK is the correct approach - we always want to emit the correct values of the property change for auditing, irrespective of whether the end user has access to the records or not
---
.run/SimpleApp.run.xml | 2 +-
.../services/iactnlayer/InteractionContext.java | 4 ---
.../apache/isis/core/config/IsisConfiguration.java | 9 ++----
.../objectlifecycle/ObjectLifecyclePublisher.java | 5 +--
.../repository/RepositoryServiceDefault.java | 13 ++++----
.../AuthenticationManager_authenticators_Test.java | 6 ++--
...rdAuthenticationManager_AuthenticationTest.java | 3 +-
...uthenticatedWebSessionForIsis_Authenticate.java | 13 ++++----
...ticatedWebSessionForIsis_NotYetImplemented.java | 37 ----------------------
.../AuthenticatedWebSessionForIsis_SignIn.java | 9 ++++--
10 files changed, 32 insertions(+), 69 deletions(-)
diff --git a/.run/SimpleApp.run.xml b/.run/SimpleApp.run.xml
index 983ba73..e9d41a7 100644
--- a/.run/SimpleApp.run.xml
+++ b/.run/SimpleApp.run.xml
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
- <configuration default="false" name="SimpleApp" type="Application" factoryName="Application" nameIsGenerated="true">
+ <configuration default="false" name="SimpleApp (JPA)" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="domainapp.webapp.SimpleApp" />
<module name="simpleapp-jpa-webapp" />
<shortenClasspath name="ARGS_FILE" />
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 c7d30f9..fb169ba 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
@@ -29,12 +29,10 @@ import org.apache.isis.applib.services.iactn.Interaction;
import org.apache.isis.applib.services.user.UserMemento;
import lombok.AccessLevel;
-import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
-import lombok.RequiredArgsConstructor;
import lombok.ToString;
import lombok.With;
@@ -45,11 +43,9 @@ import lombok.With;
*/
@Getter
@lombok.experimental.FieldDefaults(makeFinal=false, level= AccessLevel.PRIVATE)
-@AllArgsConstructor
@ToString
@EqualsAndHashCode
@Builder
-@RequiredArgsConstructor
public class InteractionContext implements Serializable {
private static final long serialVersionUID = -220896735209733865L;
diff --git a/core/config/src/main/java/org/apache/isis/core/config/IsisConfiguration.java b/core/config/src/main/java/org/apache/isis/core/config/IsisConfiguration.java
index 3c03bc0..9bd71a1 100644
--- a/core/config/src/main/java/org/apache/isis/core/config/IsisConfiguration.java
+++ b/core/config/src/main/java/org/apache/isis/core/config/IsisConfiguration.java
@@ -1623,13 +1623,8 @@ public class IsisConfiguration {
* This key allows this behaviour to be disabled.
*
* <p>
- * Originally introduced as part of ISIS-1134 (fixing memory leaks in the objectstore)
- * where it was found that the autoflush behaviour was causing a (now unrepeatable)
- * data integrity error (see <a href="https://issues.apache.org/jira/browse/ISIS-1134?focusedCommentId=14500638&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14500638">ISIS-1134 comment</a>, in the isis-module-security.
- * However, that this could be circumvented by removing the call to flush().
- * We don't want to break existing apps that might rely on this behaviour, on the
- * other hand we want to fix the memory leak. Adding this configuration property
- * seems the most prudent way forward.
+ * NOTE: this key is redundant for JPA/EclipseLink, which supports its own auto-flush using
+ * <a href="https://www.eclipse.org/eclipselink/documentation/2.7/jpa/extensions/persistenceproperties_ref.htm#BABDHEEB">eclipselink.persistence-context.flush-mode</a>
* </p>
*/
private boolean disableAutoFlush = false;
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/objectlifecycle/ObjectLifecyclePublisher.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/objectlifecycle/ObjectLifecyclePublisher.java
index aec3a74..873a7a9 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/objectlifecycle/ObjectLifecyclePublisher.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/objectlifecycle/ObjectLifecyclePublisher.java
@@ -24,6 +24,7 @@ import org.apache.isis.applib.services.factory.FactoryService;
import org.apache.isis.applib.services.publishing.spi.EntityPropertyChange;
import org.apache.isis.applib.services.xactn.TransactionId;
import org.apache.isis.commons.collections.Can;
+import org.apache.isis.core.metamodel.consent.InteractionInitiatedBy;
import org.apache.isis.core.metamodel.facets.properties.property.entitychangepublishing.EntityPropertyChangePublishingPolicyFacet;
import org.apache.isis.core.metamodel.objectmanager.ObjectManager;
import org.apache.isis.core.metamodel.spec.ManagedObject;
@@ -86,7 +87,7 @@ public interface ObjectLifecyclePublisher {
property,
PreAndPostValue
.pre(PropertyValuePlaceholder.NEW)
- .withPost(ManagedObjects.UnwrapUtil.single(property.get(entity))))
+ .withPost(ManagedObjects.UnwrapUtil.single(property.get(entity, InteractionInitiatedBy.FRAMEWORK))))
.toEntityPropertyChange(
timestamp,
user,
@@ -121,7 +122,7 @@ public interface ObjectLifecyclePublisher {
entity,
property,
PreAndPostValue
- .pre(ManagedObjects.UnwrapUtil.single(property.get(entity)))
+ .pre(ManagedObjects.UnwrapUtil.single(property.get(entity, InteractionInitiatedBy.FRAMEWORK)))
.withPost(PropertyValuePlaceholder.DELETED))
.toEntityPropertyChange(
timestamp,
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/repository/RepositoryServiceDefault.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/repository/RepositoryServiceDefault.java
index 248bdf1..c157bed 100644
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/repository/RepositoryServiceDefault.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/repository/RepositoryServiceDefault.java
@@ -29,7 +29,6 @@ import java.util.stream.Collectors;
import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.annotation.Priority;
-import javax.inject.Inject;
import javax.inject.Named;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -55,20 +54,22 @@ import org.apache.isis.core.metamodel.spec.ManagedObjects.EntityUtil;
import org.apache.isis.core.metamodel.spec.ManagedObjects.UnwrapUtil;
import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
import lombok.val;
@Service
@Named("isis.runtimeservices.RepositoryServiceDefault")
@Priority(PriorityPrecedence.EARLY)
@Qualifier("Default")
+@RequiredArgsConstructor
//@Log4j2
public class RepositoryServiceDefault implements RepositoryService {
- @Inject private FactoryService factoryService;
- @Inject private WrapperFactory wrapperFactory;
- @Inject private TransactionService transactionService;
- @Inject private IsisConfiguration isisConfiguration;
- @Inject private ObjectManager objectManager;
+ final FactoryService factoryService;
+ final WrapperFactory wrapperFactory;
+ final TransactionService transactionService;
+ final IsisConfiguration isisConfiguration;
+ final ObjectManager objectManager;
private boolean autoFlush;
diff --git a/core/security/src/test/java/org/apache/isis/security/authentication/standard/AuthenticationManager_authenticators_Test.java b/core/security/src/test/java/org/apache/isis/security/authentication/standard/AuthenticationManager_authenticators_Test.java
index 0d67d00..c4be1fc 100644
--- a/core/security/src/test/java/org/apache/isis/security/authentication/standard/AuthenticationManager_authenticators_Test.java
+++ b/core/security/src/test/java/org/apache/isis/security/authentication/standard/AuthenticationManager_authenticators_Test.java
@@ -46,7 +46,8 @@ public class AuthenticationManager_authenticators_Test {
authenticationManager = new AuthenticationManager(
Collections.emptyList(),
new InteractionService_forTesting(),
- new RandomCodeGeneratorDefault());
+ new RandomCodeGeneratorDefault(),
+ Collections.emptyList());
authenticationManager.authenticate(new AuthenticationRequestPassword("foo", "bar"));
}
@@ -58,7 +59,8 @@ public class AuthenticationManager_authenticators_Test {
authenticationManager = new AuthenticationManager(
Collections.singletonList(auth),
new InteractionService_forTesting(),
- new RandomCodeGeneratorDefault());
+ new RandomCodeGeneratorDefault(),
+ Collections.emptyList());
assertThat(authenticationManager.getAuthenticators().size(), is(1));
assertThat(authenticationManager.getAuthenticators().getElseFail(0), is(sameInstance(auth)));
}
diff --git a/core/security/src/test/java/org/apache/isis/security/authentication/standard/StandardAuthenticationManager_AuthenticationTest.java b/core/security/src/test/java/org/apache/isis/security/authentication/standard/StandardAuthenticationManager_AuthenticationTest.java
index e462f8f..741fb39 100644
--- a/core/security/src/test/java/org/apache/isis/security/authentication/standard/StandardAuthenticationManager_AuthenticationTest.java
+++ b/core/security/src/test/java/org/apache/isis/security/authentication/standard/StandardAuthenticationManager_AuthenticationTest.java
@@ -44,7 +44,8 @@ public class StandardAuthenticationManager_AuthenticationTest {
authenticationManager = new AuthenticationManager(
Collections.singletonList(AuthenticatorsForTesting.authenticatorValidForFoo()),
new InteractionService_forTesting(),
- new RandomCodeGeneratorDefault());
+ new RandomCodeGeneratorDefault(),
+ Collections.emptyList());
}
@Test
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 9f10e41..b5a40da 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
@@ -29,6 +29,11 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.nullValue;
+
import org.apache.isis.applib.services.iactnlayer.InteractionLayerTracker;
import org.apache.isis.applib.services.iactnlayer.InteractionService;
import org.apache.isis.applib.services.iactnlayer.ThrowingRunnable;
@@ -46,11 +51,6 @@ import org.apache.isis.core.security.authentication.InteractionContextFactory;
import org.apache.isis.core.security.authentication.manager.AuthenticationManager;
import org.apache.isis.core.security.authentication.standard.RandomCodeGeneratorDefault;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.nullValue;
-
public class AuthenticatedWebSessionForIsis_Authenticate {
@@ -75,7 +75,8 @@ public class AuthenticatedWebSessionForIsis_Authenticate {
authMgr = new AuthenticationManager(
Collections.singletonList(mockAuthenticator),
new InteractionService_forTesting(),
- new RandomCodeGeneratorDefault());
+ new RandomCodeGeneratorDefault(),
+ Collections.emptyList());
context.checking(new Expectations() {
{
diff --git a/viewers/wicket/viewer/src/test/java/org/apache/isis/viewer/wicket/viewer/integration/AuthenticatedWebSessionForIsis_NotYetImplemented.java b/viewers/wicket/viewer/src/test/java/org/apache/isis/viewer/wicket/viewer/integration/AuthenticatedWebSessionForIsis_NotYetImplemented.java
deleted file mode 100644
index cf290e5..0000000
--- a/viewers/wicket/viewer/src/test/java/org/apache/isis/viewer/wicket/viewer/integration/AuthenticatedWebSessionForIsis_NotYetImplemented.java
+++ /dev/null
@@ -1,37 +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.viewer.wicket.viewer.integration;
-
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-
-public class AuthenticatedWebSessionForIsis_NotYetImplemented {
-
- @Before
- public void setUp() throws Exception {
- }
-
- @Ignore("not yet implemented")
- @Test
- public void testIsDebugMode() {
- }
-
-}
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 f050eca..8b886c6 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
@@ -19,9 +19,11 @@
package org.apache.isis.viewer.wicket.viewer.integration;
-import java.util.Collections;
import java.util.Locale;
+import static java.util.Collections.emptyList;
+import static java.util.Collections.singletonList;
+
import org.apache.wicket.request.Request;
import org.jmock.Expectations;
import org.jmock.auto.Mock;
@@ -66,9 +68,10 @@ public class AuthenticatedWebSessionForIsis_SignIn {
@Before
public void setUp() throws Exception {
authMgr = new AuthenticationManager(
- Collections.singletonList(mockAuthenticator),
+ singletonList(mockAuthenticator),
new InteractionService_forTesting(),
- new RandomCodeGeneratorDefault());
+ new RandomCodeGeneratorDefault(),
+ emptyList());
}
@Test