[ 
https://issues.apache.org/jira/browse/SLING-12640?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17922405#comment-17922405
 ] 

Rakesh Kumar edited comment on SLING-12640 at 1/30/25 3:17 PM:
---------------------------------------------------------------

so, what should be the correct behaviour here?

IMHO, the filter should have been completely ignored in cases like this.

Consider a situation where I want to make the filter registration basis the 
value of *sling.filter.scope* property from env var
{code:java}
{
  "sling.filter.scope": ["$[env:MY_CUSTOM_FILTER_SCOPE;default=DISABLED]"],
  "sling.filter.pattern": "/content/.*"
}{code}
This becomes handy in situations where we need to make the filter operational 
whenever needed, we just need to create/update the env var with one of the 
valid values of *sling.filter.scope* property.

 


was (Author: rakeshk15):
so, what should be the correct behaviour here?

IMHO, the filter should have been completely ignored in cases like this.

Consider a situation where I want to make the filter registration basis the 
value of *sling.filter.scope* property from env vars

 
{code:java}
{
  "sling.filter.scope": ["$[env:MY_CUSTOM_FILTER_SCOPE;default=DISABLED]"],
  "sling.filter.pattern": "/content/.*"
}{code}
This becomes handy in situations where we need to make the filter operational 
whenever needed, we just need to create/update the env var with one of the 
valid values of *sling.filter.scope* property.

 

> Setting Sling filter service property sling.filter.scope to an invalid value 
> does not disable the filter.
> ---------------------------------------------------------------------------------------------------------
>
>                 Key: SLING-12640
>                 URL: https://issues.apache.org/jira/browse/SLING-12640
>             Project: Sling
>          Issue Type: Bug
>          Components: Engine
>    Affects Versions: Engine 2.15.16
>            Reporter: Rakesh Kumar
>            Priority: Major
>
> I have created a filter service and provided the value of 
> *sling.filter.scope* as some arbitrary string({*}MyDisabledFilter{*})
> I followed the disabling mechanism mentioned here - 
> [https://sling.apache.org/documentation/the-sling-engine/filters.html#disabling-filters-1]
> But the filter is still registered by Sling as a request filter.
> I was looking at the
> {code:java}
> org.apache.sling.engine.impl.filter.ServletFilterManager{code}
> code and found that if an invalid value is specified for *sling.filter.scope* 
> property, then the filter is still registered as a REQUEST scoped filter as 
> some fallback.
> {code:java}
> final String[] scopes =
>                 
> Converters.standardConverter().convert(scopeValue).to(String[].class);
>         final FilterPredicate predicate = new FilterPredicate(reference);
>         boolean used = false;
>         for (String scope : scopes) {
>             scope = scope.toUpperCase();
>             try {
>                 FilterChainType type = 
> FilterChainType.valueOf(scope.toString());
>                 getFilterChain(type).addFilter(filter, predicate, serviceId, 
> order, orderSource, mbean);
>                 if (type == FilterChainType.COMPONENT) {
>                     getFilterChain(FilterChainType.INCLUDE)
>                             .addFilter(filter, predicate, serviceId, order, 
> orderSource, mbean);
>                     getFilterChain(FilterChainType.FORWARD)
>                             .addFilter(filter, predicate, serviceId, order, 
> orderSource, mbean);
>                 }
>                 used = true;
>             } catch (final IllegalArgumentException iae) {
>                 log.warn("Filter service {} has invalid value {} for scope. 
> Value is ignored", reference, scope);
>             }
>         }
>         if (!used) {
>             log.warn(
>                     "Filter service {} has been registered without a valid {} 
> property. Using default value.",
>                     serviceId,
>                     EngineConstants.SLING_FILTER_SCOPE);
>             getFilterChain(FilterChainType.REQUEST).addFilter(filter, 
> predicate, serviceId, order, orderSource, mbean);
>         } {code}
>  
> This seems to be contradictory to the official documentation.
> Please let me know if I am missing something.
> [~cziegeler] can you please look at this?
> Thanks,
> Rakesh
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to