Search in sources :

Example 11 with ContentRepository

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

the class OakTest method checkMissingStrategySetting.

@Test(expected = CommitFailedException.class)
public void checkMissingStrategySetting() throws Exception {
    Whiteboard wb = new DefaultWhiteboard();
    WhiteboardIndexEditorProvider wbProvider = new WhiteboardIndexEditorProvider();
    wbProvider.start(wb);
    Registration r1 = wb.register(IndexEditorProvider.class, new PropertyIndexEditorProvider(), null);
    Registration r2 = wb.register(IndexEditorProvider.class, new ReferenceEditorProvider(), null);
    Oak oak = new Oak().with(new OpenSecurityProvider()).with(new InitialContent()).with(wb).with(wbProvider).withFailOnMissingIndexProvider();
    ContentRepository repo = oak.createContentRepository();
    ContentSession cs = repo.login(null, null);
    Root root = cs.getLatestRoot();
    Tree t = root.getTree("/");
    t.setProperty("foo", "u1", Type.REFERENCE);
    r1.unregister();
    root.commit();
    cs.close();
    ((Closeable) repo).close();
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) Closeable(java.io.Closeable) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) WhiteboardIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.WhiteboardIndexEditorProvider) ReferenceEditorProvider(org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider) Registration(org.apache.jackrabbit.oak.spi.whiteboard.Registration) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Tree(org.apache.jackrabbit.oak.api.Tree) Whiteboard(org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard) DefaultWhiteboard(org.apache.jackrabbit.oak.spi.whiteboard.DefaultWhiteboard) Test(org.junit.Test)

Example 12 with ContentRepository

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

the class OakTest method checkExecutorShutdown.

@Test
public void checkExecutorShutdown() throws Exception {
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
        }
    };
    Oak oak = new Oak().with(new OpenSecurityProvider());
    ContentRepository repo = oak.createContentRepository();
    WhiteboardUtils.scheduleWithFixedDelay(oak.getWhiteboard(), runnable, 1);
    ((Closeable) repo).close();
    try {
        WhiteboardUtils.scheduleWithFixedDelay(oak.getWhiteboard(), runnable, 1);
        fail("Executor should have rejected the task");
    } catch (RejectedExecutionException ignore) {
    }
    //Externally passed executor should not be shutdown upon repository close
    ScheduledExecutorService externalExecutor = Executors.newSingleThreadScheduledExecutor();
    Oak oak2 = new Oak().with(new OpenSecurityProvider()).with(externalExecutor);
    ContentRepository repo2 = oak2.createContentRepository();
    WhiteboardUtils.scheduleWithFixedDelay(oak2.getWhiteboard(), runnable, 1);
    ((Closeable) repo2).close();
    WhiteboardUtils.scheduleWithFixedDelay(oak2.getWhiteboard(), runnable, 1);
    externalExecutor.shutdown();
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Closeable(java.io.Closeable) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Test(org.junit.Test)

Example 13 with ContentRepository

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

the class PrivilegeDefinitionReaderTest method testMissingPermissionRoot.

@Test
public void testMissingPermissionRoot() throws Exception {
    ContentRepository repo = new Oak().with(new OpenSecurityProvider()).createContentRepository();
    Root tmpRoot = repo.login(null, null).getLatestRoot();
    try {
        PrivilegeDefinitionReader reader = new PrivilegeDefinitionReader(tmpRoot);
        assertNull(reader.readDefinition(JCR_READ));
    } finally {
        tmpRoot.getContentSession().close();
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) Oak(org.apache.jackrabbit.oak.Oak) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 14 with ContentRepository

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

the class UserInitializerTest method testAdminConfiguration.

/**
     * @since OAK 1.0 The configuration defines if the password of the
     * admin user is being set.
     */
@Test
public void testAdminConfiguration() throws Exception {
    Map<String, Object> userParams = new HashMap();
    userParams.put(UserConstants.PARAM_ADMIN_ID, "admin");
    userParams.put(UserConstants.PARAM_OMIT_ADMIN_PW, true);
    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 adminUser = umgr.getAuthorizable("admin");
        assertNotNull(adminUser);
        Tree adminTree = root.getTree(adminUser.getPath());
        assertTrue(adminTree.exists());
        assertNull(adminTree.getProperty(UserConstants.REP_PASSWORD));
    } finally {
        cs.close();
    }
    // login as admin should fail
    ContentSession adminSession = null;
    try {
        adminSession = repo.login(new SimpleCredentials("admin", new char[0]), null);
        fail();
    } catch (LoginException e) {
    //success
    } finally {
        if (adminSession != null) {
            adminSession.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) SimpleCredentials(javax.jcr.SimpleCredentials) 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) Tree(org.apache.jackrabbit.oak.api.Tree) LoginException(javax.security.auth.login.LoginException) SecurityProviderImpl(org.apache.jackrabbit.oak.security.SecurityProviderImpl) UserConfiguration(org.apache.jackrabbit.oak.spi.security.user.UserConfiguration) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 15 with ContentRepository

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

the class L16_RepositoryWithoutUserManagement method testUserManagementDescriptor.

@Test
public void testUserManagementDescriptor() throws RepositoryException {
    Oak oak = new Oak().with(new InitialContent()).with(getSecurityProvider());
    ContentRepository contentRepository = oak.createContentRepository();
    assertFalse(contentRepository.getDescriptors().getValue(JackrabbitRepository.OPTION_USER_MANAGEMENT_SUPPORTED).getBoolean());
}
Also used : InitialContent(org.apache.jackrabbit.oak.InitialContent) Oak(org.apache.jackrabbit.oak.Oak) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) 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