use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class ACLProvider method getEffectivePolicies.
/**
* @see org.apache.jackrabbit.core.security.authorization.AccessControlProvider#getEffectivePolicies(org.apache.jackrabbit.spi.Path,org.apache.jackrabbit.core.security.authorization.CompiledPermissions)
*/
public AccessControlPolicy[] getEffectivePolicies(Path absPath, CompiledPermissions permissions) throws ItemNotFoundException, RepositoryException {
if (absPath == null) {
// TODO: JCR-2774
log.warn("TODO: JCR-2774 - Repository level permissions.");
return new AccessControlPolicy[0];
}
String jcrPath = session.getJCRPath(absPath);
String pName = ISO9075.encode(session.getJCRName(ACLTemplate.P_NODE_PATH));
int ancestorCnt = absPath.getAncestorCount();
// search all ACEs whose rep:nodePath property equals the specified
// absPath or any of it's ancestors
StringBuilder stmt = new StringBuilder("/jcr:root");
stmt.append(acRoot.getPath());
stmt.append("//element(*,");
stmt.append(session.getJCRName(NT_REP_ACE));
stmt.append(")[");
for (int i = 0; i <= ancestorCnt; i++) {
String path = Text.getRelativeParent(jcrPath, i);
if (i > 0) {
stmt.append(" or ");
}
stmt.append("@");
stmt.append(pName);
stmt.append("='");
stmt.append(path.replaceAll("'", "''"));
stmt.append("'");
}
stmt.append("]");
QueryResult result;
try {
QueryManager qm = session.getWorkspace().getQueryManager();
Query q = qm.createQuery(stmt.toString(), Query.XPATH);
result = q.execute();
} catch (RepositoryException e) {
log.error("Unexpected error while searching effective policies. {}", e.getMessage());
throw new UnsupportedOperationException("Retrieve effective policies at absPath '" + jcrPath + "' not supported.", e);
}
/**
* Loop over query results and verify that
* - the corresponding ACE really takes effect on the specified absPath.
* - the corresponding ACL can be read by the editing session.
*/
Set<AccessControlPolicy> acls = new LinkedHashSet<AccessControlPolicy>();
for (NodeIterator it = result.getNodes(); it.hasNext(); ) {
Node aceNode = it.nextNode();
String accessControlledNodePath = Text.getRelativeParent(aceNode.getPath(), 2);
Path acPath = session.getQPath(accessControlledNodePath);
AccessControlPolicy[] policies = editor.getPolicies(accessControlledNodePath);
if (policies.length > 0) {
ACLTemplate acl = (ACLTemplate) policies[0];
for (AccessControlEntry ace : acl.getAccessControlEntries()) {
ACLTemplate.Entry entry = (ACLTemplate.Entry) ace;
if (entry.matches(jcrPath)) {
if (permissions.grants(acPath, Permission.READ_AC)) {
acls.add(new UnmodifiableAccessControlList(acl));
break;
} else {
throw new AccessDeniedException("Access denied at " + accessControlledNodePath);
}
}
}
}
}
return acls.toArray(new AccessControlPolicy[acls.size()]);
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class ShareableNodeTest method testSearch.
/**
* Verify that a descendant of a shareable node appears once in the
* result set (6.13.23)
*/
public void testSearch() throws Exception {
// setup parent nodes and first child
Node a1 = testRootNode.addNode("a1");
Node a2 = testRootNode.addNode("a2");
Node b1 = a1.addNode("b1");
testRootNode.getSession().save();
// add mixin
ensureMixinType(b1, mixShareable);
b1.save();
// clone
Workspace workspace = b1.getSession().getWorkspace();
workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false);
// add new referenceable child
Node c = b1.addNode("c");
ensureMixinType(c, mixReferenceable);
b1.save();
String sql = "SELECT * FROM nt:unstructured WHERE jcr:uuid = '" + c.getUUID() + "'";
QueryResult res = workspace.getQueryManager().createQuery(sql, Query.SQL).execute();
List<Node> list = new ArrayList<Node>();
NodeIterator iter = res.getNodes();
while (iter.hasNext()) {
list.add(iter.nextNode());
}
assertEquals(1, list.size());
assertTrue(list.get(0).isSame(c));
}
use of javax.jcr.query.QueryResult in project jackrabbit-oak by apache.
the class TextExtractionQueryTest method testScoreWithoutFulltext.
public void testScoreWithoutFulltext() throws Exception {
System.out.println(Query.JCR_SQL2);
QueryResult r = executeSQL2Query("select [jcr:path] from [nt:base] order by [jcr:score]");
RowIterator it = r.getRows();
while (it.hasNext()) {
it.nextRow();
}
}
use of javax.jcr.query.QueryResult in project jackrabbit-oak by apache.
the class FacetTest method testFacetRetrievalNumberOfFacetsConfiguredLowerThanDefault.
public void testFacetRetrievalNumberOfFacetsConfiguredLowerThanDefault() throws RepositoryException {
Node facetsConfig = superuser.getNode(FACET_CONFING_NODE_PATH);
facetsConfig.setProperty(LuceneIndexConstants.PROP_FACETS_TOP_CHILDREN, 7);
markIndexForReindex();
superuser.save();
superuser.refresh(true);
Session session = superuser;
Node n1 = testRootNode.addNode("node1");
String pn = "jcr:title";
n1.setProperty(pn, "hello 1");
Node n2 = testRootNode.addNode("node2");
n2.setProperty(pn, "hallo 2");
Node n3 = testRootNode.addNode("node3");
n3.setProperty(pn, "hallo 3");
Node n4 = testRootNode.addNode("node4");
n4.setProperty(pn, "hallo 4");
Node n5 = testRootNode.addNode("node5");
n5.setProperty(pn, "hallo 5");
Node n6 = testRootNode.addNode("node6");
n6.setProperty(pn, "hallo 6");
Node n7 = testRootNode.addNode("node7");
n7.setProperty(pn, "hallo 7");
Node n8 = testRootNode.addNode("node8");
n8.setProperty(pn, "hallo 8");
Node n9 = testRootNode.addNode("node9");
n9.setProperty(pn, "hallo 9");
Node n10 = testRootNode.addNode("node10");
n10.setProperty(pn, "hallo 10");
Node n11 = testRootNode.addNode("node11");
n11.setProperty(pn, "hallo 11");
Node n12 = testRootNode.addNode("node12");
n12.setProperty(pn, "hallo 12");
session.save();
QueryManager qm = session.getWorkspace().getQueryManager();
String sql2 = "select [jcr:path], [rep:facet(" + pn + ")] from [nt:base] " + "where contains([" + pn + "], 'hallo') order by [jcr:path]";
Query q = qm.createQuery(sql2, Query.JCR_SQL2);
QueryResult result = q.execute();
FacetResult facetResult = new FacetResult(result);
assertNotNull(facetResult);
assertNotNull(facetResult.getDimensions());
assertEquals(1, facetResult.getDimensions().size());
assertTrue(facetResult.getDimensions().contains(pn));
List<FacetResult.Facet> facets = facetResult.getFacets(pn);
assertNotNull(facets);
assertEquals(7, facets.size());
}
use of javax.jcr.query.QueryResult in project jackrabbit-oak by apache.
the class LuceneIndexSuggestionTest method suggestNodeName.
//OAK-3825
@Test
public void suggestNodeName() throws Exception {
final String nodeType = "nt:unstructured";
createSuggestIndex("lucene-suggest", nodeType, LuceneIndexConstants.PROPDEF_PROP_NODE_NAME);
root.addNode("indexedNode", nodeType);
session.save();
String suggQuery = createSuggestQuery(nodeType, "indexedn");
QueryManager queryManager = session.getWorkspace().getQueryManager();
QueryResult result = queryManager.createQuery(suggQuery, Query.JCR_SQL2).execute();
RowIterator rows = result.getRows();
String value = null;
while (rows.hasNext()) {
Row firstRow = rows.nextRow();
value = firstRow.getValue("suggestion").getString();
break;
}
assertEquals("Node name should be suggested", "indexedNode", value);
}
Aggregations