Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Dynamically node creation in AEM publisher without administrative access

Avatar

Level 2

I have one scenario to discuss in programatically node creation in JCR with out administrative access.

Is there any way we can create node in publisher , lets say we hit the URL like below via dispatcher

http://example.domain.com/content/project/example.html

and in the component jsp we will write some code to create the node, if not present in Publisher JCR.

Right now the node creation is happening , but only when we logged in the publisher.

I need to create the node , with out logging to JCR .

Can anybody help?

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi,

In publish you are acessing the repository using the anonymous user, which does not have any write permission (which is a good thing). So you need to bypass this restriction, and the easiest and most secure way is to create a user, which has write access on the specific area, where you need to write. Nothing more. And then write a service, which uses this user's session to write the data. The service is called from your component.

But: I think, that in your design there are some shortcomings, when you need to create content nodes on publish in a non-UGC context. Carefully review if you can do this in a more controlled manner. Because you open a can of worms, if these write activities are not properly controlled.

kind regards,
Jörg

View solution in original post

3 Replies

Avatar

Level 10

I think you should probably take a look at comments component in AEM 

There for every comment a node gets created., it uses anonymous user and sing default post servlet. have a look this page

http://localhost:4502/cf#/content/geometrixx-media/en/entertainment/summer-blockbuster-hits-and-miss...

Avatar

Correct answer by
Employee Advisor

Hi,

In publish you are acessing the repository using the anonymous user, which does not have any write permission (which is a good thing). So you need to bypass this restriction, and the easiest and most secure way is to create a user, which has write access on the specific area, where you need to write. Nothing more. And then write a service, which uses this user's session to write the data. The service is called from your component.

But: I think, that in your design there are some shortcomings, when you need to create content nodes on publish in a non-UGC context. Carefully review if you can do this in a more controlled manner. Because you open a can of worms, if these write activities are not properly controlled.

kind regards,
Jörg

Avatar

Level 10

You can create a Sling Servlet and bind it to the resource that is rendered at that URL. In the Sling Servlet - you can use the JCR API or SLing API to create nodes dynamically. Then make sure that you deploy the OSGi that contains the Sling Servlet to Pub. 

For access to the JCR - make sure that you create a dedicated user account and that account has read/write privileges to the JCR location where you want to create nodes.