javax.jcr.AccessDeniedException: OakAccess0000: Access denied

Avatar

Avatar

deana66659071

Avatar

deana66659071

deana66659071

06-02-2017

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

View Entire Topic

Avatar

Avatar

Gdubz-57m2mu

Avatar

Gdubz-57m2mu

Gdubz-57m2mu

07-02-2017

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