Invoking an AEM servlet from outside the domain | Community
Skip to main content
Level 4
February 1, 2016

Invoking an AEM servlet from outside the domain

  • February 1, 2016
  • 1 reply
  • 1893 views

Ok so based on earlier discussion with Adobe folks, we wrote a servlet on the AEM platform in cloud that executes some functions based on our post. Now the challenge is protecting the URL and be able to post.

 

For example, our serlvet path is /bin/wcm/myproject/manageusers

Since the path is virtual, how do we assign rights by creating a user who can invoke that servlet? Where would we do that. Secondly, do we have an example of an Ajax call that can invoke that servlet by passing a username/pwd?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Kunal_Gaba_
February 1, 2016

You should bind your servlet with a resourceType and use that resource type in a custom page component and a template. You can then create a page with that template and define permissions or ACLs on the page node for defining the access control. Whenever you hit the URL of the page the AEM will call the servlet (if the permissions of the user are allowed) as the resourceType of the page will point to the servlet. 

[1] https://cqdump.wordpress.com/2015/03/23/aem-coding-best-practice-servlets/

[2] http://labs.6dglobal.com/blog/2013-01-31/servlets-sling-case-disappearing-servlet-path/

Example code for calling AEM url with user name /password-

$.ajax ({ type: "GET", url: "/content/sites/test.html", dataType: 'json', async: false, headers: { "Authorization": "Basic " + btoa(USERNAME + ":" + PASSWORD) }, data: '{ "test" }', success: function (){ alert('success!'); } });
Level 4
February 2, 2016

Kunal,

Is that the standard way for AJAX call with parameters?

what's btoa in the headers? is that a standard jquery function? Are there other examples of similar ajax calls?