Search in sources :

Example 1 with TransientRepository

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;
}
Also used : Context(javax.naming.Context) AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) SimpleCredentials(javax.jcr.SimpleCredentials) User(org.apache.jackrabbit.api.security.user.User) TransientRepository(org.apache.jackrabbit.core.TransientRepository) UserManager(org.apache.jackrabbit.api.security.user.UserManager) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) SessionImpl(org.apache.jackrabbit.core.SessionImpl) File(java.io.File)

Example 2 with TransientRepository

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;
}
Also used : Context(javax.naming.Context) TransientRepository(org.apache.jackrabbit.core.TransientRepository) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File)

Example 3 with TransientRepository

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();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) TransientRepository(org.apache.jackrabbit.core.TransientRepository) File(java.io.File) Session(javax.jcr.Session)

Example 4 with TransientRepository

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();
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) TransientRepository(org.apache.jackrabbit.core.TransientRepository) Node(javax.jcr.Node) File(java.io.File) Session(javax.jcr.Session)

Example 5 with TransientRepository

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"));
}
Also used : NodeIterator(javax.jcr.NodeIterator) TransientRepository(org.apache.jackrabbit.core.TransientRepository) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) UUID(java.util.UUID) File(java.io.File) Session(javax.jcr.Session)

Aggregations

TransientRepository (org.apache.jackrabbit.core.TransientRepository)16 File (java.io.File)15 Node (javax.jcr.Node)10 Session (javax.jcr.Session)10 UUID (java.util.UUID)7 SimpleCredentials (javax.jcr.SimpleCredentials)6 ConsistencyReport (org.apache.jackrabbit.core.persistence.check.ConsistencyReport)6 RepositoryException (javax.jcr.RepositoryException)3 Context (javax.naming.Context)3 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 SQLException (java.sql.SQLException)2 ItemNotFoundException (javax.jcr.ItemNotFoundException)2 NodeIterator (javax.jcr.NodeIterator)2 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)2 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 Path (java.nio.file.Path)1 Credentials (javax.jcr.Credentials)1 AccessControlList (javax.jcr.security.AccessControlList)1