use of org.apache.jackrabbit.core.TransientRepository in project camel by apache.
the class JcrAuthTestBase method createJndiContext.
@Override
protected Context createJndiContext() throws Exception {
Context context = super.createJndiContext();
repository = new TransientRepository(new File(REPO_PATH));
// set up a user to authenticate
SessionImpl session = (SessionImpl) repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
UserManager userManager = session.getUserManager();
User user = (User) userManager.getAuthorizable("test");
if (user == null) {
user = userManager.createUser("test", "quatloos");
}
// set up permissions
String path = session.getRootNode().getPath();
AccessControlManager accessControlManager = session.getAccessControlManager();
AccessControlPolicyIterator acls = accessControlManager.getApplicablePolicies(path);
AccessControlList acl = null;
if (acls.hasNext()) {
acl = (AccessControlList) acls.nextAccessControlPolicy();
} else {
acl = (AccessControlList) accessControlManager.getPolicies(path)[0];
}
acl.addAccessControlEntry(user.getPrincipal(), accessControlManager.getSupportedPrivileges(path));
accessControlManager.setPolicy(path, acl);
session.save();
session.logout();
context.bind("repository", repository);
return context;
}
use of org.apache.jackrabbit.core.TransientRepository in project camel by apache.
the class JcrRouteTestSupport method createJndiContext.
@Override
protected Context createJndiContext() throws Exception {
File config = new File(CONFIG_FILE);
if (!config.exists()) {
throw new FileNotFoundException("Missing config file: " + config.getPath());
}
Context context = super.createJndiContext();
repository = new TransientRepository(CONFIG_FILE, REPO_PATH);
context.bind("repository", repository);
return context;
}
use of org.apache.jackrabbit.core.TransientRepository in project sling by apache.
the class AddOrUpdateNodeCommandTest method doWithTransientRepository.
private void doWithTransientRepository(CallableWithSession callable) throws Exception {
File out = new File(new File("target"), "jackrabbit");
TransientRepository repo = new TransientRepository(new File(out, "repository.xml"), new File(out, "repository"));
SimpleCredentials credentials = new SimpleCredentials("admin", "admin".toCharArray());
Session session = repo.login(credentials);
importNodeTypeDefinitions(session, "test-definitions.cnd");
importNodeTypeDefinitions(session, "folder.cnd");
try {
callable.setCredentials(credentials);
callable.setSession(session);
callable.call();
} finally {
if (session.itemExists("/content"))
session.removeItem("/content");
session.save();
session.logout();
}
}
use of org.apache.jackrabbit.core.TransientRepository in project jackrabbit by apache.
the class SimpleBench method test.
void test(int run) throws Exception {
this.run = run;
new File("target/jcr.log").delete();
FileUtils.deleteQuietly(new File("repository"));
start();
repository = new TransientRepository();
Session session = repository.login(new SimpleCredentials("", "".toCharArray()));
if (session.getRootNode().hasNode("test")) {
session.getRootNode().getNode("test").remove();
session.save();
}
session.getRootNode().addNode("test");
session.save();
end("init");
Node node = session.getRootNode().getNode("test");
Node n = null;
int len = run == 0 ? 100 : 1000;
start();
for (int i = 0; i < len; i++) {
if (i % 100 == 0) {
n = node.addNode("sub" + i);
}
Node x = n.addNode("x" + (i % 100));
x.setProperty("name", "John");
x.setProperty("firstName", "Doe");
session.save();
}
end("addNodes");
session.logout();
}
use of org.apache.jackrabbit.core.TransientRepository in project jackrabbit by apache.
the class AutoFixCorruptNode method testAutoFix.
public void testAutoFix() throws Exception {
// new repository
TransientRepository rep = new TransientRepository(new File(TEST_DIR));
Session s = openSession(rep, false);
Node root = s.getRootNode();
// add nodes /test and /test/missing
Node test = root.addNode("test");
Node missing = test.addNode("missing");
missing.addMixin("mix:referenceable");
UUID id = UUID.fromString(missing.getIdentifier());
s.save();
s.logout();
destroyBundle(id, "workspaces/default");
// login and try the operation
s = openSession(rep, false);
test = s.getRootNode().getNode("test");
// try to add a node with the same name
try {
test.addNode("missing");
s.save();
} catch (RepositoryException e) {
// expected
}
s.logout();
s = openSession(rep, true);
test = s.getRootNode().getNode("test");
// iterate over all child nodes fixes the corruption
NodeIterator it = test.getNodes();
while (it.hasNext()) {
it.nextNode();
}
// try to add a node with the same name
test.addNode("missing");
s.save();
// try to delete the parent node
test.remove();
s.save();
s.logout();
rep.shutdown();
FileUtils.deleteDirectory(new File("repository"));
}
Aggregations