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

[SLING-11742] Provide alternative equitable terminology for properties #89

Closed
wants to merge 3 commits into from

Conversation

cristic83
Copy link

This PR introduces alternative terminology for terms that are considered un-appropriate for vanity paths, as described in [1]. The approach taken was to provide additional properties to the existing properties so that backwards compatibility is kept. For the sake of backwards compatibility, the existing vanity paths properties are checked first and if these are not defined, the newly introduced properties are checked. A log message is produced in this case.

[1] https://issues.apache.org/jira/browse/SLING-11742

@rombert rombert self-requested a review January 11, 2023 11:45
Copy link
Contributor

@rombert rombert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @cristic83 ! I've addede a few comments.

description ="This setting can contain a list of path prefixes, e.g. /libs/, /content/. If " +
"such a list is configured, only vanity paths from resources starting with this prefix " +
" are considered. If the list is empty, all vanity paths are used.")
String[] resource_resolver_vanitypath_allowedlist();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use 'allowlist' instead of 'allowedlist' . See also https://cwiki.apache.org/confluence/display/SLING/Removal+of+problematic+language

description ="This setting can contain a list of path prefixes, e.g. /misc/. If " +
"such a list is configured,vanity paths from resources starting with this prefix " +
" are not considered. If the list is empty, all vanity paths are used.")
String[] resource_resolver_vanitypath_deniedlist();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use 'denylist' instead of 'deniedlist'

@@ -195,6 +195,11 @@ public String[] resource_resolver_virtual() {

@Override
public String[] resource_resolver_vanitypath_whitelist() {
return resource_resolver_vanitypath_allowedlist();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can get confusing, please return just null.

@@ -215,6 +220,11 @@ public int resource_resolver_vanitypath_bloomfilter_maxBytes() {

@Override
public String[] resource_resolver_vanitypath_blacklist() {
return resource_resolver_vanitypath_deniedlist();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can get confusing, please return just null.

@@ -79,6 +81,45 @@ private static final class FactoryRegistration {
public volatile CommonResourceResolverFactoryImpl commonFactory;
}

private static final class VanityPathConfigurer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extract a test for this class, having the logic separated makes it easy.

String pathPrefixesPropertyName, String pathPrefixesFallbackPropertyName,
Consumer<String[]> filteredPathPrefixesConsumer) {
if (pathPrefixes != null) {
configureVanityPathPrefixes(pathPrefixes, filteredPathPrefixesConsumer);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please log a WARN in the case where both the regular prefixes and the fallback ones are defined; this is probably a customer error. We should rely on the old behaviour in this case and only take information from config.resource_resolver_vanitypath_whitelist().

private static final class VanityPathConfigurer {
private final Logger logger = LoggerFactory.getLogger(this.getClass());

void configureVanityPathPrefixes(String[] pathPrefixes, String[] pathPrefixesFallback,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it makes sense to pass in the whole config object, so simplify the signature ; now we pass to fields and their names, passing in the object might make things nicer.

Copy link
Author

@cristic83 cristic83 Jan 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I attempted to implement this suggestion and the result looks like below. I don't think it's all that nicer,what do you think?

void configureVanityPAthPrefix(ResourceResolverFactoryConfig config, Consumer<String[]> allowVanityPathConsumer, Consumer<String[]> denyVanityPathConsumer) { configureVanityPathPrefixes(config.resource_resolver_vanitypath_whitelist(), config.resource_resolver_vanitypath_allowlist(), "resource_resolver_vanitypath_whitelist", "resource_resolver_vanitypath_allowlist", allowVanityPathConsumer); configureVanityPathPrefixes(config.resource_resolver_vanitypath_blacklist(), config.resource_resolver_vanitypath_denylist(), "resource_resolver_vanitypath_blacklist", "resource_resolver_vanitypath_denylist", denyVanityPathConsumer); }

@sonarcloud
Copy link

sonarcloud bot commented Jan 20, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 9 Code Smells

88.9% 88.9% Coverage
0.0% 0.0% Duplication

@rombert rombert self-requested a review March 3, 2023 16:35
@rombert
Copy link
Contributor

rombert commented Mar 3, 2023

I've assigned myself as a reviewer to make sure it's on my TODO list. Not sure when I will get around to it, if anyone beats me to it I won't mind :-)

@cziegeler
Copy link
Contributor

cziegeler commented Mar 13, 2023

@cristic83 I suggest we use an approach where we keep the existing code out of doing conversions from old to new. With a ConfigurationPlugin we can convert transparently the old properties to the new ones. The plugin can then also trigger to update the configuration in configuration admin (async). The components consuming the configurations should implement modified events and check for changes and only act on a real configuration change

@sonarcloud
Copy link

sonarcloud bot commented Apr 19, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 9 Code Smells

88.9% 88.9% Coverage
0.0% 0.0% Duplication

@@ -163,15 +163,27 @@
@AttributeDefinition(name = "Allowed Vanity Path Location",
description ="This setting can contain a list of path prefixes, e.g. /libs/, /content/. If " +
"such a list is configured, only vanity paths from resources starting with this prefix " +
" are considered. If the list is empty, all vanity paths are used.")
" are considered. If the list is empty, we fallback to resource.resolver.vanitypath.allowlist.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the fallback should be in the opposite direction: if the new property is not used, the old one will be used

@AttributeDefinition(name = "Denied Vanity Path Location",
description ="This setting can contain a list of path prefixes, e.g. /misc/. If " +
"such a list is configured,vanity paths from resources starting with this prefix " +
" are not considered. If the list is empty, all vanity paths are used.")
" are not considered. If the list is empty, we fallback to resource.resolver.vanitypath.denylist.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

"such a list is configured, only vanity paths from resources starting with this prefix " +
" are considered. If the list is empty, all vanity paths are used.")
String[] resource_resolver_vanitypath_allowlist();

@AttributeDefinition(name = "Denied Vanity Path Location",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove the metatype information for this property

@@ -163,15 +163,27 @@
@AttributeDefinition(name = "Allowed Vanity Path Location",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should remove the metatype info for this property

class VanityPathConfigurer {
private final Logger logger = LoggerFactory.getLogger(this.getClass());

void configureVanityPathPrefixes(String[] pathPrefixes, String[] pathPrefixesFallback,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a static method just taking the Config object as a parameter and returning a String[]

@cziegeler cziegeler mentioned this pull request Jun 3, 2023
@cziegeler
Copy link
Contributor

@cristic83 I think we were a little bit unfair here with all our comments and nit picking. I think you did very good work so far. In order to spare you the burden of applying all our nitpicking, I put your code changes into a new branch and applied our comments there.
Created a new PR based on that branch #97

@sonarcloud
Copy link

sonarcloud bot commented Sep 13, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 7 Code Smells

88.9% 88.9% Coverage
0.0% 0.0% Duplication

@cziegeler
Copy link
Contributor

This has been implemented a while ago by #97

@cziegeler cziegeler closed this Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants