use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class AcReadWriteTest method testReadAccessControl.
public void testReadAccessControl() throws NotExecutableException, RepositoryException {
/* precondition:
testuser must have READ-only permission on test-node and below
*/
checkReadOnly(path);
/* give 'testUser' jcr:readAccessControl privileges at subtree below
path excluding the node at path itself. */
Privilege[] privileges = privilegesFromNames(new String[] { Privilege.JCR_READ_ACCESS_CONTROL });
Map<String, Value> restrictions = new HashMap<String, Value>(getRestrictions(superuser, path));
restrictions.put(AccessControlConstants.P_GLOB.toString(), vf.createValue("/" + nodeName2));
JackrabbitAccessControlList tmpl = givePrivileges(path, privileges, restrictions);
/*
testuser must not be allowed to read AC content at the target node;
however, retrieving potential AC content at 'childPath' is granted.
*/
Session testSession = getTestSession();
AccessControlManager testAcMgr = getTestACManager();
assertFalse(testAcMgr.hasPrivileges(path, privileges));
try {
testAcMgr.getPolicies(path);
fail("AccessDeniedException expected");
} catch (AccessDeniedException e) {
// success.
}
assertTrue(testAcMgr.hasPrivileges(childNPath, privileges));
assertEquals(0, testAcMgr.getPolicies(childNPath).length);
/* similarly reading the corresponding AC items at 'path' must be forbidden */
String aclNodePath = null;
Node n = superuser.getNode(path);
for (NodeIterator itr = n.getNodes(); itr.hasNext(); ) {
Node child = itr.nextNode();
if (child.isNodeType("rep:Policy")) {
aclNodePath = child.getPath();
}
}
if (aclNodePath == null) {
fail("Expected node at " + path + " to have an ACL child node.");
}
assertFalse(testSession.nodeExists(aclNodePath));
for (NodeIterator aceNodes = superuser.getNode(aclNodePath).getNodes(); aceNodes.hasNext(); ) {
Node aceNode = aceNodes.nextNode();
String aceNodePath = aceNode.getPath();
assertFalse(testSession.nodeExists(aceNodePath));
for (PropertyIterator it = aceNode.getProperties(); it.hasNext(); ) {
assertFalse(testSession.propertyExists(it.nextProperty().getPath()));
}
}
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class ExportDocViewTest method compareNode.
/**
* Compares the given node with the given element. Comparison is succesful
* if the number of exported child nodes and exported properties match the
* found child elements and attributes considering the possible exceptions
* and if the comparison of the properties of the node with the attributes
* of the element is successful too.
*
* @param node
* @param elem
* @throws RepositoryException
*/
private void compareNode(Node node, Element elem) throws RepositoryException, IOException {
// count the child nodes and compare with the exported child elements
compareChildNumber(node, elem);
// count the properties and compare with attributes exported
comparePropNumber(node, elem);
PropertyIterator propIter = node.getProperties();
while (propIter.hasNext()) {
Property prop = propIter.nextProperty();
Attr attr = findAttribute(prop, elem);
checkAttribute(prop, attr);
if (attr != null) {
compareProperty(prop, attr);
}
}
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class ExportDocViewTest method setExportInvalidXmlNames.
/**
* Loops through all child items of a given node to test if items with
* invalid xml name are exported. (chapter 6.4.2.4 of the JCR
* specification).
*
* @param node the root node of the tree to search
* @param elem the parent element of the element to which the parent node of
* the given node is exported.
* @throws RepositoryException
*/
private boolean setExportInvalidXmlNames(Node node, Element elem, boolean isSet) throws RepositoryException {
if (!XMLChar.isValidName(node.getName())) {
if (elem != null) {
exportInvalidXmlNames = true;
isSet = true;
} else {
exportInvalidXmlNames = false;
isSet = true;
}
}
// try properties
if (!isSet) {
PropertyIterator iter = node.getProperties();
while (iter.hasNext()) {
Property prop = iter.nextProperty();
if (!exportMultivalProps && prop.getDefinition().isMultiple()) {
continue;
}
if (!XMLChar.isValidName(prop.getName())) {
// property exported?
exportInvalidXmlNames = isExportedProp(prop, elem);
isSet = true;
}
}
}
// try child nodes
if (!isSet && !noRecurse) {
// search again
NodeIterator iter = node.getNodes();
while (iter.hasNext()) {
Node n = iter.nextNode();
Element el = findElem(n, elem);
isSet = setExportInvalidXmlNames(n, el, isSet);
}
}
return isSet;
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class DocumentViewImportTest method checkXmlTextNode.
/**
* Tests if xmltext in a body of a xml element is correctly imported to a
* node with name jcr:xmltext and that the value of the text is stored in
* the singlevalued jcr:xmlcharacters property of String type.
*
* @throws RepositoryException
*/
public void checkXmlTextNode(Node node) throws RepositoryException, IOException {
if (node.hasNode(JCR_XMLTEXT)) {
Node xmlNode = node.getNode(JCR_XMLTEXT);
if (xmlNode.hasProperty(JCR_XMLCHAR)) {
Property prop = xmlNode.getProperty(JCR_XMLCHAR);
// correct type?
assertTrue("Property " + prop.getPath() + " is not of type String.", prop.getType() == PropertyType.STRING);
// correct text?
// todo remove the trim as only the white spaces of the current text should be collected
assertEquals("Xml text is not correctly stored.", xmltext.trim(), prop.getString().trim());
// only jcr:xmlcharacters property beneath the jcr:primaryType
PropertyIterator iter = xmlNode.getProperties();
assertTrue(JCR_XMLCHAR + " is not the only property beneath " + jcrPrimaryType + " in a " + JCR_XMLTEXT + " node.", getSize(iter) == 2);
} else {
fail("Xmltext not stored in property named " + JCR_XMLCHAR);
}
} else {
fail("Xmltext not imported to Node named " + JCR_XMLTEXT);
}
}
use of javax.jcr.PropertyIterator in project jackrabbit by apache.
the class NodeReadMethodsTest method testGetProperty.
/**
* Test if getProperty(String relPath) returns the correct node and if a
* PathNotFoundException is thrown when property at relPath does not exist
*/
public void testGetProperty() throws NotExecutableException, RepositoryException {
StringBuffer notExistingPath = new StringBuffer("X");
PropertyIterator properties = testRootNode.getProperties();
while (properties.hasNext()) {
// build a path that for sure is not existing
// (":" of namespace prefix will be replaced later on)
notExistingPath.append(properties.nextProperty().getName());
}
try {
testRootNode.getProperty(notExistingPath.toString().replaceAll(":", ""));
fail("getProperty(String relPath) must throw a " + "PathNotFoundException if no node exists at relPath");
} catch (PathNotFoundException e) {
// success
}
try {
PropertyIterator properties2 = testRootNode.getProperties();
Property property = properties2.nextProperty();
assertTrue("Property returned by getProperties() is not the same as returned by getProperty(String).", testRootNode.getProperty(property.getName()).isSame(property));
} catch (NoSuchElementException e) {
fail("Root node must always have at least one property: jcr:primaryType");
}
}
Aggregations