Search in sources :

Example 1 with JackrabbitRepository

use of org.apache.jackrabbit.api.JackrabbitRepository in project jackrabbit-oak by apache.

the class RepositoryTest method loginWithAttribute.

@Test
public void loginWithAttribute() throws RepositoryException {
    Session session = ((JackrabbitRepository) getRepository()).login(new GuestCredentials(), null, Collections.<String, Object>singletonMap(RepositoryImpl.REFRESH_INTERVAL, 42));
    String[] attributeNames = session.getAttributeNames();
    assertEquals(1, attributeNames.length);
    assertEquals(RepositoryImpl.REFRESH_INTERVAL, attributeNames[0]);
    assertEquals(42L, session.getAttribute(RepositoryImpl.REFRESH_INTERVAL));
    session.logout();
}
Also used : JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) JackrabbitRepository(org.apache.jackrabbit.api.JackrabbitRepository) GuestCredentials(javax.jcr.GuestCredentials) Session(javax.jcr.Session) Test(org.junit.Test)

Example 2 with JackrabbitRepository

use of org.apache.jackrabbit.api.JackrabbitRepository in project jackrabbit-oak by apache.

the class UpgradeOldSegmentTest method upgradeFrom10.

@Test
public void upgradeFrom10() throws Exception {
    File testFolder = new File(new File("target"), UpgradeOldSegmentTest.class.getSimpleName());
    FileUtils.deleteDirectory(testFolder);
    File oldRepo = new File(testFolder, "test-repo-1.0");
    oldRepo.mkdirs();
    try (InputStream in = UpgradeOldSegmentTest.class.getResourceAsStream("/test-repo-1.0.zip")) {
        Util.unzip(in, oldRepo);
    }
    SegmentTarNodeStoreContainer newRepoContainer = new SegmentTarNodeStoreContainer();
    OakUpgrade.main("segment-old:" + oldRepo.getPath(), newRepoContainer.getDescription());
    Repository repo = new Jcr(newRepoContainer.open()).createRepository();
    Session s = repo.login(new SimpleCredentials("admin", "admin".toCharArray()));
    Node myType = s.getNode("/jcr:system/jcr:nodeTypes/test:MyType");
    assertEquals(2, Iterators.size(myType.getNodes("jcr:propertyDefinition")));
    NodeTypeManager ntMgr = s.getWorkspace().getNodeTypeManager();
    assertTrue(ntMgr.hasNodeType("test:MyType"));
    NodeType nt = ntMgr.getNodeType("test:MyType");
    PropertyDefinition[] pDefs = nt.getDeclaredPropertyDefinitions();
    assertEquals(2, pDefs.length);
    for (PropertyDefinition pd : pDefs) {
        String name = pd.getName();
        if (name.equals("test:mandatory")) {
            assertTrue(pd.isMandatory());
        } else if (name.equals("test:optional")) {
            assertFalse(pd.isMandatory());
        } else {
            fail("Unexpected property definition: " + name);
        }
    }
    // flip mandatory flag for test:mandatory
    String cnd = "<'test'='http://www.apache.org/jackrabbit/test'>\n" + "[test:MyType] > nt:unstructured\n" + " - test:mandatory (string)\n" + " - test:optional (string)";
    CndImporter.registerNodeTypes(new StringReader(cnd), s, true);
    myType = s.getNode("/jcr:system/jcr:nodeTypes/test:MyType");
    assertEquals(2, Iterators.size(myType.getNodes("jcr:propertyDefinition")));
    nt = ntMgr.getNodeType("test:MyType");
    pDefs = nt.getDeclaredPropertyDefinitions();
    assertEquals(2, pDefs.length);
    for (PropertyDefinition pd : pDefs) {
        String name = pd.getName();
        if (name.equals("test:mandatory")) {
            assertFalse(pd.isMandatory());
        } else if (name.equals("test:optional")) {
            assertFalse(pd.isMandatory());
        } else {
            fail("Unexpected property definition: " + name);
        }
    }
    s.logout();
    if (repo instanceof JackrabbitRepository) {
        ((JackrabbitRepository) repo).shutdown();
    }
    newRepoContainer.close();
    newRepoContainer.clean();
    deleteRecursive(testFolder);
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) InputStream(java.io.InputStream) Node(javax.jcr.Node) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) SimpleCredentials(javax.jcr.SimpleCredentials) Repository(javax.jcr.Repository) JackrabbitRepository(org.apache.jackrabbit.api.JackrabbitRepository) SegmentTarNodeStoreContainer(org.apache.jackrabbit.oak.upgrade.cli.container.SegmentTarNodeStoreContainer) NodeType(javax.jcr.nodetype.NodeType) Jcr(org.apache.jackrabbit.oak.jcr.Jcr) StringReader(java.io.StringReader) JackrabbitRepository(org.apache.jackrabbit.api.JackrabbitRepository) File(java.io.File) Session(javax.jcr.Session) Test(org.junit.Test)

Example 3 with JackrabbitRepository

use of org.apache.jackrabbit.api.JackrabbitRepository in project sling by apache.

the class OakSlingRepository method createAdministrativeSession.

@Override
protected Session createAdministrativeSession(String workspace) throws RepositoryException {
    // TODO: use principal provider to retrieve admin principal
    Set<? extends Principal> principals = singleton(new AdminPrincipal() {

        @Override
        public String getName() {
            return OakSlingRepository.this.adminId;
        }
    });
    AuthInfo authInfo = new AuthInfoImpl(this.adminId, Collections.<String, Object>emptyMap(), principals);
    Subject subject = new Subject(true, principals, singleton(authInfo), Collections.<Object>emptySet());
    Session adminSession;
    try {
        adminSession = Subject.doAsPrivileged(subject, new PrivilegedExceptionAction<Session>() {

            @Override
            public Session run() throws Exception {
                Map<String, Object> attrs = new HashMap<String, Object>();
                attrs.put("oak.refresh-interval", 0);
                // TODO OAK-803: Backwards compatibility of long-lived sessions
                JackrabbitRepository repo = (JackrabbitRepository) getRepository();
                return repo.login(null, null, attrs);
            }
        }, null);
    } catch (PrivilegedActionException e) {
        throw new RepositoryException("failed to retrieve admin session.", e);
    }
    return adminSession;
}
Also used : AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) HashMap(java.util.HashMap) PrivilegedActionException(java.security.PrivilegedActionException) RepositoryException(javax.jcr.RepositoryException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Subject(javax.security.auth.Subject) AdminPrincipal(org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal) AuthInfoImpl(org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl) JackrabbitRepository(org.apache.jackrabbit.api.JackrabbitRepository) Session(javax.jcr.Session)

Example 4 with JackrabbitRepository

use of org.apache.jackrabbit.api.JackrabbitRepository in project pentaho-platform by pentaho.

the class PentahoSystemReadyListener method contextDestroyed.

@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
    Repository jcrRepository = PentahoSystem.get(Repository.class, "jcrRepository", null);
    if (jcrRepository == null) {
        Logger.error(PentahoSystemReadyListener.class.getName(), "Cannot obtain JCR repository. Exiting");
        return;
    }
    if (!(jcrRepository instanceof JackrabbitRepository)) {
        Logger.error(PentahoSystemReadyListener.class.getName(), String.format("Expected RepositoryImpl, but got: [%s]. Exiting", jcrRepository.getClass().getName()));
        return;
    }
    ((JackrabbitRepository) jcrRepository).shutdown();
}
Also used : Repository(javax.jcr.Repository) JackrabbitRepository(org.apache.jackrabbit.api.JackrabbitRepository) JackrabbitRepository(org.apache.jackrabbit.api.JackrabbitRepository)

Example 5 with JackrabbitRepository

use of org.apache.jackrabbit.api.JackrabbitRepository in project jackrabbit-oak by apache.

the class SameNamePropertyNodeTest method testNodeStoreSupport.

/**
 * Tests if a nodestore fixture sets the SNNP repository descriptor to true.
 */
@Test
public void testNodeStoreSupport() throws Exception {
    NodeStore nodeStore = NodeStoreFixtures.SEGMENT_TAR.createNodeStore();
    JackrabbitRepository repository = (JackrabbitRepository) new Jcr(nodeStore).createRepository();
    try {
        assertTrue(repository.getDescriptorValue(Repository.OPTION_NODE_AND_PROPERTY_WITH_SAME_NAME_SUPPORTED).getBoolean());
    } finally {
        repository.shutdown();
    }
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) JackrabbitRepository(org.apache.jackrabbit.api.JackrabbitRepository) AbstractJCRTest(org.apache.jackrabbit.test.AbstractJCRTest) Test(org.junit.Test)

Aggregations

JackrabbitRepository (org.apache.jackrabbit.api.JackrabbitRepository)7 Session (javax.jcr.Session)4 Test (org.junit.Test)4 Repository (javax.jcr.Repository)3 HashMap (java.util.HashMap)2 File (java.io.File)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 Properties (java.util.Properties)1 GuestCredentials (javax.jcr.GuestCredentials)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 SimpleCredentials (javax.jcr.SimpleCredentials)1 NodeType (javax.jcr.nodetype.NodeType)1 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)1 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)1 Subject (javax.security.auth.Subject)1 JackrabbitRepositoryFactory (org.apache.jackrabbit.api.JackrabbitRepositoryFactory)1