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

abort processing of the request

Avatar

Avatar
Validate 10
Level 2
anelem1760873
Level 2

Likes

9 likes

Total Posts

59 posts

Correct Reply

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

Avatar
Validate 10
Level 2
anelem1760873
Level 2

Likes

9 likes

Total Posts

59 posts

Correct Reply

3 solutions
Top badges earned
Validate 10
Validate 1
Ignite 3
Ignite 1
Give Back 5
View profile
anelem1760873
Level 2

29-04-2021

Hey there,
 
how do I block/abort processing of the request using  sling filter.
 
Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Boost 25
Employee
markus_bulla_adobe
Employee

Likes

40 likes

Total Posts

46 posts

Correct Reply

18 solutions
Top badges earned
Boost 25
Affirm 10
Applaud 5
Affirm 5
Establish
View profile

Avatar
Boost 25
Employee
markus_bulla_adobe
Employee

Likes

40 likes

Total Posts

46 posts

Correct Reply

18 solutions
Top badges earned
Boost 25
Affirm 10
Applaud 5
Affirm 5
Establish
View profile
markus_bulla_adobe
Employee

29-04-2021

Hi @anelem1760873!

 

Usually, you would include your filter into the filter chain and override the doFilter() method as @bilal_ahmad outlined in his code example.

Depending on your understanding of how to "block/abort" the request, you could do one of the following:

  • Check for the right condition and send an appropriate HTTP response (e. g. 404 Not Found or any other 4xx or 5xx code that makes sense for your use case) - exactly what @bilal_ahmad mentioned. You can find a simple example of a LoggingFilter [1] in the AEM Maven Archetype [2].
  • Proceed with request processing but skip any additional filters. Probably not what you are looking for.
  • Stop processing all together and not even waste additional computing resources by sending any kind of response. You probably don't want to do that as this may lead to unexpected results.

If your use case is really about blocking and/or dropping incoming requests (e. g. as a protective measure against DoS/DDoS, unwanted crawlers or other clients, etc.) my suggestion would be to stop them at an earlier stage. You could leverage some kind of web application firewall (WAF). Sometimes certain modules for Apache HTTPD do the job (mod_security [3], mod_qos [4] or for simple cases even mod_rewrite [5]).

 

[1] https://github.com/adobe/aem-project-archetype/blob/develop/src/main/archetype/core/src/main/java/co...

[2] https://experienceleague.adobe.com/docs/experience-manager-core-components/using/developing/archetyp...

[3] https://github.com/SpiderLabs/ModSecurity/wiki

[4] http://mod-qos.sourceforge.net/

[5] https://httpd.apache.org/docs/current/mod/mod_rewrite.html

Answers (1)

Answers (1)

Avatar

Avatar
Springboard
Level 4
bilal_ahmad
Level 4

Likes

66 likes

Total Posts

106 posts

Correct Reply

16 solutions
Top badges earned
Springboard
Validate 10
Validate 1
Ignite 1
Establish
View profile

Avatar
Springboard
Level 4
bilal_ahmad
Level 4

Likes

66 likes

Total Posts

106 posts

Correct Reply

16 solutions
Top badges earned
Springboard
Validate 10
Validate 1
Ignite 1
Establish
View profile
bilal_ahmad
Level 4

29-04-2021

Hey @anelem1760873 you can write something this sort in the doFilter() method:

if (resource.getPath().startsWith("/content/pathToBlock/")) {
    if (<right condition>)) {
        <YOUR BUSINESS LOGIC>
    } else {
        slingResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
    return;
}


Thanks,

Bilal.