EvaluationContextFactories.java

1
package pro.verron.officestamper.api;
2
3
import org.springframework.expression.*;
4
import org.springframework.expression.spel.SpelEvaluationException;
5
import org.springframework.expression.spel.SpelMessage;
6
import org.springframework.expression.spel.support.*;
7
8
import java.util.ArrayList;
9
10
/// A deprecated class providing factory methods for creating predefined [EvaluationContextFactory] instances.
11
/// The factories are used to create [EvaluationContext] objects with specific configurations for evaluation logic.
12
/// This class has been marked for removal in future versions and should no longer be used, it is planned to move this
13
/// in the core package.
14
@Deprecated(since = "3.4", forRemoval = true) public class EvaluationContextFactories {
15
16
    private EvaluationContextFactories() {
17
        throw new OfficeStamperException("EvaluationContextFactories cannot be instantiated");
18
    }
19
20
    /// Creates a restricted [EvaluationContextFactory] that provides a predefined,
21
    /// limited configuration to ensure security and control during expression evaluation.
22
    /// This factory configures the resulting [EvaluationContext] to disallow certain
23
    /// operations, such as bean resolution and type resolution, which could pose security risks.
24
    ///
25
    /// The resulting context supports access to properties and maps but restricts the
26
    /// use of reflection for method invocation and disables constructor resolution. The factory
27
    /// is particularly suited for scenarios where strict evaluation constraints are necessary
28
    /// to avoid potential misuse or unintended consequences.
29
    ///
30
    /// @return a restricted [EvaluationContextFactory] with controlled behavior and
31
    ///         limited capabilities for evaluating expressions.
32
    /// @deprecated since 3.4, for removal in a future version. The use of this factory is no longer
33
    ///             recommended due to upcoming changes in evaluation context configurations.
34
    @Deprecated(since = "3.4", forRemoval = true)
35
    public static EvaluationContextFactory restrictedFactory() {
36 1 1. restrictedFactory : replaced return value with null for pro/verron/officestamper/api/EvaluationContextFactories::restrictedFactory → KILLED
        return object -> {
37
            var standardEvaluationContext = new StandardEvaluationContext(object);
38
39
            var propertyAccessor = DataBindingPropertyAccessor.forReadWriteAccess();
40
            var mapAccessor = new MapAccessor();
41
            var propertyAccessors = new ArrayList<PropertyAccessor>();
42
            propertyAccessors.add(propertyAccessor);
43
            propertyAccessors.add(mapAccessor);
44 1 1. lambda$restrictedFactory$0 : removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setPropertyAccessors → KILLED
            standardEvaluationContext.setPropertyAccessors(propertyAccessors);
45
46 1 1. lambda$restrictedFactory$0 : removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setConstructorResolvers → SURVIVED
            standardEvaluationContext.setConstructorResolvers(new ArrayList<>());
47
48
            var instanceMethodInvocation = DataBindingMethodResolver.forInstanceMethodInvocation();
49
            var methodResolvers = new ArrayList<MethodResolver>();
50
            methodResolvers.add(instanceMethodInvocation);
51 1 1. lambda$restrictedFactory$0 : removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setMethodResolvers → SURVIVED
            standardEvaluationContext.setMethodResolvers(methodResolvers);
52
53
            BeanResolver beanResolver = (_, _) -> {
54
                throw new AccessException("Bean resolution not supported for security reasons.");
55
            };
56 1 1. lambda$restrictedFactory$0 : removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setBeanResolver → SURVIVED
            standardEvaluationContext.setBeanResolver(beanResolver);
57
58
            TypeLocator typeLocator = typeName -> {
59
                throw new SpelEvaluationException(SpelMessage.TYPE_NOT_FOUND, typeName);
60
            };
61 1 1. lambda$restrictedFactory$0 : removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setTypeLocator → KILLED
            standardEvaluationContext.setTypeLocator(typeLocator);
62
63 1 1. lambda$restrictedFactory$0 : removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setTypeConverter → SURVIVED
            standardEvaluationContext.setTypeConverter(new StandardTypeConverter());
64 1 1. lambda$restrictedFactory$0 : removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setTypeComparator → SURVIVED
            standardEvaluationContext.setTypeComparator(new StandardTypeComparator());
65 1 1. lambda$restrictedFactory$0 : removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setOperatorOverloader → SURVIVED
            standardEvaluationContext.setOperatorOverloader(new StandardOperatorOverloader());
66 1 1. lambda$restrictedFactory$0 : replaced return value with null for pro/verron/officestamper/api/EvaluationContextFactories::lambda$restrictedFactory$0 → KILLED
            return standardEvaluationContext;
67
        };
68
    }
69
70
    /// Creates a permissive [EvaluationContextFactory] that provides a configuration
71
    /// allowing flexible property and map access during evaluation.
72
    ///
73
    /// This factory configures the resulting [EvaluationContext] to include support
74
    /// for reflective property access and map-based property access. It incorporates
75
    /// an ordered list of [PropertyAccessor] implementations, granting enhanced
76
    /// capabilities for resolving properties and accessing data in expressions.
77
    ///
78
    /// The resulting context is designed for scenarios where relaxed evaluation
79
    /// constraints are needed to allow dynamic property and map access within the
80
    /// evaluation process. It may not be suitable for use in security-sensitive
81
    /// contexts due to its permissive nature.
82
    ///
83
    /// @return a permissive [EvaluationContextFactory] configured for flexible property
84
    ///         and map access during evaluation.
85
    /// @deprecated since 3.4, for removal in a future version. The use of this factory is no longer
86
    ///             recommended due to upcoming changes in evaluation context configurations.
87
    @Deprecated(since = "3.4", forRemoval = true)
88
    public static EvaluationContextFactory permissiveFactory() {
89 1 1. permissiveFactory : replaced return value with null for pro/verron/officestamper/api/EvaluationContextFactories::permissiveFactory → KILLED
        return object -> {
90
            var standardEvaluationContext = new StandardEvaluationContext(object);
91
            var reflectivePropertyAccessor = new ReflectivePropertyAccessor();
92
            var mapAccessor = new MapAccessor();
93
            var propertyAccessors = new ArrayList<PropertyAccessor>();
94
            propertyAccessors.add(reflectivePropertyAccessor);
95
            propertyAccessors.add(mapAccessor);
96 1 1. lambda$permissiveFactory$0 : removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setPropertyAccessors → SURVIVED
            standardEvaluationContext.setPropertyAccessors(propertyAccessors);
97 1 1. lambda$permissiveFactory$0 : replaced return value with null for pro/verron/officestamper/api/EvaluationContextFactories::lambda$permissiveFactory$0 → KILLED
            return standardEvaluationContext;
98
        };
99
    }
100
}

Mutations

36

1.1
Location : restrictedFactory
Killed by : pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.FailOnUnresolvedPlaceholderTest]/[test-template:fails(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced return value with null for pro/verron/officestamper/api/EvaluationContextFactories::restrictedFactory → KILLED

44

1.1
Location : lambda$restrictedFactory$0
Killed by : pro.verron.officestamper.test.CustomFunctionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.CustomFunctionTests]/[test-template:trifunctions(pro.verron.officestamper.test.utils.ContextFactory, java.lang.String, java.lang.String)]/[test-template-invocation:#12]
removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setPropertyAccessors → KILLED

46

1.1
Location : lambda$restrictedFactory$0
Killed by : none
removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setConstructorResolvers → SURVIVED
Covering tests

51

1.1
Location : lambda$restrictedFactory$0
Killed by : none
removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setMethodResolvers → SURVIVED
Covering tests

56

1.1
Location : lambda$restrictedFactory$0
Killed by : none
removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setBeanResolver → SURVIVED
Covering tests

61

1.1
Location : lambda$restrictedFactory$0
Killed by : pro.verron.officestamper.test.SpelInjectionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.SpelInjectionTest]/[test-template:spelInjectionTest(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setTypeLocator → KILLED

63

1.1
Location : lambda$restrictedFactory$0
Killed by : none
removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setTypeConverter → SURVIVED
Covering tests

64

1.1
Location : lambda$restrictedFactory$0
Killed by : none
removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setTypeComparator → SURVIVED
Covering tests

65

1.1
Location : lambda$restrictedFactory$0
Killed by : none
removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setOperatorOverloader → SURVIVED
Covering tests

66

1.1
Location : lambda$restrictedFactory$0
Killed by : pro.verron.officestamper.test.SpelInjectionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.SpelInjectionTest]/[test-template:spelInjectionTest(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced return value with null for pro/verron/officestamper/api/EvaluationContextFactories::lambda$restrictedFactory$0 → KILLED

89

1.1
Location : permissiveFactory
Killed by : pro.verron.officestamper.test.SpelInstantiationTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.SpelInstantiationTest]/[test-template:testDateInstantiationAndResolution(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced return value with null for pro/verron/officestamper/api/EvaluationContextFactories::permissiveFactory → KILLED

96

1.1
Location : lambda$permissiveFactory$0
Killed by : none
removed call to org/springframework/expression/spel/support/StandardEvaluationContext::setPropertyAccessors → SURVIVED
Covering tests

97

1.1
Location : lambda$permissiveFactory$0
Killed by : pro.verron.officestamper.test.SpelInstantiationTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.SpelInstantiationTest]/[test-template:testDateInstantiationAndResolution(pro.verron.officestamper.test.utils.ContextFactory)]/[test-template-invocation:#2]
replaced return value with null for pro/verron/officestamper/api/EvaluationContextFactories::lambda$permissiveFactory$0 → KILLED

Active mutators

Tests examined


Report generated by PIT 1.23.1 support