Search in sources :

Example 21 with InitialContent

use of org.apache.jackrabbit.oak.InitialContent in project jackrabbit-oak by apache.

the class ChangeCollectorProviderTest method setup.

@Before
public void setup() throws PrivilegedActionException, CommitFailedException {
    collectorProvider = new ChangeCollectorProvider();
    recorder = new Recorder();
    Oak oak = new Oak().with(new InitialContent()).with(collectorProvider).with(recorder).with(getSecurityProvider());
    contentRepository = oak.createContentRepository();
    session = Subject.doAs(SystemSubject.INSTANCE, new PrivilegedExceptionAction<ContentSession>() {

        @Override
        public ContentSession run() throws LoginException, NoSuchWorkspaceException {
            return contentRepository.login(null, null);
        }
    });
    Root root = session.getLatestRoot();
    Tree rootTree = root.getTree("/").addChild("test");
    rootTree.setProperty(JcrConstants.JCR_PRIMARYTYPE, "test:parentType", Type.NAME);
    Tree child1 = rootTree.addChild("child1");
    child1.setProperty("child1Prop", 1);
    child1.setProperty(JcrConstants.JCR_PRIMARYTYPE, "test:childType", Type.NAME);
    Tree grandChild1 = child1.addChild("grandChild1");
    grandChild1.setProperty("grandChild1Prop", 1);
    grandChild1.setProperty(JcrConstants.JCR_PRIMARYTYPE, "test:grandChildType", Type.NAME);
    Tree greatGrandChild1 = grandChild1.addChild("greatGrandChild1");
    greatGrandChild1.setProperty("greatGrandChild1Prop", 1);
    greatGrandChild1.setProperty(JcrConstants.JCR_PRIMARYTYPE, "test:greatGrandChildType", Type.NAME);
    Tree child2 = rootTree.addChild("child2");
    child2.setProperty("child2Prop", 1);
    child2.setProperty(JcrConstants.JCR_PRIMARYTYPE, "test:childType", Type.NAME);
    Tree grandChild2 = child2.addChild("grandChild2");
    grandChild2.setProperty("grandChild2Prop", 1);
    grandChild2.setProperty(JcrConstants.JCR_PRIMARYTYPE, "test:grandChildType", Type.NAME);
    recorder.changes.clear();
    root.commit();
    ChangeSet changeSet = getSingleChangeSet();
    assertMatches("parentPaths", changeSet.getParentPaths(), "/test/child2", "/test/child1", "/test/child1/grandChild1/greatGrandChild1", "/", "/test", "/test/child1/grandChild1", "/test/child2/grandChild2");
    assertMatches("parentNodeNames", changeSet.getParentNodeNames(), "child2", "child1", "greatGrandChild1", "test", "grandChild1", "grandChild2");
    assertMatches("parentNodeTypes", changeSet.getParentNodeTypes(), "test:parentType", "test:childType", "test:grandChildType", "test:greatGrandChildType");
    assertMatches("allNodeTypes", changeSet.getAllNodeTypes(), "test:parentType", "test:childType", "test:grandChildType", "test:greatGrandChildType");
    assertMatches("propertyNames", changeSet.getPropertyNames(), JcrConstants.JCR_PRIMARYTYPE, "child1Prop", "child2Prop", "grandChild1Prop", "grandChild2Prop", "greatGrandChild1Prop");
    // clear the recorder so that we start off empty
    recorder.changes.clear();
}
Also used : InitialContent(org.apache.jackrabbit.oak.InitialContent) Root(org.apache.jackrabbit.oak.api.Root) Oak(org.apache.jackrabbit.oak.Oak) Tree(org.apache.jackrabbit.oak.api.Tree) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Before(org.junit.Before)

Example 22 with InitialContent

use of org.apache.jackrabbit.oak.InitialContent 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 23 with InitialContent

use of org.apache.jackrabbit.oak.InitialContent in project jackrabbit-oak by apache.

the class UserProviderTest method setUp.

@Before
public void setUp() throws Exception {
    root = new Oak().with(new OpenSecurityProvider()).with(new InitialContent()).with(new PropertyIndexEditorProvider()).createRoot();
    defaultConfig = ConfigurationParameters.EMPTY;
    defaultUserPath = defaultConfig.getConfigValue(UserConstants.PARAM_USER_PATH, UserConstants.DEFAULT_USER_PATH);
    defaultGroupPath = defaultConfig.getConfigValue(UserConstants.PARAM_GROUP_PATH, UserConstants.DEFAULT_GROUP_PATH);
    customOptions = new HashMap<String, Object>();
    customOptions.put(UserConstants.PARAM_GROUP_PATH, customGroupPath);
    customOptions.put(UserConstants.PARAM_USER_PATH, customUserPath);
}
Also used : InitialContent(org.apache.jackrabbit.oak.InitialContent) Oak(org.apache.jackrabbit.oak.Oak) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) Before(org.junit.Before)

Example 24 with InitialContent

use of org.apache.jackrabbit.oak.InitialContent 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)

Example 25 with InitialContent

use of org.apache.jackrabbit.oak.InitialContent in project jackrabbit-oak by apache.

the class PrivateStoreValidatorProviderTest method setUp.

private void setUp(String... readOnlyPaths) {
    configureMountInfoProvider(readOnlyPaths);
    repository = new Oak().with(new OpenSecurityProvider()).with(new InitialContent()).with(privateStoreValidatorProvider).createContentRepository();
}
Also used : InitialContent(org.apache.jackrabbit.oak.InitialContent) Oak(org.apache.jackrabbit.oak.Oak) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider)

Aggregations

InitialContent (org.apache.jackrabbit.oak.InitialContent)32 Oak (org.apache.jackrabbit.oak.Oak)23 OpenSecurityProvider (org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider)17 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)11 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)10 Before (org.junit.Before)9 Test (org.junit.Test)9 SecurityProviderImpl (org.apache.jackrabbit.oak.security.SecurityProviderImpl)7 Root (org.apache.jackrabbit.oak.api.Root)6 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)6 TypeEditorProvider (org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider)6 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)5 IOException (java.io.IOException)4 ContentRepository (org.apache.jackrabbit.oak.api.ContentRepository)4 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)3 Tree (org.apache.jackrabbit.oak.api.Tree)3 NodeTypeIndexProvider (org.apache.jackrabbit.oak.plugins.index.nodetype.NodeTypeIndexProvider)3 QueryIndexProvider (org.apache.jackrabbit.oak.spi.query.QueryIndexProvider)3 HashMap (java.util.HashMap)2 Nonnull (javax.annotation.Nonnull)2