Expand my Community achievements bar.

QueryBuilder loadQuery throws a javax.jcr.AccessDeniedException: Root node is not accessible.

Avatar

Former Community Member

Hi folks,

Trying to use the QueryBuilder loadQuery method... basically loading a QB predicate string from a content node.

This works if running as an administrator... but otherwise throws the javax.jcr.AccessDeniedException: Root node is not accessible exception.

The "serviceUser" has full read permissions on jcr content node tree... but this isnt enough. If I add user to "Administrators" group, it works, no access denied exception is thrown.

 

We're running AEM 6.1..soon to be on 6.2

Code:

 

public ArrayList<String> query(String savedQuery) throws RepositoryException, LoginException, IOException { ArrayList<String> resultNodePaths = new ArrayList<String>(); Map<String, Object> param = new HashMap<String, Object>(); param.put(ResourceResolverFactory.SUBSERVICE, "ServiceUser"); ResourceResolver resourceResolver = null; try { resourceResolver = resolverFactory .getServiceResourceResolver(param); session = resourceResolver.adaptTo(Session.class); QueryBuilder queryBuilder = resourceResolver.adaptTo(QueryBuilder.class); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Executing stored query from: " + savedQuery); } Query query = queryBuilder.loadQuery(savedQuery, session); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Query predicates: " + query.getPredicates().toString()); } SearchResult result = query.getResult(); Iterator<Node> resultIterator = result.getNodes(); while (resultIterator.hasNext()) { Node node = resultIterator.next(); LOGGER.debug("Node path : " + node.getPath()); resultNodePaths.add(node.getPath()); } } catch (LoginException e) { LOGGER.error("ERROR IN EXECUTE CONTENT QUERY.", e); throw e; } catch (RepositoryException e) { LOGGER.error("ERROR IN EXECUTE CONTENT QUERY.", e); throw e; } catch (IOException e) { LOGGER.error("ERROR IN EXECUTE CONTENT QUERY.", e); throw e; } finally { if (resourceResolver != null) { resourceResolver.close(); LOGGER.debug("CLOSED RESOURCE RESOLVER IN EXECUTE CONTENT QUERY."); } } return resultNodePaths; }

Is this by design?

0 Replies