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/causeway.git


The following commit(s) were added to refs/heads/master by this push:
     new e656ce18a7 CAUSEWAY-2968: [Validation] Guard against Members that 
contribute vetoed Domain-Types
e656ce18a7 is described below

commit e656ce18a7983a53b937c87ffd8fe36085a7bd62
Author: andi-huber <[email protected]>
AuthorDate: Sun Apr 30 10:47:15 2023 +0200

    CAUSEWAY-2968: [Validation] Guard against Members that contribute vetoed
    Domain-Types
---
 .../CausewayBeanFactoryPostProcessorForSpring.java |  4 -
 .../beans/CausewayComponentScanInterceptor.java    |  2 +-
 .../config/beans/CausewayDomainObjectScope.java    | 22 +++---
 .../progmodel/ProgrammingModelConstants.java       |  2 +
 .../all/SanityChecksPostProcessor.java             | 90 ++++++++++++++++++++++
 .../dflt/ProgrammingModelFacetsJava11.java         |  2 +
 6 files changed, 105 insertions(+), 17 deletions(-)

diff --git 
a/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayBeanFactoryPostProcessorForSpring.java
 
b/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayBeanFactoryPostProcessorForSpring.java
index fe2ac3abed..e958b089fe 100644
--- 
a/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayBeanFactoryPostProcessorForSpring.java
+++ 
b/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayBeanFactoryPostProcessorForSpring.java
@@ -20,12 +20,8 @@ package org.apache.causeway.core.config.beans;
 
 import java.util.Objects;
 
-import javax.inject.Inject;
 import javax.inject.Named;
-import javax.inject.Provider;
 
-import org.apache.causeway.applib.services.bookmark.BookmarkService;
-import org.apache.causeway.applib.services.iactnlayer.InteractionService;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
 import 
org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
diff --git 
a/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayComponentScanInterceptor.java
 
b/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayComponentScanInterceptor.java
index ab77ff285e..fb18c1d6be 100644
--- 
a/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayComponentScanInterceptor.java
+++ 
b/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayComponentScanInterceptor.java
@@ -30,7 +30,7 @@ import lombok.NonNull;
  *
  * @since 2.0
  */
-public interface CausewayComponentScanInterceptor {
+interface CausewayComponentScanInterceptor {
 
     /**
      * Allows for the given type-meta to be modified before bean-definition 
registration
diff --git 
a/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayDomainObjectScope.java
 
b/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayDomainObjectScope.java
index 2f313d2b48..cbd8993246 100644
--- 
a/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayDomainObjectScope.java
+++ 
b/core/config/src/main/java/org/apache/causeway/core/config/beans/CausewayDomainObjectScope.java
@@ -18,21 +18,19 @@
  */
 package org.apache.causeway.core.config.beans;
 
-import lombok.RequiredArgsConstructor;
-import lombok.extern.log4j.Log4j2;
-
 import java.util.UUID;
 
-import javax.inject.Inject;
-import javax.inject.Provider;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.ObjectFactory;
+import org.springframework.beans.factory.config.Scope;
 
 import org.apache.causeway.applib.services.bookmark.Bookmark;
 import org.apache.causeway.applib.services.bookmark.BookmarkService;
 import org.apache.causeway.applib.services.iactn.Interaction;
 import org.apache.causeway.applib.services.iactnlayer.InteractionService;
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.ObjectFactory;
-import org.springframework.beans.factory.config.Scope;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.log4j.Log4j2;
 
 @RequiredArgsConstructor
 @Log4j2
@@ -41,7 +39,7 @@ class CausewayDomainObjectScope implements Scope {
     private final BeanFactory beanFactory;
 
     @Override
-    public Object get(String name, ObjectFactory<?> objectFactory) {
+    public Object get(final String name, final ObjectFactory<?> objectFactory) 
{
         if (!interactionService().isInInteraction()) {
             throw new IllegalStateException("No Causeway Interaction is 
currently active");
         }
@@ -51,12 +49,12 @@ class CausewayDomainObjectScope implements Scope {
     }
 
     @Override
-    public Object remove(String name) {
+    public Object remove(final String name) {
         throw new UnsupportedOperationException();
     }
 
     @Override
-    public void registerDestructionCallback(String name, Runnable runnable) {
+    public void registerDestructionCallback(final String name, final Runnable 
runnable) {
         if (!interactionService().isInInteraction()) {
             throw new IllegalStateException("No Causeway Interaction is 
currently active");
         }
@@ -64,7 +62,7 @@ class CausewayDomainObjectScope implements Scope {
     }
 
     @Override
-    public Object resolveContextualObject(String key) {
+    public Object resolveContextualObject(final String key) {
         return bookmarkService();
     }
 
diff --git 
a/core/config/src/main/java/org/apache/causeway/core/config/progmodel/ProgrammingModelConstants.java
 
b/core/config/src/main/java/org/apache/causeway/core/config/progmodel/ProgrammingModelConstants.java
index 11d8907dfd..53a7713ff1 100644
--- 
a/core/config/src/main/java/org/apache/causeway/core/config/progmodel/ProgrammingModelConstants.java
+++ 
b/core/config/src/main/java/org/apache/causeway/core/config/progmodel/ProgrammingModelConstants.java
@@ -531,6 +531,8 @@ public final class ProgrammingModelConstants {
                 + "Can use @ParameterTuple only on parameter of a single arg 
action."),
         PARAMETER_TUPLE_TYPE_WITH_AMBIGUOUS_CONSTRUCTORS("${type}#${member}: "
                 + "Tuple type ${patType} referenced by @ParameterTuple 
annotated parameter has no or more than one public constructor."),
+        VETOED_OR_MANAGED_TYPE_NOT_ALLOWED_TO_ENTER_METAMODEL("${type}: has a 
member with either vetoed or managed "
+                + "element-type ${elementType}, which is not allowed"),
         ;
 
         private final String template;
diff --git 
a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/postprocessors/all/SanityChecksPostProcessor.java
 
b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/postprocessors/all/SanityChecksPostProcessor.java
new file mode 100644
index 0000000000..ebdee2e640
--- /dev/null
+++ 
b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/postprocessors/all/SanityChecksPostProcessor.java
@@ -0,0 +1,90 @@
+/*
+ *  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.causeway.core.metamodel.postprocessors.all;
+
+import javax.inject.Inject;
+
+import org.apache.causeway.core.config.progmodel.ProgrammingModelConstants;
+import org.apache.causeway.core.metamodel.context.MetaModelContext;
+import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
+import 
org.apache.causeway.core.metamodel.postprocessors.ObjectSpecificationPostProcessorAbstract;
+import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
+import org.apache.causeway.core.metamodel.spec.feature.ObjectAction;
+import org.apache.causeway.core.metamodel.spec.feature.ObjectActionParameter;
+import org.apache.causeway.core.metamodel.spec.feature.OneToManyAssociation;
+import org.apache.causeway.core.metamodel.spec.feature.OneToOneAssociation;
+import 
org.apache.causeway.core.metamodel.specloader.validator.ValidationFailure;
+
+/**
+ * Checks various preconditions for a sane meta-model.
+ * <ul>
+ * <li>Guard against members that contribute vetoed or managed types.
+ * Those are not allowed as member/return/param.</li>
+ * </ul>
+ */
+public class SanityChecksPostProcessor
+extends ObjectSpecificationPostProcessorAbstract {
+
+    @Inject
+    public SanityChecksPostProcessor(final MetaModelContext mmc) {
+        super(mmc);
+    }
+
+    @Override
+    public void postProcessParameter(final ObjectSpecification 
objectSpecification, final ObjectAction objectAction, final 
ObjectActionParameter parameter) {
+        checkElementType(parameter, objectSpecification, 
parameter.getElementType());
+    }
+
+    @Override
+    public void postProcessAction(final ObjectSpecification 
objectSpecification, final ObjectAction objectAction) {
+        checkElementType(objectAction, objectSpecification, 
objectAction.getElementType());
+    }
+
+    @Override
+    public void postProcessProperty(final ObjectSpecification 
objectSpecification, final OneToOneAssociation prop) {
+        checkElementType(prop, objectSpecification, prop.getElementType());
+    }
+
+    @Override
+    public void postProcessCollection(final ObjectSpecification 
objectSpecification, final OneToManyAssociation coll) {
+        checkElementType(coll, objectSpecification, coll.getElementType());
+    }
+
+    // -- HELPER
+
+    private void checkElementType(
+            final FacetHolder facetHolder,
+            final ObjectSpecification declaringType,
+            final ObjectSpecification elementType) {
+
+        if(elementType == null
+                || elementType.getBeanSort().isManagedBeanAny()
+                || elementType.getBeanSort().isMixin()
+                || elementType.getBeanSort().isVetoed()) {
+
+            ValidationFailure.raiseFormatted(facetHolder,
+                    
ProgrammingModelConstants.Violation.VETOED_OR_MANAGED_TYPE_NOT_ALLOWED_TO_ENTER_METAMODEL
+                        .builder()
+                        .addVariable("type", declaringType.fqcn())
+                        .addVariable("elementType", ""+elementType)
+                        .buildMessage());
+        }
+    }
+
+}
diff --git 
a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/progmodels/dflt/ProgrammingModelFacetsJava11.java
 
b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/progmodels/dflt/ProgrammingModelFacetsJava11.java
index 5f77a0975f..39eb78ed14 100644
--- 
a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/progmodels/dflt/ProgrammingModelFacetsJava11.java
+++ 
b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/progmodels/dflt/ProgrammingModelFacetsJava11.java
@@ -84,6 +84,7 @@ import 
org.apache.causeway.core.metamodel.facets.value.semantics.ValueSemanticsA
 import 
org.apache.causeway.core.metamodel.methods.DomainIncludeAnnotationEnforcesMetamodelContributionValidator;
 import 
org.apache.causeway.core.metamodel.postprocessors.all.CssOnActionFromConfiguredRegexPostProcessor;
 import 
org.apache.causeway.core.metamodel.postprocessors.all.DescribedAsFromTypePostProcessor;
+import 
org.apache.causeway.core.metamodel.postprocessors.all.SanityChecksPostProcessor;
 import 
org.apache.causeway.core.metamodel.postprocessors.all.i18n.SynthesizeObjectNamingPostProcessor;
 import 
org.apache.causeway.core.metamodel.postprocessors.all.i18n.TranslationPostProcessor;
 import 
org.apache.causeway.core.metamodel.postprocessors.allbutparam.authorization.AuthorizationPostProcessor;
@@ -238,6 +239,7 @@ extends ProgrammingModelAbstract {
     private void addPostProcessors() {
 
         val mmc = getMetaModelContext();
+        addPostProcessor(PostProcessingOrder.A1_BUILTIN, new 
SanityChecksPostProcessor(mmc));
 
         // must run before Object nouns are used
         addPostProcessor(PostProcessingOrder.A1_BUILTIN, new 
SynthesizeObjectNamingPostProcessor(mmc));

Reply via email to