use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.
the class UserAccessControlProviderTest method testAnonymousAccessDenied2.
public void testAnonymousAccessDenied2() throws Exception {
Map<String, String> config = new HashMap<String, String>();
config.put(UserAccessControlProvider.PARAM_ANONYMOUS_ACCESS, "false");
config.put(UserAccessControlProvider.PARAM_ANONYMOUS_ID, "abc");
AccessControlProvider p2 = new UserAccessControlProvider();
try {
p2.init(s, config);
Principal princ = new Principal() {
public String getName() {
return "abc";
}
};
Set<Principal> anonymousPrincipals = Collections.singleton(princ);
assertFalse(p2.canAccessRoot(anonymousPrincipals));
CompiledPermissions cp = p2.compilePermissions(anonymousPrincipals);
try {
assertEquals(CompiledPermissions.NO_PERMISSION, cp);
assertFalse(cp.canReadAll());
assertFalse(cp.grants(((NodeImpl) s.getRootNode()).getPrimaryPath(), Permission.READ));
} finally {
cp.close();
}
} finally {
p2.close();
}
}
use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.
the class UserImporterTest method testImportUser.
public void testImportUser() throws RepositoryException, IOException, SAXException, NotExecutableException {
String xml = "<?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:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>t</sv:value></sv:property>" + " <sv:property sv:name=\"rep:disabled\" sv:type=\"String\"><sv:value>disabledUser</sv:value></sv:property>" + "</sv:node>";
NodeImpl target = (NodeImpl) sImpl.getNode(umgr.getUsersPath());
try {
doImport(target, xml);
assertTrue(target.isModified());
assertTrue(sImpl.hasPendingChanges());
Authorizable newUser = umgr.getAuthorizable("t");
assertNotNull(newUser);
assertFalse(newUser.isGroup());
assertEquals("t", newUser.getPrincipal().getName());
assertEquals("t", newUser.getID());
assertTrue(((User) newUser).isDisabled());
assertEquals("disabledUser", ((User) newUser).getDisabledReason());
NodeImpl n = ((UserImpl) newUser).getNode();
assertTrue(n.isNew());
assertTrue(n.getParent().isSame(target));
assertEquals("t", n.getName());
assertEquals("t", n.getProperty(UserConstants.P_PRINCIPAL_NAME).getString());
assertEquals("{sha1}8efd86fb78a56a5145ed7739dcb00c78581c5375", n.getProperty(UserConstants.P_PASSWORD).getString());
assertEquals("disabledUser", n.getProperty(UserConstants.P_DISABLED).getString());
// saving changes of the import -> must succeed. add mandatory
// props should have been created.
sImpl.save();
} finally {
sImpl.refresh(false);
if (target.hasNode("t")) {
target.getNode("t").remove();
sImpl.save();
}
}
}
use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.
the class UserImporterTest method testAccessControlActionExecutionForUser.
public void testAccessControlActionExecutionForUser() throws Exception {
AccessControlAction a1 = new AccessControlAction();
a1.setUserPrivilegeNames(Privilege.JCR_ALL);
umgr.setAuthorizableActions(new AuthorizableAction[] { a1 });
String xml = "<?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:property sv:name=\"rep:principalName\" sv:type=\"String\"><sv:value>tPrincipal</sv:value></sv:property>" + "</sv:node>";
NodeImpl target = (NodeImpl) sImpl.getNode(umgr.getUsersPath());
try {
doImport(target, xml);
Authorizable a = umgr.getAuthorizable("t");
assertNotNull(a);
assertFalse(a.isGroup());
AccessControlManager acMgr = sImpl.getAccessControlManager();
AccessControlPolicy[] policies = acMgr.getPolicies(a.getPath());
assertNotNull(policies);
assertEquals(1, policies.length);
assertTrue(policies[0] instanceof AccessControlList);
AccessControlEntry[] aces = ((AccessControlList) policies[0]).getAccessControlEntries();
assertEquals(1, aces.length);
assertEquals("tPrincipal", aces[0].getPrincipal().getName());
} finally {
sImpl.refresh(false);
}
}
use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.
the class UserImporterTest method testIncompleteGroup.
public void testIncompleteGroup() throws IOException, RepositoryException, SAXException, NotExecutableException {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<sv:node sv:name=\"g\" 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:Group</sv:value></sv:property>" + " <sv:property sv:name=\"jcr:uuid\" sv:type=\"String\"><sv:value>b2f5ff47-4366-31b6-a533-d8dc3614845d</sv:value></sv:property>" + "</sv:node>";
/*
importing a group without rep:principalName property
- saving changes must fail with ConstraintViolationEx.
*/
NodeImpl target = (NodeImpl) sImpl.getNode(umgr.getGroupsPath());
try {
doImport(target, xml);
// saving changes of the import -> must fail as mandatory prop is missing
try {
sImpl.save();
fail("Import must be incomplete. Saving changes must fail.");
} catch (ConstraintViolationException e) {
// success
}
} finally {
sImpl.refresh(false);
if (target.hasNode("g")) {
target.getNode("g").remove();
sImpl.save();
}
}
}
use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.
the class UserAccessControlProviderTest method testAnonymousAccessDenied.
public void testAnonymousAccessDenied() throws Exception {
Map<String, String> config = new HashMap<String, String>();
config.put(UserAccessControlProvider.PARAM_ANONYMOUS_ACCESS, "false");
AccessControlProvider p2 = new UserAccessControlProvider();
try {
p2.init(s, config);
Set<Principal> anonymousPrincipals = getAnonymousPrincipals();
assertFalse(p2.canAccessRoot(anonymousPrincipals));
CompiledPermissions cp = p2.compilePermissions(anonymousPrincipals);
try {
assertEquals(CompiledPermissions.NO_PERMISSION, cp);
assertFalse(cp.canReadAll());
assertFalse(cp.grants(((NodeImpl) s.getRootNode()).getPrimaryPath(), Permission.READ));
} finally {
cp.close();
}
} finally {
p2.close();
}
}
Aggregations