use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit-oak by apache.
the class AuthorizablePropertiesImpl method checkProtectedProperty.
private void checkProtectedProperty(@Nonnull Tree parent, @Nonnull PropertyState property) throws RepositoryException {
ReadOnlyNodeTypeManager nodeTypeManager = authorizable.getUserManager().getNodeTypeManager();
PropertyDefinition def = nodeTypeManager.getDefinition(parent, property, false);
if (def.isProtected()) {
throw new ConstraintViolationException("Attempt to set an protected property " + property.getName());
}
}
use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit-oak by apache.
the class UserImportTest method testIncompleteUser.
@Test
public void testIncompleteUser() throws Exception {
List<String> incompleteXml = new ArrayList<String>();
incompleteXml.add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sv:node sv:name=\"t\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" + " <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:User</sv:value></sv:property>" + " <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>e358efa4-89f5-3062-b10d-d7316b65649e</sv:value></sv:property>" + " <sv:property sv:name=\"rep:password\" sv:type=\"String\"><sv:value>{sha1}8efd86fb78a56a5145ed7739dcb00c78581c5375</sv:value></sv:property>" + "</sv:node>");
incompleteXml.add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sv:node sv:name=\"t\" xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\" xmlns:fn_old=\"http://www.w3.org/2004/10/xpath-functions\" xmlns:fn=\"http://www.w3.org/2005/xpath-functions\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:sv=\"http://www.jcp.org/jcr/sv/1.0\" xmlns:rep=\"internal\" xmlns:jcr=\"http://www.jcp.org/jcr/1.0\">" + " <sv:property sv:name=\"jcr:primaryType\" sv:type=\"Name\"><sv:value>rep:User</sv:value></sv:property>" + " <sv:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>t</sv:value></sv:property>" + "</sv:node>");
Session s = getImportSession();
for (String xml : incompleteXml) {
Node target = s.getNode(getTargetPath());
try {
doImport(getTargetPath(), xml);
// saving changes of the import -> must fail as mandatory prop is missing
try {
s.save();
fail("Import must be incomplete. Saving changes must fail.");
} catch (ConstraintViolationException e) {
// success
}
} finally {
s.refresh(false);
if (target.hasNode("t")) {
target.getNode("t").remove();
s.save();
}
}
}
}
use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit-oak by apache.
the class AuthorizablePropertyTest method testRemoveSpecialGroupPropertiesDirectly.
@Test
public void testRemoveSpecialGroupPropertiesDirectly() throws RepositoryException, NotExecutableException {
Node n = getNode(group, superuser);
try {
if (n.hasProperty(UserConstants.REP_PRINCIPAL_NAME)) {
n.getProperty(UserConstants.REP_PRINCIPAL_NAME).remove();
fail("Attempt to remove protected property rep:principalName should fail.");
}
} catch (ConstraintViolationException e) {
// ok.
}
try {
if (n.hasProperty(UserConstants.REP_MEMBERS)) {
n.getProperty(UserConstants.REP_MEMBERS).remove();
fail("Attempt to remove protected property rep:members should fail.");
}
} catch (ConstraintViolationException e) {
// ok.
}
}
use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit-oak by apache.
the class AuthorizablePropertyTest method testRemoveSpecialUserPropertiesDirectly.
@Test
public void testRemoveSpecialUserPropertiesDirectly() throws RepositoryException, NotExecutableException {
Node n = getNode(user, superuser);
try {
n.getProperty(UserConstants.REP_PASSWORD).remove();
fail("Attempt to remove protected property rep:password should fail.");
} catch (ConstraintViolationException e) {
// ok.
}
try {
if (n.hasProperty(UserConstants.REP_PRINCIPAL_NAME)) {
n.getProperty(UserConstants.REP_PRINCIPAL_NAME).remove();
fail("Attempt to remove protected property rep:principalName should fail.");
}
} catch (ConstraintViolationException e) {
// ok.
}
}
use of javax.jcr.nodetype.ConstraintViolationException in project jackrabbit-oak by apache.
the class AccessControlManagementTest method testAcContentIsProtected.
@Test
public void testAcContentIsProtected() throws Exception {
// search for a rep:policy node
Node policyNode = findPolicyNode(superuser.getRootNode());
if (policyNode == null) {
throw new NotExecutableException("no policy node found.");
}
assertTrue("The rep:Policy node must be protected", policyNode.getDefinition().isProtected());
try {
policyNode.remove();
fail("rep:Policy node must be protected.");
} catch (ConstraintViolationException e) {
// success
}
for (NodeIterator it = policyNode.getNodes(); it.hasNext(); ) {
Node n = it.nextNode();
if (n.isNodeType("rep:ACE")) {
try {
n.remove();
fail("ACE node must be protected.");
} catch (ConstraintViolationException e) {
// success
}
break;
}
}
try {
policyNode.setProperty("test", "anyvalue");
fail("rep:policy node must be protected.");
} catch (ConstraintViolationException e) {
// success
}
try {
policyNode.addNode("test", "rep:ACE");
fail("rep:policy node must be protected.");
} catch (ConstraintViolationException e) {
// success
}
}
Aggregations