request contains authorization in coming when accessing to get servlet | Community
Skip to main content
AdobeID24
Level 5
February 22, 2024
Solved

request contains authorization in coming when accessing to get servlet

  • February 22, 2024
  • 3 replies
  • 2422 views

http://localhost:8080/content/anything/us/en/jcr:content.txt

this servlet I am hiiting from post man without passing any credentials and it is giving me response . but this is not getting cached ...

 

if I want to cache it what needs to be done ?

 

I am also not doing any authorization check in dispatcher level .

 

note : when i am accessing any page normally then in logs i do not see "request contains authorization"

and it properly get cache or served from cache .

 

why only for servlet it shows "request contains authorization" and no cache happens?

 

 

I do not want to do this -->

/allowAuthorized "1"
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by aanchal-sikka

yeah servlet is GET only

Docroot and all set properly I believe because when i make "allowauthorization":1 from 0 it start caching secure content  .

 

Caching is happening on above case . 

 

 


@adobeid24 

 

Option-1: Please change the resourceType in your Servlet to "sling/servlet/default". Now access this servlet as http://localhost:8080/content/anything/us/en.txt

 

The Servlet should be accessible for all resourcetypes and cacheable. 

 

Option-2: Rewrite as suggested by @imran__khan 

3 replies

Imran__Khan
Community Advisor
Community Advisor
February 22, 2024
AdobeID24
AdobeID24Author
Level 5
February 23, 2024

I have seen that response . 

 

I have set up everything ok as per that discussion .

 

in my local I have allowed everything to cache as of now ..

 

/cache--> /rules -->

/0000 {
/glob "*"
/type "allow"
}
aanchal-sikka
Community Advisor
Community Advisor
February 23, 2024

@adobeid24 

 

Please validate the rules defined in /cache -> /rules section of your dispatcher 

https://experienceleague.adobe.com/docs/experience-manager-learn/ams/dispatcher/understanding-cache.html?lang=en

 

A rule like this instructs dispatcher not to cache html files under /libs

/0002 { /glob "/libs/*.html" /type "deny" }

 

 

Also, enable the DEBUG logs on dispatcher to have better understanding of the request and how dispatcher is handling it. Set DISP_LOG_LEVEL to debug. Example:

Define DISP_LOG_LEVEL debug

https://techrevel.blog/2023/08/28/navigating-aem-dispatcher-setup-farm-file-resolution-and-variable-utilization/#env-variables

Aanchal Sikka
AdobeID24
AdobeID24Author
Level 5
February 23, 2024

Hi @aanchal-sikka  ,

 

I have dispatcher logs in debug level only  , there only I am getting these two traces :

"request contains authorization" and "cache-action for [/content/something/us/en/jcr:content.txt]: NONE"

 

accessing servlet through postman no credentials required :

 

 

if I make below allowAuthorized from 0 to 1 it will start caching servlet response and serve from cache the response . but I do not want to do.

/allowAuthorized "1"

 

my /cache --> /rules is very simple i just allowed everything to cache . 

 

/cache--> /rules -->

/0000 {
/glob "*"
/type "allow"
}
Imran__Khan
Community Advisor
Community Advisor
February 23, 2024

@adobeid24 
First of all please correct you servlet path using below sample code as it should not have jcr:content as part of servlet path.
Correct  Path: http://localhost:8080/content/anything/us/en.txt or http://localhost:8080/content/anything/us/en.json 

import java.io.IOException; import javax.servlet.Servlet; import javax.servlet.ServletException; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.servlets.HttpConstants; import org.apache.sling.api.servlets.ServletResolverConstants; import org.apache.sling.api.servlets.SlingSafeMethodsServlet; import org.osgi.service.component.annotations.Component; @Component( immediate = true, service = Servlet.class, name = "test", property = { ServletResolverConstants.SLING_SERVLET_METHODS + "=" + HttpConstants.METHOD_GET, ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES + "=" + CommonConstants.RESOURCE_TYPE_CQ_PAGE, ServletResolverConstants.SLING_SERVLET_EXTENSIONS + "=txt" } ) public class DetailsServlet extends SlingSafeMethodsServlet { private static final long serialVersionUID = 1L; @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { } }

 

kautuk_sahni
Community Manager
Community Manager
February 28, 2024

@adobeid24  Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni