[
https://issues.apache.org/jira/browse/WW-5766?focusedWorklogId=1046944&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1046944
]
ASF GitHub Bot logged work on WW-5766:
--------------------------------------
Author: ASF GitHub Bot
Created on: 12/Oct/26 09:17
Start Date: 12/Oct/26 09:17
Worklog Time Spent: 10m
Work Description: lukaszlenart opened a new pull request, #2006:
URL: https://github.com/apache/struts/pull/2006
Fixes [WW-5766](https://issues.apache.org/jira/browse/WW-5766)
## Summary
Java-based configuration (`StrutsJavaConfiguration`) can now select a custom
`ScopedConstantProvider`. Before this change the only way was to subclass
`ConstantConfig` and override `getAllAsStringsMap()`.
`ConstantConfig` gets a `scopedConstantProvider` field, mapped to
`struts.scopedConstantProvider` in `getAllAsStringsMap()`. It has a getter and
two setters, following the `localizedTextProvider` mapping. The class setter
takes `Class<? extends ScopedConstantProvider>` rather than the file's usual
`Class<?>`, so a wrong class is caught at compile time.
## Tests
- `ConstantConfigTest.testScopedConstantProviderToString`: the key is absent
until set, then maps to the bean name from either setter.
-
`StrutsJavaConfigurationProviderTest.testScopedConstantProviderSelectedThroughConstantConfig`:
a custom provider registered through `beans()` and selected through
`ConstantConfig` is the one the container returns.
-
`StrutsJavaConfigurationProviderTest.testScopableConstantsBeanSatisfiesScopedConstantValidation`:
a `ScopableConstants` bean registered through `beans()` lets an XML package's
`<scoped-constant>` pass startup validation. This already worked and had no
test.
The two integration tests load providers in the same order as `Dispatcher`:
default properties, `struts-default.xml`, the Java config, then
`StrutsBeanSelectionProvider`. They don't use
`StrutsDefaultConfigurationProvider`, because it binds `ScopedConstantProvider`
under the default name. With that binding, `alias()` skips the constant, so the
test could never see the mapping.
I checked that the tests aren't vacuous. With the `map.put` line removed,
both mapping tests fail. With the `ScopableConstants` bean removed, the
validation test fails with "declares scoped constant [sample.scopable], which
is not scopable". The full `core` suite passes: 3446 tests, 0 failures.
## Out of scope
- Package-level overrides in Java config. `StrutsJavaConfiguration` has no
package concept.
- Other bean-selection constants that `ConstantConfig` doesn't map either
(`parameterAuthorizer`, `ognlGuard`, `proxyService`, ...).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Issue Time Tracking
-------------------
Worklog Id: (was: 1046944)
Remaining Estimate: 0h
Time Spent: 10m
> Support struts.scopedConstantProvider in Java-based configuration
> (ConstantConfig)
> ----------------------------------------------------------------------------------
>
> Key: WW-5766
> URL: https://issues.apache.org/jira/browse/WW-5766
> Project: Struts 2
> Issue Type: Improvement
> Components: Core
> Reporter: Lukasz Lenart
> Priority: Major
> Fix For: 7.5.0
>
> Time Spent: 10m
> Remaining Estimate: 0h
>
> h2. Background
> [WW-3476|https://issues.apache.org/jira/browse/WW-3476] adds package-scoped
> constants. Part of that is a new bean-selection extension point,
> {{ScopedConstantProvider}}, selected through the
> {{struts.scopedConstantProvider}} constant
> ({{StrutsConstants.STRUTS_SCOPED_CONSTANT_PROVIDER}}). It is covered for XML
> and properties configuration, but not for Java-based configuration
> ({{StrutsJavaConfiguration}}).
> h2. Problem
> Java-based configuration passes constants only through the typed
> {{ConstantConfig}} class: {{StrutsJavaConfigurationProvider}} reads them from
> {{ConstantConfig.getAllAsStringsMap()}}, and there is no way to set an
> arbitrary key. {{ConstantConfig}} has no field for
> {{struts.scopedConstantProvider}}, so an application using Java-based
> configuration cannot select a custom {{ScopedConstantProvider}}. The only
> workaround is to subclass {{ConstantConfig}} and override
> {{getAllAsStringsMap()}}.
> h2. What to add
> In
> {{core/src/main/java/org/apache/struts2/config/entities/ConstantConfig.java}},
> following the existing {{localizedTextProvider}} mapping:
> * a {{BeanConfig}} field {{scopedConstantProvider}}, next to
> {{localizedTextProvider}}
> * an entry in {{getAllAsStringsMap()}}:
> {code:java}map.put(StrutsConstants.STRUTS_SCOPED_CONSTANT_PROVIDER,
> beanConfToString(scopedConstantProvider));
> {code}
> * a getter and two setters, modelled on {{setLocalizedTextProvider}}:
> {code:java}public BeanConfig getScopedConstantProvider()
> public void setScopedConstantProvider(BeanConfig scopedConstantProvider)
> public void setScopedConstantProvider(Class<? extends ScopedConstantProvider>
> clazz)
> {code}
> h2. Tests
> * {{ConstantConfigTest.testGetAllAsStringsMap}}: the new key maps to the bean
> name.
> * {{StrutsJavaConfigurationProviderTest}}: a Java configuration that
> registers a custom {{ScopedConstantProvider}} bean through {{beans()}} and
> selects it through {{ConstantConfig}} resolves to that bean.
> * {{StrutsJavaConfigurationProviderTest}}: a {{ScopableConstants}} bean
> registered through {{beans()}} satisfies the startup validation of
> {{<scoped-constant>}} (this already works and is not yet covered by a test).
> h2. Already working, no change needed
> * Registering {{ScopableConstants}} beans and a custom provider bean through
> {{StrutsJavaConfiguration.beans()}}.
> * {{PackageConfig}}, the startup validation in {{DefaultConfiguration}} and
> {{StrutsScopedConstantProvider}} work the same whatever configuration a value
> came from.
> h2. Out of scope
> * Package-level overrides in Java-based configuration:
> {{StrutsJavaConfiguration}} has no package concept
> ({{StrutsJavaConfigurationProvider.loadPackages()}} is empty), so there is
> nothing to attach them to.
> * Other bean-selection constants that {{ConstantConfig}} does not map either
> (for example {{struts.parameterAuthorizer}}, {{struts.parameterAllowlister}},
> {{struts.ognlGuard}}, {{struts.proxyService}}). That is a separate gap.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)