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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

javax.jcr.AccessDeniedException: OakAccess0000: Access denied

Avatar

Level 4

Here is an example of what I'm seeing in the logs:

06.02.2017 12:44:06.231 *ERROR* [10.1.51.108 [1486410246131] GET /content/business/enterprise/assets/gartner-magic-quadrant-for-cloud-infrastructure-as-service-2015.html HTTP/1.1] com.adobe.cq.sightly.WCMUsePojo Failed to activate Use class
javax.jcr.AccessDeniedException: OakAccess0000: Access denied
        at org.apache.jackrabbit.oak.api.CommitFailedException.asRepositoryException(CommitFailedException.java:231)
        at org.apache.jackrabbit.oak.api.CommitFailedException.asRepositoryException(CommitFailedException.java:212)
        at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.newRepositoryException(SessionDelegate.java:670)
        at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.save(SessionDelegate.java:496)
        at org.apache.jackrabbit.oak.jcr.session.SessionImpl$8.performVoid(SessionImpl.java:419)
        at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.performVoid(SessionDelegate.java:274)
        at org.apache.jackrabbit.oak.jcr.session.SessionImpl.save(SessionImpl.java:416)
        at ewcm.sightly.components.ColumnControl.activate(ColumnControl.java:112)
        at com.adobe.cq.sightly.WCMUsePojo.init(WCMUsePojo.java:84)

Any thoughts is greatly appreciated.

 

Thanks,

 

-Dean

1 Accepted Solution

Avatar

Correct answer by
Level 10

Create a service named Foo (as an example) that does you JCR modification (for example - retrieve data, delete data etc). Then in your @Service/@Component Foo class - use a System user and Sling Mapping - see this for information: 

http://scottsdigitalcommunity.blogspot.ca/2014/12/querying-adobe-experience-manager-6.html (there is a video too that steps you through) 

Then in your WCMUsePojo - get a instance of this class:

fooService = getSlingScriptHelper().getService(Foo.class);

This is how you get a object of an AEM Service from a class that extends WCMUsePojo. 

We will have this in a HELPX article --

http://scottsdigitalcommunity.blogspot.ca/2017/02/creating-aem-htl-component-that-queries.html

View solution in original post

9 Replies

Avatar

Level 10

Are you trying to perform some JCR Operations from a WCMUsePojo class? Looks like something is happening in an HTL component. 

Avatar

Level 4

As a matter of fact, I am.  I check to see if there is a sling:resourceType associated with the component and if there is NOT, I add one.

Once I'm done I call save.

Is this not allowed?

Avatar

Correct answer by
Level 10

Create a service named Foo (as an example) that does you JCR modification (for example - retrieve data, delete data etc). Then in your @Service/@Component Foo class - use a System user and Sling Mapping - see this for information: 

http://scottsdigitalcommunity.blogspot.ca/2014/12/querying-adobe-experience-manager-6.html (there is a video too that steps you through) 

Then in your WCMUsePojo - get a instance of this class:

fooService = getSlingScriptHelper().getService(Foo.class);

This is how you get a object of an AEM Service from a class that extends WCMUsePojo. 

We will have this in a HELPX article --

http://scottsdigitalcommunity.blogspot.ca/2017/02/creating-aem-htl-component-that-queries.html

Avatar

Level 4

I'm not sure what I'm missing here .... this is what I have so far

 

    @Reference
    private ResourceResolverFactory factory;
    private ResourceResolver resourceResolverWriter;
    private static Session adminSession;
    
    /*
     * data structure to store attributes for each column
     */
    private ArrayList<Map<String, String>> columns;

    /*
     * should flyIn css classes be added to the columns
     */
    private boolean animateFlyIn;

    @SuppressWarnings("deprecation")
    @Override
    public void activate() throws Exception {

        try {
            Map<String, Object> param = new HashMap<String, Object>();        
            param.put(ResourceResolverFactory.SUBSERVICE, "writeService");
            resourceResolverWriter = factory.getServiceResourceResolver(param);            
            adminSession = resourceResolverWriter.adaptTo(Session.class);
            


factory is ALWAYS nulll .... I'm a little lost on how to resolve.

Thanks,

-Dean

Avatar

Level 10

Dean, i will look into this tomorrow and get it wirking!

Avatar

Level 4

Here is another example of things that I've tried ....

**************************************************************************************************

public interface ColumnControlService {

    public void generateColumns(int columns, Node currentNode);
    
}

**************************************************************************************************

@Component
@Service
public class ColumnControlServiceImpl implements ColumnControlService {

    private final Logger logger = LoggerFactory.getLogger(ColumnControlServiceImpl.class);

    @Reference
    private ResourceResolverFactory factory;
    private ResourceResolver resourceResolverWriter;
    private static Session adminSession;

    public void generateColumns(int columns, Node currentNode) {

        try {
            Map<String, Object> param = new HashMap<String, Object>();        
            param.put(ResourceResolverFactory.SUBSERVICE, "writeService");
            resourceResolverWriter = factory.getServiceResourceResolver(param);            
            adminSession = resourceResolverWriter.adaptTo(Session.class);

**************************************************************************************************

public class ColumnControl extends WCMUsePojo {

    private final Logger logger = LoggerFactory.getLogger(ColumnControl.class);

    @Reference
    private ColumnControlService ccs;

    @Override
    public void activate() throws Exception {

        try {
            Node currentNode = getResource().adaptTo(Node.class);
            ccs.generateColumns(columns.size(), currentNode);

 

The css reference in the line above always returns NULL.

Avatar

Level 10

I am looking into this code right now - something seems strange. 

Avatar

Level 5

Hi Dean,

Unless I'm mistaken, simply extending WCMUsePojo does not allow you the ability to use @Reference annotations to pull other services/components into your class. Your class would either need to be a @Service or @Component itself in order to have this luxury.

One thing you COULD do is get a reference through the SlingScriptHelper[1] interface, like so:

package com.your.pkg.name; import com.adobe.cq.sightly.WCMUsePojo; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.resource.ResourceResolverFactory; import org.apache.sling.api.resource.ResourceUtil; import org.apache.sling.api.resource.ValueMap; import org.apache.sling.api.scripting.SlingScriptHelper; import java.util.HashMap; import java.util.Map; /** * Created by Greg Wells on 2/7/17. */ public class TestService extends WCMUsePojo { @Override public void activate() throws Exception { // get a sling script helper, this is available globally through the WCMUsePojo class SlingScriptHelper sling = getSlingScriptHelper(); // get a reference to the ResourceResolverFactory ResourceResolverFactory resourceResolverFactory = sling.getService(ResourceResolverFactory.class); // define your service params Map<String, Object> serviceParams = new HashMap<>(); serviceParams.put(ResourceResolverFactory.SUBSERVICE, "writeService"); // get your service resolver in a try-with-resources block try (ResourceResolver serviceResolver = resourceResolverFactory.getServiceResourceResolver(serviceParams)) { // do whatever you need with your service resolver here... Resource resource = serviceResolver.getResource("/some/path/to/a/resource"); ValueMap valueMap = ResourceUtil.getValueMap(resource); if (valueMap.containsKey("customPropName")) { String customPropValue = valueMap.get("customPropName", String.class); // do something with this String value... } } } }

Let me know if any of that doesn't make sense, hope this helps!

EDIT: One caveat to doing this, you may run into a situation like the one I posted about earlier today[2]... If that is the case, you may not be able to use the SlingScriptHelper as its BundleContext[3] is different than your own bundle, most likely. The following should work instead:

package com.your.pkg.name; import com.adobe.cq.sightly.WCMUsePojo; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.resource.ResourceResolverFactory; import org.apache.sling.api.resource.ResourceUtil; import org.apache.sling.api.resource.ValueMap; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference; import java.util.HashMap; import java.util.Map; /** * Created by Greg Wells on 2/7/17. */ public class TestService extends WCMUsePojo { @Override public void activate() throws Exception { // get the ResourceResolverFactory directly from your own bundle. BundleContext bundleContext = FrameworkUtil.getBundle(TestService.class).getBundleContext(); ServiceReference factoryRef = bundleContext.getServiceReference(ResourceResolverFactory.class.getName()); ResourceResolverFactory resourceResolverFactory = (ResourceResolverFactory) bundleContext.getService(factoryRef); // define your service params Map<String, Object> serviceParams = new HashMap<>(); serviceParams.put(ResourceResolverFactory.SUBSERVICE, "writeService"); // get your service resolver in a try-with-resources block try (ResourceResolver serviceResolver = resourceResolverFactory.getServiceResourceResolver(serviceParams)) { // do whatever you need with your service resolver here... Resource resource = serviceResolver.getResource("/some/path/to/a/resource"); ValueMap valueMap = ResourceUtil.getValueMap(resource); if (valueMap.containsKey("customPropName")) { String customPropValue = valueMap.get("customPropName", String.class); // do something with this String value... } } } }

[1] https://sling.apache.org/apidocs/sling8/org/apache/sling/api/scripting/SlingScriptHelper.html
[2] http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...
[3] http://www.knopflerfish.org/releases/5.2.0/docs/javadoc/org/osgi/framework/BundleContext.html

Avatar

Level 10

Excellent post Greg - @Reference cannot be used in class that extends WCMUsePojo  - see the article i referenced that shows How TO get an instance of an AEM service from WCMUsePojo.