Search in sources :

Example 16 with RepositoryImpl

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

the class SessionImplTest method testCreateSession.

/**
     * JCR-2595: SessionImpl.createSession uses same Subject/LoginContext
     *
     * @see <a href="https://issues.apache.org/jira/browse/JCR-2595">JCR-2595</a>
     */
public void testCreateSession() throws RepositoryException, NotExecutableException {
    if (!(superuser instanceof SessionImpl)) {
        throw new NotExecutableException();
    }
    String currentWsp = superuser.getWorkspace().getName();
    String otherWsp = null;
    for (String wsp : superuser.getWorkspace().getAccessibleWorkspaceNames()) {
        if (!wsp.equals(currentWsp)) {
            otherWsp = wsp;
            break;
        }
    }
    SessionImpl sImpl = (SessionImpl) superuser;
    Subject subject = sImpl.getSubject();
    Session s1 = sImpl.createSession(currentWsp);
    try {
        assertFalse(s1 == sImpl);
        assertFalse(subject == ((SessionImpl) s1).getSubject());
        assertEquals(subject, ((SessionImpl) s1).getSubject());
        assertEquals(currentWsp, s1.getWorkspace().getName());
    } finally {
        s1.logout();
        assertFalse(subject.getPrincipals().isEmpty());
        assertFalse(subject.getPublicCredentials().isEmpty());
    }
    Session s2 = sImpl.createSession(otherWsp);
    try {
        assertFalse(s2 == sImpl);
        assertFalse(subject == ((SessionImpl) s2).getSubject());
        assertEquals(subject, ((SessionImpl) s2).getSubject());
        assertEquals(otherWsp, s2.getWorkspace().getName());
    } finally {
        s2.logout();
        assertFalse(subject.getPrincipals().isEmpty());
        assertFalse(subject.getPublicCredentials().isEmpty());
    }
    Session s3 = sImpl.createSession(null);
    try {
        assertFalse(s3 == sImpl);
        assertFalse(subject == ((SessionImpl) s3).getSubject());
        assertEquals(subject, ((SessionImpl) s3).getSubject());
        assertEquals(((RepositoryImpl) sImpl.getRepository()).getConfig().getDefaultWorkspaceName(), s3.getWorkspace().getName());
    } finally {
        s3.logout();
        assertFalse(subject.getPrincipals().isEmpty());
        assertFalse(subject.getPublicCredentials().isEmpty());
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) RepositoryImpl(org.apache.jackrabbit.core.RepositoryImpl) SessionImpl(org.apache.jackrabbit.core.SessionImpl) Subject(javax.security.auth.Subject) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 17 with RepositoryImpl

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

the class IndexingQueueTest method testInitialIndex.

public void testInitialIndex() throws Exception {
    BlockingParser.block();
    File indexDir = new File(getSearchIndex().getPath());
    // fill workspace
    Node testFolder = testRootNode.addNode("folder", "nt:folder");
    int num = createFiles(testFolder, 10, 2, 0);
    session.save();
    // 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");
    }
    int initialNumExtractorFiles = getNumExtractorFiles();
    BlockingParser.unblock();
    Thread t = new Thread(new Runnable() {

        public void run() {
            try {
                session = getHelper().getSuperuserSession(getWorkspaceName());
            } catch (RepositoryException e) {
                throw new RuntimeException(e);
            }
        }
    });
    t.start();
    while (t.isAlive()) {
        // there must not be more than 20 extractor files, because:
        // - initial index creation checks indexing queue every 10 nodes
        // - there is an aggregate definition on the workspace that causes
        //   2 extractor jobs per nt:resource
        // => 2 * 10 = 20
        int numFiles = getNumExtractorFiles() - initialNumExtractorFiles;
        assertTrue(numFiles <= 20);
        Thread.sleep(50);
    }
    qm = session.getWorkspace().getQueryManager();
    waitForTextExtractionTasksToFinish();
    String stmt = testPath + "//element(*, nt:resource)[jcr:contains(., 'fox')] order by @jcr:score descending";
    Query q = qm.createQuery(stmt, Query.XPATH);
    assertEquals(num, q.execute().getNodes().getSize());
}
Also used : Query(javax.jcr.query.Query) Node(javax.jcr.Node) RepositoryImpl(org.apache.jackrabbit.core.RepositoryImpl) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) File(java.io.File)

Example 18 with RepositoryImpl

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

the class UserAccessControlProviderTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    RepositoryImpl repo = (RepositoryImpl) superuser.getRepository();
    String wspName = repo.getConfig().getSecurityConfig().getSecurityManagerConfig().getWorkspaceName();
    s = getHelper().getSuperuserSession(wspName);
    provider = new UserAccessControlProvider();
    provider.init(s, Collections.emptyMap());
}
Also used : RepositoryImpl(org.apache.jackrabbit.core.RepositoryImpl)

Example 19 with RepositoryImpl

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

the class BackwardsCompatibilityIT method checkJackrabbitRepository.

private void checkJackrabbitRepository(File directory) throws Exception {
    File configuration = new File(directory, "repository.xml");
    try {
        RepositoryConfig config = RepositoryConfig.create(configuration.getPath(), directory.getPath());
        RepositoryImpl repository = RepositoryImpl.create(config);
        try {
            checkRepositoryContent(repository);
        } finally {
            repository.shutdown();
        }
    } catch (RepositoryException e) {
        String message = "Unable to access repository " + directory;
        log.error(message, e);
        fail(message);
    }
}
Also used : RepositoryConfig(org.apache.jackrabbit.core.config.RepositoryConfig) RepositoryImpl(org.apache.jackrabbit.core.RepositoryImpl) RepositoryException(javax.jcr.RepositoryException) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 20 with RepositoryImpl

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

the class AbstractRepositoryTest method doCreateRepository.

/**
     * Creates a named test repository with the given configuration file.
     *
     * @param name name of the repository
     * @param xml input stream for reading the repository configuration
     * @throws Exception if the repository could not be created
     */
protected void doCreateRepository(String name, InputStream xml) throws Exception {
    File directory = new File(new File("target", "repository"), name);
    File configuration = new File(directory, "repository.xml");
    // Copy the configuration file into the repository directory
    try {
        OutputStream output = FileUtils.openOutputStream(configuration);
        try {
            IOUtils.copy(xml, output);
        } finally {
            output.close();
        }
    } finally {
        xml.close();
    }
    // Create the repository
    try {
        RepositoryConfig config = RepositoryConfig.create(configuration.getPath(), directory.getPath());
        RepositoryImpl repository = RepositoryImpl.create(config);
        try {
            Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
            try {
                createTestData(session);
            } finally {
                session.logout();
            }
        } finally {
            repository.shutdown();
        }
    } catch (RepositoryException e) {
        e.printStackTrace();
        fail("Create repository " + name);
    }
}
Also used : RepositoryConfig(org.apache.jackrabbit.core.config.RepositoryConfig) SimpleCredentials(javax.jcr.SimpleCredentials) OutputStream(java.io.OutputStream) RepositoryImpl(org.apache.jackrabbit.core.RepositoryImpl) RepositoryException(javax.jcr.RepositoryException) File(java.io.File) 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