Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Sling Filter Restring scope to resources

Avatar

Avatar
Level 1
karthikb1706130
Level 1

Likes

0 likes

Total Posts

2 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
karthikb1706130
Level 1

Likes

0 likes

Total Posts

2 posts

Correct Reply

0 solutions
View profile
karthikb1706130
Level 1

18-06-2020

Hi,

I want to reggister a filter using a resourceTypes , as part of my code i have implemented the following

@component(service = Filter.class, property = {SLING_FILTER_SCOPE_REQUEST, SERVICE_RANKING_MAX,
    SLING_FILTER_RESOURCETYPES + "= testproject/components/page/myDetailsPage"})

 

when i open an page with the above resourcetype, the above filter is not getting triggered, can anyone help me how to overcome this issue. 
also how to register the filter using multiple resourceTypes
 

AEM 6.5 slingfilter

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 1
MVP
Albin_Issac
MVP

Likes

106 likes

Total Posts

119 posts

Correct Reply

33 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Validate 1
MVP
Albin_Issac
MVP

Likes

106 likes

Total Posts

119 posts

Correct Reply

33 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
Albin_Issac
MVP

18-06-2020

try with

@component(service = Filter.class, name = "Custom Logging Filter", property = {
SLING_FILTER_SCOPE + "=" + FILTER_SCOPE_REQUEST, Constants.SERVICE_RANKING + ":Integer=1",
SLING_FILTER_RESOURCETYPES + "testproject/components/page/myDetailsPage" })

add SLING_FILTER_RESOURCETYPES multiple times to support different resource types

@component(service = Filter.class, name = "Custom Logging Filter", property = {
SLING_FILTER_SCOPE + "=" + FILTER_SCOPE_REQUEST, Constants.SERVICE_RANKING + ":Integer=1",
SLING_FILTER_RESOURCETYPES + "testproject/components/page/myDetailsPage",

SLING_FILTER_RESOURCETYPES + "testproject/components/page/myDetailsPage1"})

 

import static org.apache.sling.engine.EngineConstants.*; for properties

 

Regards

Albin

Answers (2)

Answers (2)

Avatar

Avatar
Establish
Level 6
antoniom5495929
Level 6

Likes

91 likes

Total Posts

212 posts

Correct Reply

39 solutions
Top badges earned
Establish
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile

Avatar
Establish
Level 6
antoniom5495929
Level 6

Likes

91 likes

Total Posts

212 posts

Correct Reply

39 solutions
Top badges earned
Establish
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile
antoniom5495929
Level 6

19-06-2020

Hi @karthikb1706130 ,

If I understood correctly you want to create a filter which is able to get all the request that comes from a specific resourcetype or list of resourcetype.

If this is your purpose, I think that it's better for you to use a servlet instead of a filter. In this way you can use also multiple resourcetype without problems [0].

 

A suggestion, don't use a filter if it's not required since this filter will be executed every time for each request (also the AEM default request) and then will evaluate the conditions.  

 

[0]https://helpx.adobe.com/experience-manager/using/resourcetypes.html

 

Thanks,

Antonio

Avatar

Avatar
Boost 500
MVP
Vijayalakshmi_S
MVP

Likes

510 likes

Total Posts

645 posts

Correct Reply

213 solutions
Top badges earned
Boost 500
Give Back 50
Give Back 5
Ignite 10
Ignite 5
View profile

Avatar
Boost 500
MVP
Vijayalakshmi_S
MVP

Likes

510 likes

Total Posts

645 posts

Correct Reply

213 solutions
Top badges earned
Boost 500
Give Back 50
Give Back 5
Ignite 10
Ignite 5
View profile
Vijayalakshmi_S
MVP

18-06-2020

Hi @karthikb1706130,

Looks like the resource type to be mentioned in sling.filter.resourceTypes is jcr:primaryType of the resource and not sling:resourceType

For your case, if the pages created using myDetailsPage is created/resides under one hierarchy, then we can restrict the filter using sling.filter.pattern property.

Sample below will apply the filter to pages under /content/learnings

dam:Asset type will not take effect given the pattern. Have just added to showcase the multiple resource types (similar to what @Albin_Issac said)

 

@Component(service = Filter.class,
           property = {
                   EngineConstants.SLING_FILTER_SCOPE + "=" + EngineConstants.FILTER_SCOPE_REQUEST,
                   EngineConstants.SLING_FILTER_PATTERN + "=/content/learnings/(.*)",            
                   EngineConstants.SLING_FILTER_RESOURCETYPES + "=cq:Page",  
                   EngineConstants.SLING_FILTER_RESOURCETYPES + "=dam:Asset", 
                   Constants.SERVICE_RANKING + "=500",
           })