[
https://issues.apache.org/jira/browse/WW-5766?focusedWorklogId=1046956&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1046956
]
ASF GitHub Bot logged work on WW-5766:
--------------------------------------
Author: ASF GitHub Bot
Created on: 12/Oct/26 10:10
Start Date: 12/Oct/26 10:10
Worklog Time Spent: 10m
Work Description: sonarqubecloud[bot] commented on PR #2006:
URL: https://github.com/apache/struts/pull/2006#issuecomment-6122145423
## [](https://sonarcloud.io/dashboard?id=apache_struts&pullRequest=2006)
**Quality Gate passed**
Issues
 [0 New
issues](https://sonarcloud.io/project/issues?id=apache_struts&pullRequest=2006&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted
issues](https://sonarcloud.io/project/issues?id=apache_struts&pullRequest=2006&issueStatuses=ACCEPTED)
Measures
 [0 Security
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_struts&pullRequest=2006&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [83.3% Coverage on New
Code](https://sonarcloud.io/component_measures?id=apache_struts&pullRequest=2006&metric=new_coverage&view=list)
 [0.0% Duplication on New
Code](https://sonarcloud.io/component_measures?id=apache_struts&pullRequest=2006&metric=new_duplicated_lines_density&view=list)
<!
Issue Time Tracking
-------------------
Worklog Id: (was: 1046956)
Time Spent: 20m (was: 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: 20m
> 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)