Search in sources :

Example 6 with RepositoryImpl

use of org.apache.jackrabbit.core.RepositoryImpl in project jackrabbit-oak by apache.

the class SameNodeSiblingsTest method migrate.

private DocumentNodeStore migrate(SourceDataCreator sourceDataCreator) throws RepositoryException, IOException {
    RepositoryConfig config = RepositoryConfig.install(crx2RepoDir);
    RepositoryImpl repository = RepositoryImpl.create(config);
    try {
        Session session = repository.login(CREDENTIALS);
        sourceDataCreator.create(session);
        session.logout();
    } finally {
        repository.shutdown();
    }
    // re-create the config
    config = RepositoryConfig.install(crx2RepoDir);
    RepositoryContext context = RepositoryContext.create(config);
    DocumentNodeStore target = new DocumentMK.Builder().getNodeStore();
    try {
        RepositoryUpgrade upgrade = new RepositoryUpgrade(context, target);
        upgrade.copy(null);
    } finally {
        context.getRepository().shutdown();
    }
    return target;
}
Also used : RepositoryConfig(org.apache.jackrabbit.core.config.RepositoryConfig) RepositoryContext(org.apache.jackrabbit.core.RepositoryContext) RepositoryImpl(org.apache.jackrabbit.core.RepositoryImpl) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) Session(javax.jcr.Session)

Example 7 with RepositoryImpl

use of org.apache.jackrabbit.core.RepositoryImpl in project jackrabbit-oak by apache.

the class UpgradeFromTwoSourcesTest method upgradeRepository.

@Before
public synchronized void upgradeRepository() throws Exception {
    if (!upgradeComplete) {
        final File sourceDir1 = new File(getTestDirectory(), "source1");
        final File sourceDir2 = new File(getTestDirectory(), "source2");
        sourceDir1.mkdirs();
        sourceDir2.mkdirs();
        final RepositoryImpl source1 = createSourceRepository(sourceDir1);
        final RepositoryImpl source2 = createSourceRepository(sourceDir2);
        final Session session1 = source1.login(CREDENTIALS);
        final Session session2 = source2.login(CREDENTIALS);
        try {
            createSourceContent(session1);
            createSourceContent2(session2);
        } finally {
            session1.save();
            session2.save();
            session1.logout();
            session2.logout();
            source1.shutdown();
            source2.shutdown();
        }
        final NodeStore target = getTargetNodeStore();
        doUpgradeRepository(sourceDir1, target, "/left");
        doUpgradeRepository(sourceDir2, target, "/right", "/left/child2", "/left/child3");
        fileStore.flush();
        upgradeComplete = true;
    }
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) RepositoryImpl(org.apache.jackrabbit.core.RepositoryImpl) File(java.io.File) Session(javax.jcr.Session) Before(org.junit.Before)

Example 8 with RepositoryImpl

use of org.apache.jackrabbit.core.RepositoryImpl in project jackrabbit by apache.

the class SimpleSecurityManager method init.

//------------------------------------------< JackrabbitSecurityManager >---
/**
     * @see JackrabbitSecurityManager#init(Repository, Session)
     */
public void init(Repository repository, Session systemSession) throws RepositoryException {
    if (initialized) {
        throw new IllegalStateException("already initialized");
    }
    if (!(repository instanceof RepositoryImpl)) {
        throw new RepositoryException("RepositoryImpl expected");
    }
    this.systemSession = systemSession;
    config = ((RepositoryImpl) repository).getConfig().getSecurityConfig();
    // read the LoginModule configuration
    LoginModuleConfig loginModConf = config.getLoginModuleConfig();
    authCtxProvider = new AuthContextProvider(config.getAppName(), loginModConf);
    if (authCtxProvider.isLocal()) {
        log.info("init: using Repository LoginModule configuration for " + config.getAppName());
    } else if (authCtxProvider.isJAAS()) {
        log.info("init: using JAAS LoginModule configuration for " + config.getAppName());
    } else {
        String msg = "No valid LoginModule configuriation for " + config.getAppName();
        log.error(msg);
        throw new RepositoryException(msg);
    }
    Properties[] moduleConfig = authCtxProvider.getModuleConfig();
    // retrieve default-ids (admin and anonymous) from login-module-configuration.
    for (Properties aModuleConfig1 : moduleConfig) {
        if (aModuleConfig1.containsKey(LoginModuleConfig.PARAM_ADMIN_ID)) {
            adminID = aModuleConfig1.getProperty(LoginModuleConfig.PARAM_ADMIN_ID);
        }
        if (aModuleConfig1.containsKey(LoginModuleConfig.PARAM_ANONYMOUS_ID)) {
            anonymID = aModuleConfig1.getProperty(LoginModuleConfig.PARAM_ANONYMOUS_ID);
        }
    }
    // fallback:
    if (adminID == null) {
        log.debug("No adminID defined in LoginModule/JAAS config -> using default.");
        adminID = SecurityConstants.ADMIN_ID;
    }
    if (anonymID == null) {
        log.debug("No anonymousID defined in LoginModule/JAAS config -> using default.");
        anonymID = SecurityConstants.ANONYMOUS_ID;
    }
    // most simple principal provider registry, that does not read anything
    // from configuration
    PrincipalProvider principalProvider = new SimplePrincipalProvider();
    // skip init of provider (nop)
    principalProviderRegistry = new ProviderRegistryImpl(principalProvider);
    // register all configured principal providers.
    for (Properties aModuleConfig : moduleConfig) {
        principalProviderRegistry.registerProvider(aModuleConfig);
    }
    SecurityManagerConfig smc = config.getSecurityManagerConfig();
    if (smc != null && smc.getWorkspaceAccessConfig() != null) {
        workspaceAccessManager = smc.getWorkspaceAccessConfig().newInstance(WorkspaceAccessManager.class);
    } else {
        // fallback -> the default simple implementation
        log.debug("No WorkspaceAccessManager configured; using default.");
        workspaceAccessManager = new SimpleWorkspaceAccessManager();
    }
    workspaceAccessManager.init(systemSession);
    initialized = true;
}
Also used : PrincipalProvider(org.apache.jackrabbit.core.security.principal.PrincipalProvider) RepositoryException(javax.jcr.RepositoryException) Properties(java.util.Properties) AuthContextProvider(org.apache.jackrabbit.core.security.authentication.AuthContextProvider) LoginModuleConfig(org.apache.jackrabbit.core.config.LoginModuleConfig) RepositoryImpl(org.apache.jackrabbit.core.RepositoryImpl) SecurityManagerConfig(org.apache.jackrabbit.core.config.SecurityManagerConfig) WorkspaceAccessManager(org.apache.jackrabbit.core.security.authorization.WorkspaceAccessManager) ProviderRegistryImpl(org.apache.jackrabbit.core.security.principal.ProviderRegistryImpl)

Example 9 with RepositoryImpl

use of org.apache.jackrabbit.core.RepositoryImpl in project jackrabbit by apache.

the class IndexingQueueTest method testReaderUpToDate.

/*
     * Test case for JCR-2082
     */
public void testReaderUpToDate() throws Exception {
    BlockingParser.block();
    SearchIndex index = getSearchIndex();
    File indexDir = new File(index.getPath());
    // shutdown workspace
    RepositoryImpl repo = (RepositoryImpl) session.getRepository();
    session.logout();
    session = null;
    superuser.logout();
    superuser = null;
    TestHelper.shutdownWorkspace(getWorkspaceName(), repo);
    // delete index
    try {
        FileUtil.delete(indexDir);
    } catch (IOException e) {
        fail("Unable to delete index directory");
    }
    BlockingParser.unblock();
    // start workspace again by getting a session
    session = getHelper().getSuperuserSession(getWorkspaceName());
    qm = session.getWorkspace().getQueryManager();
    Query q = qm.createQuery(testPath, Query.XPATH);
    assertEquals(1, getSize(q.execute().getNodes()));
}
Also used : Query(javax.jcr.query.Query) RepositoryImpl(org.apache.jackrabbit.core.RepositoryImpl) IOException(java.io.IOException) File(java.io.File)

Example 10 with RepositoryImpl

use of org.apache.jackrabbit.core.RepositoryImpl in project jackrabbit by apache.

the class PersistenceManagerIteratorTest method testGetAllNodeIds.

public void testGetAllNodeIds() throws Exception {
    Node root = testRootNode;
    Session session = root.getSession();
    Repository rep = session.getRepository();
    if (!(rep instanceof RepositoryImpl)) {
        log("Test skipped. Required repository class: " + RepositoryImpl.class + " got: " + rep.getClass());
        return;
    }
    RepositoryImpl r = (RepositoryImpl) rep;
    RepositoryConfig conf = r.getConfig();
    Collection<WorkspaceConfig> coll = conf.getWorkspaceConfigs();
    String[] names = new String[coll.size()];
    Iterator<WorkspaceConfig> wspIt = coll.iterator();
    for (int i = 0; wspIt.hasNext(); i++) {
        WorkspaceConfig wsc = wspIt.next();
        names[i] = wsc.getName();
    }
    for (int i = 0; i < names.length && i < 1; i++) {
        Session s = getHelper().getSuperuserSession(names[i]);
        try {
            Method m = r.getClass().getDeclaredMethod("getWorkspaceInfo", new Class[] { String.class });
            m.setAccessible(true);
            Object info = m.invoke(r, names[i]);
            m = info.getClass().getDeclaredMethod("getPersistenceManager", new Class[0]);
            m.setAccessible(true);
            PersistenceManager pm = (PersistenceManager) m.invoke(info, new Object[0]);
            if (!(pm instanceof AbstractBundlePersistenceManager)) {
                log("PM skipped: " + pm.getClass());
                continue;
            }
            AbstractBundlePersistenceManager apm = (AbstractBundlePersistenceManager) pm;
            log("PM: " + pm.getClass().getName());
            log("All nodes in one step");
            NodeId after = null;
            NodeId first = null;
            for (NodeId id : apm.getAllNodeIds(null, 0)) {
                log("  " + id);
                if (first == null) {
                    // initialize first node id
                    first = id;
                }
                if (after != null) {
                    assertFalse(id.compareTo(after) == 0);
                }
                after = id;
            }
            // start with first
            after = first;
            log("All nodes using batches");
            while (true) {
                log(" bigger than: " + after);
                Iterator<NodeId> it = apm.getAllNodeIds(after, 2).iterator();
                if (!it.hasNext()) {
                    break;
                }
                while (it.hasNext()) {
                    NodeId id = it.next();
                    log("    " + id);
                    assertFalse(id.compareTo(after) == 0);
                    after = id;
                }
            }
            log("Random access");
            for (int j = 0; j < 50; j++) {
                after = NodeId.randomId();
                log(" bigger than: " + after);
                for (NodeId id : apm.getAllNodeIds(after, 2)) {
                    log("    " + id);
                    assertFalse(id.compareTo(after) == 0);
                    after = id;
                }
            }
        } finally {
            s.logout();
        }
    }
}
Also used : RepositoryConfig(org.apache.jackrabbit.core.config.RepositoryConfig) PersistenceManager(org.apache.jackrabbit.core.persistence.PersistenceManager) AbstractBundlePersistenceManager(org.apache.jackrabbit.core.persistence.bundle.AbstractBundlePersistenceManager) Node(javax.jcr.Node) Method(java.lang.reflect.Method) Repository(javax.jcr.Repository) RepositoryImpl(org.apache.jackrabbit.core.RepositoryImpl) NodeId(org.apache.jackrabbit.core.id.NodeId) WorkspaceConfig(org.apache.jackrabbit.core.config.WorkspaceConfig) AbstractBundlePersistenceManager(org.apache.jackrabbit.core.persistence.bundle.AbstractBundlePersistenceManager) Session(javax.jcr.Session)

Aggregations

RepositoryImpl (org.apache.jackrabbit.core.RepositoryImpl)20 File (java.io.File)12 Session (javax.jcr.Session)9 RepositoryConfig (org.apache.jackrabbit.core.config.RepositoryConfig)6 RepositoryException (javax.jcr.RepositoryException)4 Node (javax.jcr.Node)3 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)3 Before (org.junit.Before)3 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 Properties (java.util.Properties)2 Repository (javax.jcr.Repository)2 SimpleCredentials (javax.jcr.SimpleCredentials)2 Query (javax.jcr.query.Query)2 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)2 RepositoryContext (org.apache.jackrabbit.core.RepositoryContext)2 SessionImpl (org.apache.jackrabbit.core.SessionImpl)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 Method (java.lang.reflect.Method)1