use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.
the class L4_PrivilegesAndPermissionsTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
Property p = testRootNode.setProperty(propertyName1, "val");
propertyPath = p.getPath();
Node child = testRootNode.addNode(nodeName1);
childPath = child.getPath();
p = child.setProperty(propertyName2, "val");
childPropertyPath = p.getPath();
Node grandChild = child.addNode(nodeName2);
grandChildPath = grandChild.getPath();
testUser = ExerciseUtility.createTestUser(((JackrabbitSession) superuser).getUserManager());
Group testGroup = ExerciseUtility.createTestGroup(((JackrabbitSession) superuser).getUserManager());
testGroup.addMember(testUser);
superuser.save();
testPrincipal = testUser.getPrincipal();
testGroupPrincipal = testGroup.getPrincipal();
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.
the class AbstractRandomizedTest method clearAuthorizables.
protected void clearAuthorizables() throws RepositoryException {
for (JackrabbitSession s : writeSessions) {
UserManager userManager = s.getUserManager();
for (String id : ids) {
Authorizable a = userManager.getAuthorizable(id);
if (a != null) {
a.remove();
}
}
s.save();
}
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.
the class RandomizedReadTest method setupPermissions.
private void setupPermissions(int principalIndex, String path, boolean allow, String... privilegeNames) throws Exception {
for (JackrabbitSession session : writeSessions) {
Principal principal = getPrincipal(session, principalIndex);
AccessControlManager acm = session.getAccessControlManager();
JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acm, path);
acl.addEntry(principal, AccessControlUtils.privilegesFromNames(acm, privilegeNames), allow);
acm.setPolicy(path, acl);
session.save();
}
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.
the class AbstractImportTest method before.
@Before
public void before() throws Exception {
ConfigurationParameters config = getConfigurationParameters();
if (config != null) {
securityProvider = new SecurityProviderImpl(config);
} else {
securityProvider = new SecurityProviderImpl();
}
QueryEngineSettings queryEngineSettings = new QueryEngineSettings();
queryEngineSettings.setFailTraversal(true);
Jcr jcr = new Jcr();
jcr.with(securityProvider);
jcr.with(queryEngineSettings);
repo = jcr.createRepository();
adminSession = repo.login(new SimpleCredentials(UserConstants.DEFAULT_ADMIN_ID, UserConstants.DEFAULT_ADMIN_ID.toCharArray()));
if (!(adminSession instanceof JackrabbitSession)) {
throw new NotExecutableException();
}
userMgr = ((JackrabbitSession) adminSession).getUserManager();
preTestAuthorizables.clear();
Iterator<Authorizable> iter = userMgr.findAuthorizables("rep:principalName", null);
while (iter.hasNext()) {
String id = iter.next().getID();
preTestAuthorizables.add(id);
}
// make sure the target node for group-import exists
Authorizable administrators = userMgr.getAuthorizable(ADMINISTRATORS);
if (userMgr.getAuthorizable(ADMINISTRATORS) == null) {
userMgr.createGroup(new PrincipalImpl(ADMINISTRATORS));
} else if (!administrators.isGroup()) {
throw new NotExecutableException("Expected " + administrators.getID() + " to be a group.");
}
adminSession.save();
}
use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit-oak by apache.
the class SystemUserImportTest method testExistingPrincipal.
@Test
public void testExistingPrincipal() throws Exception {
Principal existing = null;
Session s = getImportSession();
PrincipalIterator principalIterator = ((JackrabbitSession) s).getPrincipalManager().getPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
while (principalIterator.hasNext()) {
Principal p = principalIterator.nextPrincipal();
if (getUserManager().getAuthorizable(p) != null) {
existing = p;
break;
}
}
if (existing == null) {
throw new 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:SystemUser</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:principalName\" sv:type=\"String\"><sv:value>" + existing.getName() + "</sv:value></sv:property>" + "</sv:node>";
try {
doImport(getTargetPath(), xml);
s.save();
fail("Import must detect conflicting principals.");
} catch (RepositoryException e) {
// success
}
}
Aggregations