Search in sources :

Example 96 with Repository

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

the class OakOSGiRepositoryFactoryTest method testRepositoryTar.

@Test
public void testRepositoryTar() throws Exception {
    copyConfig("tar");
    config.put(BundleActivator.class.getName(), new TestActivator());
    Repository repository = repositoryFactory.getRepository(config);
    assertTrue("test activator should have been called on startup", calledOnStart);
    //Give time for system to stablize :(
    TimeUnit.SECONDS.sleep(1);
    assertNotNull(repository);
    System.out.println("Repository started ");
    basicCrudTest(repository);
    //For now SecurityConfig is giving some issue
    //so disable that
    testCallback(repository);
    shutdown(repository);
    assertTrue("test activator should have been called on stop", calledOnStop);
}
Also used : Repository(javax.jcr.Repository) JackrabbitRepository(org.apache.jackrabbit.api.JackrabbitRepository) BundleActivator(org.osgi.framework.BundleActivator) Test(org.junit.Test)

Example 97 with Repository

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

the class SlingDavExServlet method getSessionProvider.

@Override
protected SessionProvider getSessionProvider() {
    return new SessionProvider() {

        public Session getSession(final HttpServletRequest req, final Repository repository, final String workspace) throws LoginException, RepositoryException, ServletException {
            final ResourceResolver resolver = (ResourceResolver) req.getAttribute(AuthenticationSupport.REQUEST_ATTRIBUTE_RESOLVER);
            if (resolver != null) {
                final Session session = resolver.adaptTo(Session.class);
                if (session != null) {
                    final Session newSession = getLongLivedSession(session);
                    log.debug("getSession: Creating new Session ({}) for {}", newSession, newSession.getUserID());
                    return newSession;
                }
            }
            throw new ServletException("ResourceResolver missing or not providing on JCR Session");
        }

        public void releaseSession(final Session session) {
            log.debug("releaseSession: Logging out long lived Session ({})", session);
            session.logout();
        }

        /**
             * Creates a new session for the user of the slingSession in the
             * same workspace as the slingSession.
             * <p>
             * Assumption: The admin session has permission to impersonate
             * as any user without restriction. If this is not the case
             * the Session.impersonate method throws a LoginException
             * which is folded into a RepositoryException.
             *
             * @param slingSession The session provided by the Sling
             *            authentication mechanis,
             * @return a new session which may (and will) outlast the request
             * @throws RepositoryException If an error occurrs creating the
             *             session.
             */
        private Session getLongLivedSession(final Session slingSession) throws RepositoryException {
            Session adminSession = null;
            final String user = slingSession.getUserID();
            try {
                final SimpleCredentials credentials = new SimpleCredentials(user, EMPTY_PW);
                final String wsp = slingSession.getWorkspace().getName();
                adminSession = SlingDavExServlet.this.repository.loginAdministrative(wsp);
                return adminSession.impersonate(credentials);
            } catch (RepositoryException re) {
                // cause a 403/FORBIDDEN response
                throw new RepositoryException("Cannot get session for " + user, re);
            } finally {
                if (adminSession != null) {
                    adminSession.logout();
                }
            }
        }
    };
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) SimpleCredentials(javax.jcr.SimpleCredentials) SlingRepository(org.apache.sling.jcr.api.SlingRepository) Repository(javax.jcr.Repository) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) RepositoryException(javax.jcr.RepositoryException) SessionProvider(org.apache.jackrabbit.server.SessionProvider) Session(javax.jcr.Session)

Example 98 with Repository

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

the class AbstractSlingRepository2 method getDescriptor.

// Remaining Repository service methods all backed by the actual
// repository instance. They may be overwritten, but generally are not.
@Override
public String getDescriptor(String name) {
    Repository repo = getRepository();
    if (repo != null) {
        return repo.getDescriptor(name);
    }
    logger.error("getDescriptor: Repository not available");
    return null;
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) Repository(javax.jcr.Repository)

Example 99 with Repository

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

the class AbstractSlingRepository2 method getDescriptorValue.

@Override
public Value getDescriptorValue(String key) {
    Repository repo = getRepository();
    if (repo != null) {
        return repo.getDescriptorValue(key);
    }
    logger.error("getDescriptorValue: Repository not available");
    return null;
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) Repository(javax.jcr.Repository)

Example 100 with Repository

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

the class AbstractSlingRepository2 method isSingleValueDescriptor.

@Override
public boolean isSingleValueDescriptor(String key) {
    Repository repo = getRepository();
    if (repo != null) {
        return repo.isSingleValueDescriptor(key);
    }
    logger.error("isSingleValueDescriptor: Repository not available");
    return false;
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) Repository(javax.jcr.Repository)

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