use of javax.jcr.PathNotFoundException in project jackrabbit-oak by apache.
the class AccessControlManagerImplTest method testSetPolicyPropertyPath.
@Test
public void testSetPolicyPropertyPath() throws Exception {
try {
String path = "/jcr:primaryType";
AccessControlPolicy acl = createPolicy(path);
acMgr.setPolicy(path, acl);
fail("Setting access control policy at property path should fail");
} catch (PathNotFoundException e) {
// success
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class BatchedItemOperations method copy.
/**
* Copies the tree at <code>srcPath</code> retrieved using the specified
* <code>srcStateMgr</code> to the new location at <code>destPath</code>.
* Returns the id of the node at its new position.
* <p>
* <b>Precondition:</b> the state manager needs to be in edit mode.
*
* @param srcPath
* @param srcStateMgr
* @param srcHierMgr
* @param srcAccessMgr
* @param destPath
* @param flag one of
* <ul>
* <li><code>COPY</code></li>
* <li><code>CLONE</code></li>
* <li><code>CLONE_REMOVE_EXISTING</code></li>
* </ul>
* @return the id of the node at its new position
* @throws ConstraintViolationException
* @throws AccessDeniedException
* @throws VersionException
* @throws PathNotFoundException
* @throws ItemExistsException
* @throws LockException
* @throws RepositoryException
* @throws IllegalStateException if the state manager is not in edit mode.
*/
public NodeId copy(Path srcPath, ItemStateManager srcStateMgr, HierarchyManager srcHierMgr, AccessManager srcAccessMgr, Path destPath, int flag) throws ConstraintViolationException, AccessDeniedException, VersionException, PathNotFoundException, ItemExistsException, LockException, RepositoryException, IllegalStateException {
// check precondition
checkInEditMode();
// 1. check paths & retrieve state
NodeState srcState = getNodeState(srcStateMgr, srcHierMgr, srcPath);
Path destParentPath = destPath.getAncestor(1);
NodeState destParentState = getNodeState(destParentPath);
int ind = destPath.getIndex();
if (ind > 0) {
// subscript in name element
String msg = "invalid copy destination path: " + safeGetJCRPath(destPath) + " (subscript in name element is not allowed)";
log.debug(msg);
throw new RepositoryException(msg);
}
// 2. check access rights, lock status, node type constraints, etc.
// JCR-2269: store target node state in changelog early as a
// precautionary measure in order to isolate it from concurrent
// underlying changes while checking preconditions
stateMgr.store(destParentState);
checkAddNode(destParentState, destPath.getName(), srcState.getNodeTypeName(), CHECK_ACCESS | CHECK_LOCK | CHECK_CHECKED_OUT | CHECK_CONSTRAINTS | CHECK_HOLD | CHECK_RETENTION);
// check read access right on source node using source access manager
try {
if (!srcAccessMgr.isGranted(srcPath, Permission.READ)) {
throw new PathNotFoundException(safeGetJCRPath(srcPath));
}
} catch (ItemNotFoundException infe) {
String msg = "internal error: failed to check access rights for " + safeGetJCRPath(srcPath);
log.debug(msg);
throw new RepositoryException(msg, infe);
}
// 3. do copy operation (modify and store affected states)
ReferenceChangeTracker refTracker = new ReferenceChangeTracker();
// create deep copy of source node state
NodeState newState = copyNodeState(srcState, srcPath, srcStateMgr, srcAccessMgr, destParentState.getNodeId(), flag, refTracker);
// add to new parent
destParentState.addChildNodeEntry(destPath.getName(), newState.getNodeId());
// adjust references that refer to uuid's which have been mapped to
// newly generated uuid's on copy/clone
Iterator<Object> iter = refTracker.getProcessedReferences();
while (iter.hasNext()) {
PropertyState prop = (PropertyState) iter.next();
// being paranoid...
if (prop.getType() != PropertyType.REFERENCE && prop.getType() != PropertyType.WEAKREFERENCE) {
continue;
}
boolean modified = false;
InternalValue[] values = prop.getValues();
InternalValue[] newVals = new InternalValue[values.length];
for (int i = 0; i < values.length; i++) {
NodeId adjusted = refTracker.getMappedId(values[i].getNodeId());
if (adjusted != null) {
boolean weak = prop.getType() == PropertyType.WEAKREFERENCE;
newVals[i] = InternalValue.create(adjusted, weak);
modified = true;
} else {
// reference doesn't need adjusting, just copy old value
newVals[i] = values[i];
}
}
if (modified) {
prop.setValues(newVals);
stateMgr.store(prop);
}
}
refTracker.clear();
// store states
stateMgr.store(newState);
stateMgr.store(destParentState);
return newState.getNodeId();
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class LuceneQueryFactory method getDescendantNodeQuery.
protected Query getDescendantNodeQuery(DescendantNode dn, JackrabbitIndexSearcher searcher) throws RepositoryException, IOException {
BooleanQuery query = new BooleanQuery();
int clauses = 0;
try {
LinkedList<String> ids = new LinkedList<String>();
Node ancestor = session.getNode(dn.getAncestorPath());
ids.add(ancestor.getIdentifier());
while (!ids.isEmpty()) {
String id = ids.removeFirst();
Query q = new JackrabbitTermQuery(new Term(FieldNames.PARENT, id));
QueryHits hits = searcher.evaluate(q);
ScoreNode sn = hits.nextScoreNode();
if (sn != null) {
// reset query so it does not overflow because of the max
// clause count condition,
// see JCR-3108
clauses++;
if (clauses == BooleanQuery.getMaxClauseCount()) {
BooleanQuery wrapQ = new BooleanQuery();
wrapQ.add(query, SHOULD);
query = wrapQ;
clauses = 1;
}
query.add(q, SHOULD);
do {
ids.add(sn.getNodeId().toString());
sn = hits.nextScoreNode();
} while (sn != null);
}
}
} catch (PathNotFoundException e) {
query.add(new JackrabbitTermQuery(new Term(FieldNames.UUID, // never matches
"invalid-node-id")), SHOULD);
}
return query;
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class AbstractWriteTest method testAccessControlRead.
public void testAccessControlRead() throws NotExecutableException, RepositoryException {
AccessControlManager testAcMgr = getTestACManager();
checkReadOnly(path);
// re-grant READ in order to have an ACL-node
Privilege[] privileges = privilegesFromName(Privilege.JCR_READ);
JackrabbitAccessControlList tmpl = givePrivileges(path, privileges, getRestrictions(superuser, path));
// make sure the 'rep:policy' node has been created.
assertTrue(superuser.itemExists(tmpl.getPath() + "/rep:policy"));
Session testSession = getTestSession();
/*
Testuser must still have READ-only access only and must not be
allowed to view the acl-node that has been created.
*/
assertFalse(testAcMgr.hasPrivileges(path, privilegesFromName(Privilege.JCR_READ_ACCESS_CONTROL)));
assertFalse(testSession.itemExists(path + "/rep:policy"));
Node n = testSession.getNode(tmpl.getPath());
assertFalse(n.hasNode("rep:policy"));
try {
n.getNode("rep:policy");
fail("Accessing the rep:policy node must throw PathNotFoundException.");
} catch (PathNotFoundException e) {
// ok.
}
/* Finally the test user must not be allowed to remove the policy. */
try {
testAcMgr.removePolicy(path, new AccessControlPolicy() {
});
fail("Test user must not be allowed to remove the access control policy.");
} catch (AccessDeniedException e) {
// success
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class AbstractImportXmlTest method importRefNodeDocument.
/**
* Creates a document with a element rootElem containing a jcr:uuid
* attribute with the given uuid as value. This document is imported below
* the node with path absPath. If nod node at absPth it is created.
* If there is yet a node rootElem below the then this node is
* romoved in advance.
*
* @param uuid
* @param uuidBehaviour
* @param withWorkspace
* @param withHandler
* @throws RepositoryException
* @throws IOException
*/
public void importRefNodeDocument(String absPath, String uuid, int uuidBehaviour, boolean withWorkspace, boolean withHandler) throws Exception {
Document document = dom.newDocument();
Element root = document.createElement(rootElem);
root.setAttribute(XML_NS + ":jcr", NS_JCR_URI);
root.setAttributeNS(NS_JCR_URI, jcrUUID, uuid);
root.setAttributeNS(NS_JCR_URI, jcrMixinTypes, mixReferenceable);
root.setAttribute(propertyName1, "some text");
document.appendChild(root);
Node targetNode = null;
try {
targetNode = (Node) session.getItem(absPath);
// remove a yet existing node at the target
try {
Node node = targetNode.getNode(rootElem);
node.remove();
session.save();
} catch (PathNotFoundException pnfe) {
// ok
}
} catch (PathNotFoundException pnfe) {
// create the node
targetNode = createAncestors(absPath);
}
if (withHandler) {
importWithHandler(targetNode.getPath(), document, uuidBehaviour, withWorkspace);
} else {
importXML(targetNode.getPath(), document, uuidBehaviour, withWorkspace);
}
session.save();
}
Aggregations