Search in sources :

Example 21 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 = SecurityProviderBuilder.newBuilder().with(params).build();
    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) UserConfiguration(org.apache.jackrabbit.oak.spi.security.user.UserConfiguration) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 22 with ContentRepository

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

the class ThreeWayConflictHandlerTest method changeDeletedProperty.

@Test
public void changeDeletedProperty() throws Exception {
    AtomicBoolean called = new AtomicBoolean(false);
    ThreeWayConflictHandler handler = new ErrorThreeWayConflictHandler() {

        @Override
        public Resolution changeDeletedProperty(NodeBuilder parent, PropertyState ours, PropertyState base) {
            called.set(true);
            assertEquals("ours", ours.getValue(STRING));
            assertEquals("base", base.getValue(STRING));
            return Resolution.IGNORED;
        }
    };
    ContentRepository repo = newRepo(handler);
    Root root = login(repo);
    setup(root);
    Root ourRoot = login(repo);
    Root theirRoot = login(repo);
    theirRoot.getTree("/c").removeProperty("p");
    ourRoot.getTree("/c").setProperty("p", "ours");
    theirRoot.commit();
    ourRoot.commit();
    assertTrue(called.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ThreeWayConflictHandler(org.apache.jackrabbit.oak.spi.commit.ThreeWayConflictHandler) Root(org.apache.jackrabbit.oak.api.Root) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 23 with ContentRepository

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

the class ThreeWayConflictHandlerTest method changeDeletedNode.

@Test
public void changeDeletedNode() throws Exception {
    AtomicBoolean called = new AtomicBoolean(false);
    ThreeWayConflictHandler handler = new ErrorThreeWayConflictHandler() {

        @Override
        public Resolution changeDeletedNode(NodeBuilder parent, String name, NodeState ours, NodeState base) {
            called.set(true);
            assertTrue(ours.hasProperty("p"));
            assertTrue(base.hasProperty("p"));
            assertEquals("ours", ours.getProperty("p").getValue(STRING));
            assertEquals("base", base.getProperty("p").getValue(STRING));
            return Resolution.IGNORED;
        }
    };
    ContentRepository repo = newRepo(handler);
    Root root = login(repo);
    setup(root);
    Root ourRoot = login(repo);
    Root theirRoot = login(repo);
    theirRoot.getTree("/c").remove();
    ourRoot.getTree("/c").setProperty("p", "ours");
    theirRoot.commit();
    ourRoot.commit();
    assertTrue(called.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ThreeWayConflictHandler(org.apache.jackrabbit.oak.spi.commit.ThreeWayConflictHandler) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Root(org.apache.jackrabbit.oak.api.Root) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 24 with ContentRepository

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

the class ThreeWayConflictHandlerTest method deleteDeletedProperty.

@Test
public void deleteDeletedProperty() throws Exception {
    AtomicBoolean called = new AtomicBoolean(false);
    ThreeWayConflictHandler handler = new ErrorThreeWayConflictHandler() {

        @Override
        public Resolution deleteDeletedProperty(NodeBuilder parent, PropertyState base) {
            called.set(true);
            assertEquals("base", base.getValue(STRING));
            return Resolution.IGNORED;
        }
    };
    ContentRepository repo = newRepo(handler);
    Root root = login(repo);
    setup(root);
    Root ourRoot = login(repo);
    Root theirRoot = login(repo);
    theirRoot.getTree("/c").removeProperty("p");
    ourRoot.getTree("/c").removeProperty("p");
    theirRoot.commit();
    ourRoot.commit();
    assertTrue(called.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ThreeWayConflictHandler(org.apache.jackrabbit.oak.spi.commit.ThreeWayConflictHandler) Root(org.apache.jackrabbit.oak.api.Root) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 25 with ContentRepository

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

the class ThreeWayConflictHandlerTest method addExistingProperty.

@Test
public void addExistingProperty() throws Exception {
    AtomicBoolean called = new AtomicBoolean(false);
    ThreeWayConflictHandler handler = new ErrorThreeWayConflictHandler() {

        @Override
        public Resolution addExistingProperty(NodeBuilder parent, PropertyState ours, PropertyState theirs) {
            called.set(true);
            assertEquals("ours", ours.getValue(STRING));
            assertEquals("theirs", theirs.getValue(STRING));
            return Resolution.IGNORED;
        }
    };
    ContentRepository repo = newRepo(handler);
    Root root = login(repo);
    setup(root);
    Root ourRoot = login(repo);
    Root theirRoot = login(repo);
    theirRoot.getTree("/c").setProperty("p0", "theirs");
    ourRoot.getTree("/c").setProperty("p0", "ours");
    theirRoot.commit();
    ourRoot.commit();
    assertTrue(called.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ThreeWayConflictHandler(org.apache.jackrabbit.oak.spi.commit.ThreeWayConflictHandler) Root(org.apache.jackrabbit.oak.api.Root) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Aggregations

ContentRepository (org.apache.jackrabbit.oak.api.ContentRepository)28 Test (org.junit.Test)23 Root (org.apache.jackrabbit.oak.api.Root)15 OpenSecurityProvider (org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider)12 Oak (org.apache.jackrabbit.oak.Oak)9 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 ThreeWayConflictHandler (org.apache.jackrabbit.oak.spi.commit.ThreeWayConflictHandler)8 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)6 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)6 Closeable (java.io.Closeable)5 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)5 InitialContent (org.apache.jackrabbit.oak.InitialContent)5 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)4 Tree (org.apache.jackrabbit.oak.api.Tree)3 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)3 TypeEditorProvider (org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider)3 HashMap (java.util.HashMap)2 Credentials (javax.jcr.Credentials)2 SimpleCredentials (javax.jcr.SimpleCredentials)2