Search in sources :

Example 6 with ContentRepository

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

the class SuggestionIntervalTest method createRepository.

@Override
protected ContentRepository createRepository() {
    LuceneIndexProvider provider = new LuceneIndexProvider();
    ContentRepository repository = new Oak().with(new InitialContent()).with(new OpenSecurityProvider()).with((QueryIndexProvider) provider).with((Observer) provider).with(new LuceneIndexEditorProvider()).createContentRepository();
    clock = new Clock.Virtual();
    try {
        clock.waitUntil(System.currentTimeMillis());
    } catch (Exception e) {
    //eat exception if clock couldn't wait... that was just courteous anyway!
    }
    LuceneIndexEditorContext.setClock(clock);
    return repository;
}
Also used : InitialContent(org.apache.jackrabbit.oak.InitialContent) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) Oak(org.apache.jackrabbit.oak.Oak) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) Clock(org.apache.jackrabbit.oak.stats.Clock) QueryIndexProvider(org.apache.jackrabbit.oak.spi.query.QueryIndexProvider)

Example 7 with ContentRepository

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

the class UserInitializerTest method testAnonymousConfiguration.

/**
     * @since OAK 1.0 The anonymous user is optional.
     */
@Test
public void testAnonymousConfiguration() throws Exception {
    Map<String, Object> userParams = new HashMap();
    userParams.put(UserConstants.PARAM_ANONYMOUS_ID, "");
    ConfigurationParameters params = ConfigurationParameters.of(UserConfiguration.NAME, ConfigurationParameters.of(userParams));
    SecurityProvider sp = new SecurityProviderImpl(params);
    final ContentRepository repo = new Oak().with(new InitialContent()).with(new PropertyIndexEditorProvider()).with(new PropertyIndexProvider()).with(new TypeEditorProvider()).with(sp).createContentRepository();
    ContentSession cs = Subject.doAs(SystemSubject.INSTANCE, new PrivilegedExceptionAction<ContentSession>() {

        @Override
        public ContentSession run() throws Exception {
            return repo.login(null, null);
        }
    });
    try {
        Root root = cs.getLatestRoot();
        UserConfiguration uc = sp.getConfiguration(UserConfiguration.class);
        UserManager umgr = uc.getUserManager(root, NamePathMapper.DEFAULT);
        Authorizable anonymous = umgr.getAuthorizable(UserConstants.DEFAULT_ANONYMOUS_ID);
        assertNull(anonymous);
    } finally {
        cs.close();
    }
    // login as admin should fail
    ContentSession anonymousSession = null;
    try {
        anonymousSession = repo.login(new GuestCredentials(), null);
        fail();
    } catch (LoginException e) {
    //success
    } finally {
        if (anonymousSession != null) {
            anonymousSession.close();
        }
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) HashMap(java.util.HashMap) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) ConfigurationParameters(org.apache.jackrabbit.oak.spi.security.ConfigurationParameters) LoginException(javax.security.auth.login.LoginException) InitialContent(org.apache.jackrabbit.oak.InitialContent) PropertyIndexProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexProvider) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) UserManager(org.apache.jackrabbit.api.security.user.UserManager) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) Oak(org.apache.jackrabbit.oak.Oak) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) LoginException(javax.security.auth.login.LoginException) SecurityProviderImpl(org.apache.jackrabbit.oak.security.SecurityProviderImpl) GuestCredentials(javax.jcr.GuestCredentials) UserConfiguration(org.apache.jackrabbit.oak.spi.security.user.UserConfiguration) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 8 with ContentRepository

use of org.apache.jackrabbit.oak.api.ContentRepository in project sling by apache.

the class RepositoryTestHelper method createOakRepository.

public static Repository createOakRepository(NodeStore nodeStore) {
    DefaultWhiteboard whiteboard = new DefaultWhiteboard();
    final Oak oak = new Oak(nodeStore).with(new InitialContent()).with(JcrConflictHandler.createJcrConflictHandler()).with(new EditorHook(new VersionEditorProvider())).with(new OpenSecurityProvider()).with(new NamespaceEditorProvider()).with(new TypeEditorProvider()).with(new ConflictValidatorProvider()).with(//getDefaultWorkspace())
    "default").with(whiteboard);
    //        if (commitRateLimiter != null) {
    //            oak.with(commitRateLimiter);
    //        }
    final ContentRepository contentRepository = oak.createContentRepository();
    return new RepositoryImpl(contentRepository, whiteboard, new OpenSecurityProvider(), 1000, null);
}
Also used : InitialContent(org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent) NamespaceEditorProvider(org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) RepositoryImpl(org.apache.jackrabbit.oak.jcr.repository.RepositoryImpl) Oak(org.apache.jackrabbit.oak.Oak) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) VersionEditorProvider(org.apache.jackrabbit.oak.plugins.version.VersionEditorProvider) ConflictValidatorProvider(org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider)

Example 9 with ContentRepository

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

the class OakTest method testContentRepositoryReuse.

@Test
public void testContentRepositoryReuse() throws Exception {
    Oak oak = new Oak().with(new OpenSecurityProvider());
    ContentRepository r0 = null;
    ContentRepository r1 = null;
    try {
        r0 = oak.createContentRepository();
        r1 = oak.createContentRepository();
        assertEquals(r0, r1);
    } finally {
        if (r0 != null) {
            ((Closeable) r0).close();
        }
    }
}
Also used : Closeable(java.io.Closeable) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) Test(org.junit.Test)

Example 10 with ContentRepository

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

the class OakTest method testWithDefaultWorkspaceName.

@Test
public void testWithDefaultWorkspaceName() throws Exception {
    ContentRepository repo = new Oak().with("test").with(new OpenSecurityProvider()).createContentRepository();
    String[] valid = new String[] { null, "test" };
    for (String wspName : valid) {
        ContentSession cs = null;
        try {
            cs = repo.login(null, wspName);
            assertEquals("test", cs.getWorkspaceName());
        } finally {
            if (cs != null) {
                cs.close();
            }
        }
    }
    String[] invalid = new String[] { "", "another", Oak.DEFAULT_WORKSPACE_NAME };
    for (String wspName : invalid) {
        ContentSession cs = null;
        try {
            cs = repo.login(null, wspName);
            fail("invalid workspace nam");
        } catch (NoSuchWorkspaceException e) {
        // success
        } finally {
            if (cs != null) {
                cs.close();
            }
        }
    }
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) Test(org.junit.Test)

Aggregations

ContentRepository (org.apache.jackrabbit.oak.api.ContentRepository)17 Test (org.junit.Test)13 OpenSecurityProvider (org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider)11 Oak (org.apache.jackrabbit.oak.Oak)8 Closeable (java.io.Closeable)5 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)5 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)5 Root (org.apache.jackrabbit.oak.api.Root)5 InitialContent (org.apache.jackrabbit.oak.InitialContent)4 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)3 TypeEditorProvider (org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider)3 DefaultWhiteboard (org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard)3 HashMap (java.util.HashMap)2 Credentials (javax.jcr.Credentials)2 SimpleCredentials (javax.jcr.SimpleCredentials)2 LoginException (javax.security.auth.login.LoginException)2 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)2 UserManager (org.apache.jackrabbit.api.security.user.UserManager)2 Tree (org.apache.jackrabbit.oak.api.Tree)2 PropertyIndexProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexProvider)2