Search in sources :

Example 6 with Repository

use of javax.jcr.Repository in project jackrabbit by apache.

the class Login method execute.

/**
     * {@inheritDoc}
     */
public boolean execute(Context ctx) throws Exception {
    String anon = "anonymous";
    String user = (String) ctx.get(this.userKey);
    String password = (String) ctx.get(this.passwordKey);
    String workspace = (String) ctx.get(this.workspaceKey);
    if (user == null) {
        user = anon;
    }
    if (password == null || (password.equals(anon) && !user.equals(anon))) {
        ConsoleReader reader = new ConsoleReader();
        password = reader.readLine("Password: ", (char) 0);
    }
    if (log.isDebugEnabled()) {
        log.debug("logging in as " + user);
    }
    Session session = null;
    Repository repo = CommandHelper.getRepository(ctx);
    Credentials credentials = new SimpleCredentials(user, password.toCharArray());
    if (workspace == null) {
        session = repo.login(credentials);
    } else {
        session = repo.login(credentials, workspace);
    }
    CommandHelper.setSession(ctx, session);
    CommandHelper.setCurrentNode(ctx, session.getRootNode());
    return false;
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Repository(javax.jcr.Repository) ConsoleReader(jline.ConsoleReader) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) Session(javax.jcr.Session)

Example 7 with Repository

use of javax.jcr.Repository in project jackrabbit-oak by apache.

the class PersistentCacheTest method createRepository.

@Override
protected Repository[] createRepository(RepositoryFixture fixture) throws Exception {
    System.setProperty("PersistentCacheStats.rejectedPut", "true");
    if (fixture instanceof OakRepositoryFixture) {
        OakFixture oakFixture = ((OakRepositoryFixture) fixture).getOakFixture();
        if (oakFixture instanceof OakFixture.MongoFixture) {
            OakFixture.MongoFixture mongoFixture = (OakFixture.MongoFixture) oakFixture;
            DocumentMK.Builder builder = mongoFixture.getBuilder(1);
            builder.setStatisticsProvider(statsProvider);
            builder.setPersistentCache("target/persistentCache,time," + CACHE_OPTIONS);
            dns = builder.getNodeStore();
            nodesCache = DocumentNodeStoreHelper.getNodesCache(dns);
            Oak[] cluster = mongoFixture.setUpCluster(new DocumentMK.Builder[] { builder }, statsProvider);
            return new Repository[] { new Jcr(cluster[0]).createRepository() };
        }
    }
    throw new IllegalArgumentException("Fixture " + fixture + " not supported for this benchmark.");
}
Also used : OakRepositoryFixture(org.apache.jackrabbit.oak.fixture.OakRepositoryFixture) Repository(javax.jcr.Repository) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) OakFixture(org.apache.jackrabbit.oak.fixture.OakFixture) Oak(org.apache.jackrabbit.oak.Oak) Jcr(org.apache.jackrabbit.oak.jcr.Jcr)

Example 8 with Repository

use of javax.jcr.Repository in project jackrabbit-oak by apache.

the class ObservationTest method run.

@Override
public void run(Iterable<RepositoryFixture> fixtures) {
    for (RepositoryFixture fixture : fixtures) {
        if (fixture.isAvailable(1)) {
            System.out.format("%s: Observation throughput benchmark%n", fixture);
            try {
                final AtomicReference<Whiteboard> whiteboardRef = new AtomicReference<Whiteboard>();
                Repository[] cluster;
                if (fixture instanceof OakRepositoryFixture) {
                    cluster = ((OakRepositoryFixture) fixture).setUpCluster(1, new JcrCreator() {

                        @Override
                        public Jcr customize(Oak oak) {
                            whiteboardRef.set(oak.getWhiteboard());
                            return new Jcr(oak);
                        }
                    });
                } else {
                    cluster = fixture.setUpCluster(1);
                }
                try {
                    run(cluster[0], whiteboardRef.get());
                } finally {
                    fixture.tearDownCluster();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : Repository(javax.jcr.Repository) OakRepositoryFixture(org.apache.jackrabbit.oak.fixture.OakRepositoryFixture) OakRepositoryFixture(org.apache.jackrabbit.oak.fixture.OakRepositoryFixture) RepositoryFixture(org.apache.jackrabbit.oak.fixture.RepositoryFixture) Oak(org.apache.jackrabbit.oak.Oak) Jcr(org.apache.jackrabbit.oak.jcr.Jcr) AtomicReference(java.util.concurrent.atomic.AtomicReference) JcrCreator(org.apache.jackrabbit.oak.fixture.JcrCreator) Whiteboard(org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard) RepositoryException(javax.jcr.RepositoryException) ExecutionException(java.util.concurrent.ExecutionException)

Example 9 with Repository

use of javax.jcr.Repository in project jackrabbit by apache.

the class AbstractRepositoryTest method testLoginWithNullWorkspace.

/**
     * Tests the {@link AbstractRepository#login(String)} method with a
     * <code>null</code> workspace name.
     *
     * @throws RepositoryException if an error occurs
     */
public void testLoginWithNullWorkspace() throws RepositoryException {
    Repository repository = (Repository) record(AbstractRepository.class);
    repository.login(null, null);
    replay();
    repository.login((String) null);
    verify();
}
Also used : Repository(javax.jcr.Repository)

Example 10 with Repository

use of javax.jcr.Repository in project jackrabbit by apache.

the class AbstractRepositoryTest method testLoginWithCredentials.

/**
     * Tests the {@link AbstractRepository#login(Credentials)} method.
     *
     * @throws RepositoryException if an error occurs
     */
public void testLoginWithCredentials() throws RepositoryException {
    Credentials credentials = new SimpleCredentials("", "".toCharArray());
    Repository repository = (Repository) record(AbstractRepository.class);
    repository.login(credentials, null);
    replay();
    repository.login(credentials);
    verify();
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Repository(javax.jcr.Repository) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials)

Aggregations

Repository (javax.jcr.Repository)107 Session (javax.jcr.Session)31 RepositoryException (javax.jcr.RepositoryException)26 SimpleCredentials (javax.jcr.SimpleCredentials)15 Test (org.junit.Test)13 HashMap (java.util.HashMap)12 Node (javax.jcr.Node)12 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)10 SlingRepository (org.apache.sling.jcr.api.SlingRepository)10 JackrabbitRepository (org.apache.jackrabbit.api.JackrabbitRepository)9 Oak (org.apache.jackrabbit.oak.Oak)7 Jcr (org.apache.jackrabbit.oak.jcr.Jcr)7 IOException (java.io.IOException)6 Map (java.util.Map)6 InitialContext (javax.naming.InitialContext)6 NamingException (javax.naming.NamingException)6 ServletContext (javax.servlet.ServletContext)5 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)5 File (java.io.File)4 OutputStreamWriter (java.io.OutputStreamWriter)4