Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Struts-7] Merge master to 7xx 2024-01-20 #850

Merged
merged 47 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
c322aba
WW-5381 Introduce extension point for MethodAccessor
kusalk Dec 29, 2023
32584c3
WW-5382 Fix StrutsInternalTestCase
kusalk Dec 30, 2023
15acd72
WW-5382 Fix stale injections in Dispatcher
kusalk Dec 30, 2023
2024d83
WW-5382 Fix stale bootstrap context on ActionContext
kusalk Dec 30, 2023
96618eb
Bump org.apache.commons:commons-compress from 1.23.0 to 1.25.0
dependabot[bot] Jan 1, 2024
6f1e122
WW-5382 Rework existing Dispatcher tests and base test classes
kusalk Jan 1, 2024
fa5b46c
WW-5382 Add test for Dispatcher reinjection
kusalk Jan 1, 2024
ae71c46
WW-5382 Delete redundant code
kusalk Jan 1, 2024
946737c
WW-5382 Rework Dispatcher injections
kusalk Jan 1, 2024
3d25caa
WW-5382 Update Dispatcher#getContainer JavaDoc
kusalk Jan 1, 2024
8a245e8
WW-5352 Refactor ParametersInterceptor
kusalk Jan 3, 2024
573dbbc
WW-5381 Revert bean removal for backwards compatibility
kusalk Jan 3, 2024
aa4398e
WW-5352 Do not use setter notation for helper methods
kusalk Jan 5, 2024
199ea0d
WW-5352 Rename acceptable name/value methods
kusalk Jan 5, 2024
d4a0b3b
WW-5381 Reimplement ability to register additional MethodAccessors
kusalk Jan 5, 2024
78e97a4
Merge branch 'master' into WW-5381-method-accessor
kusalk Jan 5, 2024
503c8da
WW-5381 Remove unnecessary/confusing parameters
kusalk Jan 5, 2024
fb7fec3
Stops cleaning nightlies to allow to coexist different versions
lukaszlenart Jan 6, 2024
9a0df70
Merge pull request #834 from apache/fix/do-not-clean
lukaszlenart Jan 6, 2024
3b07899
Merge pull request #826 from apache/WW-5382-stale-config
kusalk Jan 6, 2024
3b76678
Merge pull request #825 from apache/WW-5381-method-accessor
kusalk Jan 6, 2024
ecd02de
Merge pull request #831 from apache/WW-5352-parameter-annotation-2
kusalk Jan 6, 2024
55ca7a5
WW-5365 Reverts changes introduced in WW-5192 to allow evaluate the v…
lukaszlenart Jan 7, 2024
b9d072d
Bump org.apache.maven.plugins:maven-release-plugin
dependabot[bot] Jan 8, 2024
07cecbf
Merge pull request #837 from apache/dependabot/maven/org.apache.maven…
lukaszlenart Jan 8, 2024
5b020eb
Reduces log level to debug to reduce noise in the logs
lukaszlenart Jan 8, 2024
f5a7c31
Merge pull request #838 from apache/fix/debug-level
kusalk Jan 8, 2024
d8dc720
Merge pull request #835 from apache/fix/WW-5365-radio-value
lukaszlenart Jan 9, 2024
3c8fff4
WW-5352 Clean up OgnlValueStackTest
kusalk Jan 14, 2024
9b5cb2d
WW-5352 Move method to XWorkTestCase
kusalk Jan 14, 2024
686189c
Bump actions/upload-artifact from 4.0.0 to 4.1.0
dependabot[bot] Jan 15, 2024
0a94b50
Merge pull request #842 from apache/dependabot/github_actions/actions…
lukaszlenart Jan 15, 2024
bdcedc5
Merge pull request #841 from apache/WW-5352-ognlvaluestack
kusalk Jan 15, 2024
d0ac76b
Merge pull request #820 from apache/dependabot/maven/org.apache.commo…
lukaszlenart Jan 15, 2024
e973869
WW-5387 Fixes remove() signature
lukaszlenart Jan 16, 2024
dc96c25
WW-5374 Allows to prepend reportUri with Servlet context
lukaszlenart Jan 17, 2024
fdd996c
Merge pull request #844 from apache/fix/WW-5387-remove
lukaszlenart Jan 17, 2024
72f551f
WW-5369 Re-define minimal library set
lukaszlenart Jan 18, 2024
5ee3811
Merge pull request #847 from apache/fix/WW-5369-min-lib
lukaszlenart Jan 18, 2024
d5932f8
WW-5374 Uses @code instead of <tt/>
lukaszlenart Jan 18, 2024
790c663
WW-5374 Adds additional test case to cover disabling prepending context
lukaszlenart Jan 18, 2024
3a1a89a
Merge pull request #845 from apache/fix/WW-5374-context
lukaszlenart Jan 19, 2024
3ec313a
WW-5357 Adds support for disabled attribute to anchor tag
lukaszlenart Jan 19, 2024
9a6411c
Extends sleep period to avoid breaking a build
lukaszlenart Jan 19, 2024
dd0f0b0
Merge pull request #849 from apache/fix/longer-sleep
lukaszlenart Jan 19, 2024
a763071
Merge pull request #848 from apache/fix/WW-5357-disabled
lukaszlenart Jan 19, 2024
13bf91b
Merge remote-tracking branch 'origin/master' into merge-master-to-7xx…
lukaszlenart Jan 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/scorecards-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
publish_results: true

- name: "Upload artifact"
uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # 4.0.0
uses: actions/upload-artifact@1eb3cb2b3e0f29609092a73eb033bb759a334595 # 4.1.0
with:
name: SARIF file
path: results.sarif
Expand Down
23 changes: 11 additions & 12 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,17 @@ pipeline {
steps {
sh './mvnw -B package -DskipTests'
sshPublisher(publishers: [
sshPublisherDesc(
configName: 'Nightlies',
transfers: [
sshTransfer(
remoteDirectory: '/struts/snapshot',
removePrefix: 'assembly/target/assembly/out',
sourceFiles: 'assembly/target/assembly/out/struts-*.zip',
cleanRemote: true
)
],
verbose: true
)
sshPublisherDesc(
configName: 'Nightlies',
transfers: [
sshTransfer(
remoteDirectory: '/struts/snapshot',
removePrefix: 'assembly/target/assembly/out',
sourceFiles: 'assembly/target/assembly/out/struts-*.zip'
)
],
verbose: true
)
])
}
}
Expand Down
2 changes: 2 additions & 0 deletions assembly/src/main/assembly/min-lib.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
<include>ognl:ognl</include>
<include>org.apache.commons:commons-fileupload2-jakarta</include>
<include>org.apache.commons:commons-io</include>
<include>com.github.ben-manes.caffeine:caffeine</include>
<include>org.javassist:javassist</include>
</includes>
</dependencySet>
</dependencySets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ public void setUp() throws Exception {
@After
public void tearDown() throws Exception {
XWorkTestCaseHelper.tearDown(configurationManager);
configurationManager = null;
configuration = null;
container = null;
actionProxyFactory = null;
}

protected void loadConfigurationProviders(ConfigurationProvider... providers) {
Expand Down
14 changes: 10 additions & 4 deletions core/src/main/java/com/opensymphony/xwork2/XWorkTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ protected void setUp() throws Exception {
@Override
protected void tearDown() throws Exception {
XWorkTestCaseHelper.tearDown(configurationManager);
configurationManager = null;
configuration = null;
container = null;
actionProxyFactory = null;
}

protected void loadConfigurationProviders(ConfigurationProvider... providers) {
Expand All @@ -77,6 +73,16 @@ protected void loadConfigurationProviders(ConfigurationProvider... providers) {
actionProxyFactory = container.getInstance(ActionProxyFactory.class);
}

protected void loadButSet(Map<String, ?> properties) {
loadConfigurationProviders(new StubConfigurationProvider() {
@Override
public void register(ContainerBuilder builder,
LocatableProperties props) throws ConfigurationException {
properties.forEach((k, v) -> props.setProperty(k, String.valueOf(v)));
}
});
}

protected <T> void loadButAdd(final Class<T> type, final T impl) {
loadButAdd(type, Container.DEFAULT_NAME, impl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
import com.opensymphony.xwork2.ognl.SecurityMemberAccess;
import com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor;
import com.opensymphony.xwork2.ognl.accessor.RootAccessor;
import com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor;
import com.opensymphony.xwork2.util.OgnlTextParser;
import com.opensymphony.xwork2.util.PatternMatcher;
import com.opensymphony.xwork2.util.StrutsLocalizedTextProvider;
Expand All @@ -100,6 +101,7 @@
import com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory;
import com.opensymphony.xwork2.util.location.LocatableProperties;
import com.opensymphony.xwork2.util.reflection.ReflectionProvider;
import ognl.MethodAccessor;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -323,12 +325,8 @@ public Class<? extends Configuration> type() {
}

protected ActionContext setContext(Container cont) {
ActionContext context = ActionContext.getContext();
if (context == null) {
ValueStack vs = cont.getInstance(ValueStackFactory.class).createValueStack();
context = ActionContext.of(vs.getContext()).bind();
}
return context;
ValueStack vs = cont.getInstance(ValueStackFactory.class).createValueStack();
return ActionContext.of(vs.getContext()).bind();
}

protected Container createBootstrapContainer(List<ContainerProvider> providers) {
Expand Down Expand Up @@ -389,6 +387,7 @@ public static ContainerBuilder bootstrapFactories(ContainerBuilder builder) {

.factory(ObjectTypeDeterminer.class, DefaultObjectTypeDeterminer.class, Scope.SINGLETON)
.factory(RootAccessor.class, CompoundRootAccessor.class, Scope.SINGLETON)
.factory(MethodAccessor.class, XWorkMethodAccessor.class, Scope.SINGLETON)

.factory(ExpressionCacheFactory.class, DefaultOgnlExpressionCacheFactory.class, Scope.SINGLETON)
.factory(BeanInfoCacheFactory.class, DefaultOgnlBeanInfoCacheFactory.class, Scope.SINGLETON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import com.opensymphony.xwork2.ognl.accessor.XWorkIteratorPropertyAccessor;
import com.opensymphony.xwork2.ognl.accessor.XWorkListPropertyAccessor;
import com.opensymphony.xwork2.ognl.accessor.XWorkMapPropertyAccessor;
import com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor;
import com.opensymphony.xwork2.security.AcceptedPatternsChecker;
import com.opensymphony.xwork2.security.DefaultAcceptedPatternsChecker;
import com.opensymphony.xwork2.security.DefaultExcludedPatternsChecker;
Expand All @@ -66,7 +65,6 @@
import com.opensymphony.xwork2.validator.DefaultValidatorFileParser;
import com.opensymphony.xwork2.validator.ValidatorFactory;
import com.opensymphony.xwork2.validator.ValidatorFileParser;
import ognl.MethodAccessor;
import ognl.PropertyAccessor;
import org.apache.struts2.dispatcher.HttpParameters;
import org.apache.struts2.dispatcher.Parameter;
Expand Down Expand Up @@ -142,8 +140,6 @@ public void register(ContainerBuilder builder, LocatableProperties props) throws
.factory(PropertyAccessor.class, HttpParameters.class.getName(), HttpParametersPropertyAccessor.class, Scope.SINGLETON)
.factory(PropertyAccessor.class, Parameter.class.getName(), ParameterPropertyAccessor.class, Scope.SINGLETON)

.factory(MethodAccessor.class, Object.class.getName(), XWorkMethodAccessor.class, Scope.SINGLETON)

.factory(NullHandler.class, Object.class.getName(), InstantiatingNullHandler.class, Scope.SINGLETON)
.factory(ActionValidatorManager.class, AnnotationActionValidatorManager.class, Scope.SINGLETON)
.factory(ActionValidatorManager.class, "no-annotations", DefaultActionValidatorManager.class, Scope.SINGLETON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import ognl.OgnlRuntime;
import ognl.PropertyAccessor;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.StrutsConstants;

import java.util.Set;
Expand All @@ -40,6 +42,8 @@
*/
public class OgnlValueStackFactory implements ValueStackFactory {

private static final Logger LOG = LogManager.getLogger(OgnlValueStackFactory.class);

protected XWorkConverter xworkConverter;
protected RootAccessor compoundRootAccessor;
protected TextProvider textProvider;
Expand All @@ -57,6 +61,11 @@ protected void setCompoundRootAccessor(RootAccessor compoundRootAccessor) {
OgnlRuntime.setMethodAccessor(CompoundRoot.class, compoundRootAccessor);
}

@Inject
protected void setMethodAccessor(MethodAccessor methodAccessor) {
OgnlRuntime.setMethodAccessor(Object.class, methodAccessor);
}

@Inject("system")
protected void setTextProvider(TextProvider textProvider) {
this.textProvider = textProvider;
Expand All @@ -79,26 +88,76 @@ protected ValueStack createValueStack(ValueStack stack, boolean useTextProvider)
return newStack.getActionContext().withContainer(container).withValueStack(newStack).getValueStack();
}

/**
* {@link PropertyAccessor}'s, {@link MethodAccessor}'s and {@link NullHandler}'s are registered on a per-class
* basis by defining a bean adhering to the corresponding interface with a name corresponding to the class it is
* intended to handle.
* <p>
* The only exception is the {@link MethodAccessor} for the {@link Object} type which has its own extension point.
*
* @see #setMethodAccessor(MethodAccessor)
* @see #registerAdditionalMethodAccessors()
*/
@Inject
protected void setContainer(Container container) throws ClassNotFoundException {
Set<String> names = container.getInstanceNames(PropertyAccessor.class);
this.container = container;
registerPropertyAccessors();
registerNullHandlers();
registerAdditionalMethodAccessors();
}

/**
* Note that the default {@link MethodAccessor} for handling {@link Object} methods is registered in
* {@link #setMethodAccessor} and can be configured using the extension point
* {@link StrutsConstants#STRUTS_METHOD_ACCESSOR}.
*/
protected void registerAdditionalMethodAccessors() {
Set<String> names = container.getInstanceNames(MethodAccessor.class);
for (String name : names) {
Class<?> cls = Class.forName(name);
OgnlRuntime.setPropertyAccessor(cls, container.getInstance(PropertyAccessor.class, name));
Class<?> cls;
try {
cls = Class.forName(name);
if (cls.equals(Object.class)) {
// The Object method accessor can only be configured using the struts.methodAccessor extension point
continue;
}
if (cls.equals(CompoundRoot.class)) {
// TODO: This bean is deprecated, please remove this if statement when removing the struts-beans.xml entry
continue;
}
} catch (ClassNotFoundException e) {
// Since this interface is also used as an extension point for the Object MethodAccessor, we expect
// there to be beans with names that don't correspond to classes. We can safely ignore these.
continue;
}
MethodAccessor methodAccessor = container.getInstance(MethodAccessor.class, name);
OgnlRuntime.setMethodAccessor(cls, methodAccessor);
LOG.debug("Registered custom OGNL MethodAccessor [{}] for class [{}]", methodAccessor.getClass().getName(), cls.getName());
}
}

names = container.getInstanceNames(MethodAccessor.class);
protected void registerNullHandlers() throws ClassNotFoundException {
Set<String> names = container.getInstanceNames(NullHandler.class);
for (String name : names) {
Class<?> cls = Class.forName(name);
OgnlRuntime.setMethodAccessor(cls, container.getInstance(MethodAccessor.class, name));
NullHandler nullHandler = container.getInstance(NullHandler.class, name);
OgnlRuntime.setNullHandler(cls, new OgnlNullHandlerWrapper(nullHandler));
LOG.debug("Registered custom OGNL NullHandler [{}] for class [{}]", nullHandler.getClass().getName(), cls.getName());
}
}

names = container.getInstanceNames(NullHandler.class);
protected void registerPropertyAccessors() throws ClassNotFoundException {
Set<String> names = container.getInstanceNames(PropertyAccessor.class);
for (String name : names) {
Class<?> cls = Class.forName(name);
OgnlRuntime.setNullHandler(cls, new OgnlNullHandlerWrapper(container.getInstance(NullHandler.class, name)));
if (cls.equals(CompoundRoot.class)) {
// TODO: This bean is deprecated, please remove this if statement when removing the struts-beans.xml entry
continue;
}
PropertyAccessor propertyAccessor = container.getInstance(PropertyAccessor.class, name);
OgnlRuntime.setPropertyAccessor(cls, propertyAccessor);
LOG.debug("Registered custom OGNL PropertyAccessor [{}] for class [{}]", propertyAccessor.getClass().getName(), cls.getName());
}
this.container = container;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,37 @@ public interface AcceptedPatternsChecker {
* @param value to check
* @return object containing result of matched pattern and pattern itself
*/
public IsAccepted isAccepted(String value);
IsAccepted isAccepted(String value);

/**
* Sets excluded patterns during runtime
*
* @param commaDelimitedPatterns comma delimited string with patterns
*/
public void setAcceptedPatterns(String commaDelimitedPatterns);
void setAcceptedPatterns(String commaDelimitedPatterns);

/**
* Set excluded patterns during runtime
*
* @param patterns array of additional excluded patterns
*/
public void setAcceptedPatterns(String[] patterns);
void setAcceptedPatterns(String[] patterns);

/**
* Sets excluded patterns during runtime
*
* @param patterns set of additional patterns
*/
public void setAcceptedPatterns(Set<String> patterns);
void setAcceptedPatterns(Set<String> patterns);

/**
* Allow access list of all defined excluded patterns
*
* @return set of excluded patterns
*/
public Set<Pattern> getAcceptedPatterns();
Set<Pattern> getAcceptedPatterns();

public final static class IsAccepted {
final class IsAccepted {

private final boolean accepted;
private final String acceptedPattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,37 @@ public interface ExcludedPatternsChecker {
* @param value to check
* @return object containing result of matched pattern and pattern itself
*/
public IsExcluded isExcluded(String value);
IsExcluded isExcluded(String value);

/**
* Sets excluded patterns during runtime
*
* @param commaDelimitedPatterns comma delimited string with patterns
*/
public void setExcludedPatterns(String commaDelimitedPatterns);
void setExcludedPatterns(String commaDelimitedPatterns);

/**
* Sets excluded patterns during runtime
*
* @param patterns array of additional excluded patterns
*/
public void setExcludedPatterns(String[] patterns);
void setExcludedPatterns(String[] patterns);

/**
* Sets excluded patterns during runtime
*
* @param patterns set of additional patterns
*/
public void setExcludedPatterns(Set<String> patterns);
void setExcludedPatterns(Set<String> patterns);

/**
* Allow access list of all defined excluded patterns
*
* @return set of excluded patterns
*/
public Set<Pattern> getExcludedPatterns();
Set<Pattern> getExcludedPatterns();

public final static class IsExcluded {
final class IsExcluded {

private final boolean excluded;
private final String excludedPattern;
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/apache/struts2/StrutsConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ public final class StrutsConstants {
/** Extension point for the Struts CompoundRootAccessor */
public static final String STRUTS_COMPOUND_ROOT_ACCESSOR = "struts.compoundRootAccessor";

/** Extension point for the Struts MethodAccessor */
public static final String STRUTS_METHOD_ACCESSOR = "struts.methodAccessor";

/** The name of the xwork converter implementation */
public static final String STRUTS_XWORKCONVERTER = "struts.xworkConverter";

Expand Down
8 changes: 0 additions & 8 deletions core/src/main/java/org/apache/struts2/components/Radio.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ protected String getDefaultTemplate() {
return TEMPLATE;
}

public void evaluateExtraParams() {
super.evaluateExtraParams();
}

/**
* Radio tag requires lazy evaluation as list of tags is dynamically generated using <s:iterator/>
*
Expand All @@ -80,8 +76,4 @@ protected boolean lazyEvaluation() {
return true;
}

protected Class<?> getValueClassType() {
return String.class;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import com.opensymphony.xwork2.util.reflection.ReflectionContextFactory;
import com.opensymphony.xwork2.util.reflection.ReflectionProvider;
import com.opensymphony.xwork2.validator.ActionValidatorManager;
import ognl.MethodAccessor;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.components.UrlRenderer;
import org.apache.struts2.components.date.DateFormatter;
Expand Down Expand Up @@ -389,6 +390,7 @@ public void register(ContainerBuilder builder, LocatableProperties props) {
alias(FileManagerFactory.class, StrutsConstants.STRUTS_FILE_MANAGER_FACTORY, builder, props, Scope.SINGLETON);

alias(RootAccessor.class, StrutsConstants.STRUTS_COMPOUND_ROOT_ACCESSOR, builder, props);
alias(MethodAccessor.class, StrutsConstants.STRUTS_METHOD_ACCESSOR, builder, props);

alias(XWorkConverter.class, StrutsConstants.STRUTS_XWORKCONVERTER, builder, props);
alias(CollectionConverter.class, StrutsConstants.STRUTS_CONVERTER_COLLECTION, builder, props);
Expand Down
Loading