Search in sources :

Example 1 with PrivilegeConfiguration

use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConfiguration in project jackrabbit-oak by apache.

the class SecurityProviderImplTest method testBindPrivilegeConfiguration.

@Test
public void testBindPrivilegeConfiguration() {
    PrivilegeConfiguration pc = Mockito.mock(PrivilegeConfiguration.class);
    securityProvider.bindPrivilegeConfiguration(pc);
    assertSame(pc, securityProvider.getConfiguration(PrivilegeConfiguration.class));
    for (SecurityConfiguration sc : securityProvider.getConfigurations()) {
        if (sc instanceof PrivilegeConfiguration) {
            assertSame(pc, sc);
        }
    }
}
Also used : SecurityConfiguration(org.apache.jackrabbit.oak.spi.security.SecurityConfiguration) PrivilegeConfiguration(org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConfiguration) Test(org.junit.Test)

Example 2 with PrivilegeConfiguration

use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConfiguration in project jackrabbit-oak by apache.

the class SecurityProviderImplTest method testUnBindPrivilegeConfiguration.

@Test
public void testUnBindPrivilegeConfiguration() {
    PrivilegeConfiguration pc = Mockito.mock(PrivilegeConfiguration.class);
    securityProvider.bindPrivilegeConfiguration(pc);
    securityProvider.unbindPrivilegeConfiguration(pc);
    assertNull(securityProvider.getConfiguration(PrivilegeConfiguration.class));
    for (SecurityConfiguration sc : securityProvider.getConfigurations()) {
        if (sc instanceof PrivilegeConfiguration) {
            fail();
        }
    }
}
Also used : SecurityConfiguration(org.apache.jackrabbit.oak.spi.security.SecurityConfiguration) PrivilegeConfiguration(org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConfiguration) Test(org.junit.Test)

Example 3 with PrivilegeConfiguration

use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConfiguration in project jackrabbit-oak by apache.

the class AbstractAccessControlManagerTest method before.

@Before
public void before() throws Exception {
    testPrivileges = new Privilege[] { mockPrivilege("priv1"), mockPrivilege("priv2") };
    allPrivileges = new Privilege[] { mockPrivilege(PrivilegeConstants.JCR_ALL) };
    cs = Mockito.mock(ContentSession.class);
    when(cs.getWorkspaceName()).thenReturn(WSP_NAME);
    when(cs.getAuthInfo()).thenReturn(new AuthInfoImpl(null, ImmutableMap.of(), testPrincipals));
    when(root.getContentSession()).thenReturn(cs);
    Tree nonExistingTree = Mockito.mock(Tree.class);
    when(nonExistingTree.exists()).thenReturn(false);
    when(root.getTree(nonExistingPath)).thenReturn(nonExistingTree);
    Tree existingTree = Mockito.mock(Tree.class);
    when(existingTree.exists()).thenReturn(true);
    when(root.getTree(testPath)).thenReturn(existingTree);
    Tree rootTree = Mockito.mock(Tree.class);
    when(rootTree.exists()).thenReturn(true);
    when(root.getTree("/")).thenReturn(rootTree);
    privilegeManager = Mockito.mock(PrivilegeManager.class);
    when(privilegeManager.getRegisteredPrivileges()).thenReturn(testPrivileges);
    when(privilegeManager.getPrivilege("priv1")).thenReturn(testPrivileges[0]);
    when(privilegeManager.getPrivilege("priv2")).thenReturn(testPrivileges[1]);
    when(privilegeManager.getPrivilege(PrivilegeConstants.JCR_ALL)).thenReturn(allPrivileges[0]);
    PrivilegeConfiguration privilegeConfiguration = Mockito.mock(PrivilegeConfiguration.class);
    when(privilegeConfiguration.getPrivilegeManager(root, getNamePathMapper())).thenReturn(privilegeManager);
    authorizationConfiguration = Mockito.mock(AuthorizationConfiguration.class);
    when(authorizationConfiguration.getPermissionProvider(root, WSP_NAME, getEveryonePrincipalSet())).thenReturn(EmptyPermissionProvider.getInstance());
    when(authorizationConfiguration.getPermissionProvider(root, WSP_NAME, testPrincipals)).thenReturn(OpenPermissionProvider.getInstance());
    when(authorizationConfiguration.getPermissionProvider(root, WSP_NAME, ImmutableSet.of())).thenReturn(EmptyPermissionProvider.getInstance());
    when(authorizationConfiguration.getContext()).thenReturn(Context.DEFAULT);
    securityProvider = Mockito.mock(SecurityProvider.class);
    when(securityProvider.getConfiguration(PrivilegeConfiguration.class)).thenReturn(privilegeConfiguration);
    when(securityProvider.getConfiguration(AuthorizationConfiguration.class)).thenReturn(authorizationConfiguration);
    acMgr = createAccessControlManager(root, getNamePathMapper());
}
Also used : AuthInfoImpl(org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl) AuthorizationConfiguration(org.apache.jackrabbit.oak.spi.security.authorization.AuthorizationConfiguration) PrivilegeManager(org.apache.jackrabbit.api.security.authorization.PrivilegeManager) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Tree(org.apache.jackrabbit.oak.api.Tree) PrivilegeConfiguration(org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConfiguration) Before(org.junit.Before)

Example 4 with PrivilegeConfiguration

use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConfiguration in project jackrabbit-oak by apache.

the class RepositoryUpgrade method copy.

/**
 * Copies the full content from the source to the target repository.
 * <p>
 * The source repository <strong>must not be modified</strong> while
 * the copy operation is running to avoid an inconsistent copy.
 * <p>
 * Note that both the source and the target repository must be closed
 * during the copy operation as this method requires exclusive access
 * to the repositories.
 *
 * @param initializer optional extra repository initializer to use
 * @throws RepositoryException if the copy operation fails
 */
public void copy(RepositoryInitializer initializer) throws RepositoryException {
    if (checkLongNames) {
        assertNoLongNames();
    }
    RepositoryConfig config = source.getRepositoryConfig();
    logger.info("Copying repository content from {} to Oak", config.getHomeDir());
    try {
        NodeBuilder targetBuilder = target.getRoot().builder();
        if (VersionHistoryUtil.getVersionStorage(targetBuilder).exists() && !versionCopyConfiguration.skipOrphanedVersionsCopy()) {
            logger.warn("The version storage on destination already exists. Orphaned version histories will be skipped.");
            versionCopyConfiguration.setCopyOrphanedVersions(null);
        }
        final Root upgradeRoot = new UpgradeRoot(targetBuilder);
        String workspaceName = source.getRepositoryConfig().getDefaultWorkspaceName();
        SecurityProvider security = SecurityProviderBuilder.newBuilder().with(mapSecurityConfig(config.getSecurityConfig())).build();
        if (skipInitialization) {
            logger.info("Skipping the repository initialization");
        } else {
            // init target repository first
            logger.info("Initializing initial repository content from {}", config.getHomeDir());
            new InitialContent().initialize(targetBuilder);
            if (initializer != null) {
                initializer.initialize(targetBuilder);
            }
            logger.debug("InitialContent completed from {}", config.getHomeDir());
            for (SecurityConfiguration sc : security.getConfigurations()) {
                RepositoryInitializer ri = sc.getRepositoryInitializer();
                ri.initialize(targetBuilder);
                logger.debug("Repository initializer '" + ri.getClass().getName() + "' completed", config.getHomeDir());
            }
            for (SecurityConfiguration sc : security.getConfigurations()) {
                WorkspaceInitializer wi = sc.getWorkspaceInitializer();
                wi.initialize(targetBuilder, workspaceName);
                logger.debug("Workspace initializer '" + wi.getClass().getName() + "' completed", config.getHomeDir());
            }
        }
        HashBiMap<String, String> uriToPrefix = HashBiMap.create();
        logger.info("Copying registered namespaces");
        copyNamespaces(targetBuilder, uriToPrefix);
        logger.debug("Namespace registration completed.");
        if (skipInitialization) {
            logger.info("Skipping registering node types and privileges");
        } else {
            logger.info("Copying registered node types");
            NodeTypeManager ntMgr = new ReadWriteNodeTypeManager() {

                @Override
                protected Tree getTypes() {
                    return upgradeRoot.getTree(NODE_TYPES_PATH);
                }

                @Nonnull
                @Override
                protected Root getWriteRoot() {
                    return upgradeRoot;
                }
            };
            copyNodeTypes(ntMgr, new ValueFactoryImpl(upgradeRoot, NamePathMapper.DEFAULT));
            logger.debug("Node type registration completed.");
            // migrate privileges
            logger.info("Copying registered privileges");
            PrivilegeConfiguration privilegeConfiguration = security.getConfiguration(PrivilegeConfiguration.class);
            copyCustomPrivileges(privilegeConfiguration.getPrivilegeManager(upgradeRoot, NamePathMapper.DEFAULT));
            logger.debug("Privilege registration completed.");
            // Triggers compilation of type information, which we need for
            // the type predicates used by the bulk  copy operations below.
            new TypeEditorProvider(false).getRootEditor(targetBuilder.getBaseState(), targetBuilder.getNodeState(), targetBuilder, null);
        }
        final NodeState reportingSourceRoot = ReportingNodeState.wrap(JackrabbitNodeState.createRootNodeState(source, workspaceName, targetBuilder.getNodeState(), uriToPrefix, copyBinariesByReference, skipOnError), new LoggingReporter(logger, "Migrating", LOG_NODE_COPY, -1));
        final NodeState sourceRoot;
        if (filterLongNames) {
            sourceRoot = NameFilteringNodeState.wrapRoot(reportingSourceRoot);
        } else {
            sourceRoot = reportingSourceRoot;
        }
        final Stopwatch watch = Stopwatch.createStarted();
        logger.info("Copying workspace content");
        copyWorkspace(sourceRoot, targetBuilder, workspaceName);
        // on TarMK this does call triggers the actual copy
        targetBuilder.getNodeState();
        logger.info("Upgrading workspace content completed in {}s ({})", watch.elapsed(TimeUnit.SECONDS), watch);
        if (!versionCopyConfiguration.skipOrphanedVersionsCopy()) {
            logger.info("Copying version storage");
            watch.reset().start();
            copyVersionStorage(targetBuilder, getVersionStorage(sourceRoot), getVersionStorage(targetBuilder), versionCopyConfiguration);
            // on TarMK this does call triggers the actual copy
            targetBuilder.getNodeState();
            logger.info("Version storage copied in {}s ({})", watch.elapsed(TimeUnit.SECONDS), watch);
        } else {
            logger.info("Skipping the version storage as the copyOrphanedVersions is set to false");
        }
        watch.reset().start();
        logger.info("Applying default commit hooks");
        // TODO: default hooks?
        List<CommitHook> hooks = newArrayList();
        UserConfiguration userConf = security.getConfiguration(UserConfiguration.class);
        String groupsPath = userConf.getParameters().getConfigValue(UserConstants.PARAM_GROUP_PATH, UserConstants.DEFAULT_GROUP_PATH);
        String usersPath = userConf.getParameters().getConfigValue(UserConstants.PARAM_USER_PATH, UserConstants.DEFAULT_USER_PATH);
        // hooks specific to the upgrade, need to run first
        hooks.add(new EditorHook(new CompositeEditorProvider(new RestrictionEditorProvider(), new GroupEditorProvider(groupsPath), // copy referenced version histories
        new VersionableEditor.Provider(sourceRoot, workspaceName, versionCopyConfiguration), new SameNameSiblingsEditor.Provider(), AuthorizableFolderEditor.provider(groupsPath, usersPath))));
        // this editor works on the VersionableEditor output, so it can't be
        // a part of the same EditorHook
        hooks.add(new EditorHook(new VersionablePropertiesEditor.Provider()));
        // security-related hooks
        for (SecurityConfiguration sc : security.getConfigurations()) {
            hooks.addAll(sc.getCommitHooks(workspaceName));
        }
        if (customCommitHooks != null) {
            hooks.addAll(customCommitHooks);
        }
        // type validation, reference and indexing hooks
        hooks.add(new EditorHook(new CompositeEditorProvider(createTypeEditorProvider(), createIndexEditorProvider())));
        target.merge(targetBuilder, new LoggingCompositeHook(hooks, source, overrideEarlyShutdown()), CommitInfo.EMPTY);
        logger.info("Processing commit hooks completed in {}s ({})", watch.elapsed(TimeUnit.SECONDS), watch);
        removeVersions();
        logger.debug("Repository upgrade completed.");
    } catch (Exception e) {
        throw new RepositoryException("Failed to copy content", e);
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) ReadWriteNodeTypeManager(org.apache.jackrabbit.oak.plugins.nodetype.write.ReadWriteNodeTypeManager) NameFilteringNodeState(org.apache.jackrabbit.oak.upgrade.nodestate.NameFilteringNodeState) ReportingNodeState(org.apache.jackrabbit.oak.plugins.migration.report.ReportingNodeState) FilteringNodeState(org.apache.jackrabbit.oak.plugins.migration.FilteringNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ValueFactoryImpl(org.apache.jackrabbit.oak.plugins.value.jcr.ValueFactoryImpl) Stopwatch(com.google.common.base.Stopwatch) LoggingReporter(org.apache.jackrabbit.oak.plugins.migration.report.LoggingReporter) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) VersionableEditor(org.apache.jackrabbit.oak.upgrade.version.VersionableEditor) PrivilegeConfiguration(org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConfiguration) UserConfiguration(org.apache.jackrabbit.oak.spi.security.user.UserConfiguration) RepositoryConfig(org.apache.jackrabbit.core.config.RepositoryConfig) ReadWriteNodeTypeManager(org.apache.jackrabbit.oak.plugins.nodetype.write.ReadWriteNodeTypeManager) CompositeEditorProvider(org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider) RestrictionEditorProvider(org.apache.jackrabbit.oak.upgrade.security.RestrictionEditorProvider) Root(org.apache.jackrabbit.oak.api.Root) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) RepositoryException(javax.jcr.RepositoryException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) IOException(java.io.IOException) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) RepositoryException(javax.jcr.RepositoryException) NamespaceException(javax.jcr.NamespaceException) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) EditorProvider(org.apache.jackrabbit.oak.spi.commit.EditorProvider) IndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider) CompositeEditorProvider(org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider) RestrictionEditorProvider(org.apache.jackrabbit.oak.upgrade.security.RestrictionEditorProvider) GroupEditorProvider(org.apache.jackrabbit.oak.upgrade.security.GroupEditorProvider) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) ReferenceEditorProvider(org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) CompositeIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider) InitialContent(org.apache.jackrabbit.oak.InitialContent) WorkspaceInitializer(org.apache.jackrabbit.oak.spi.lifecycle.WorkspaceInitializer) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) GroupEditorProvider(org.apache.jackrabbit.oak.upgrade.security.GroupEditorProvider) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) SecurityConfiguration(org.apache.jackrabbit.oak.spi.security.SecurityConfiguration) RepositoryInitializer(org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer)

Example 5 with PrivilegeConfiguration

use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConfiguration in project jackrabbit-oak by apache.

the class SecurityProviderRegistrationTest method testBindUnbindPrivilegeConfiguration.

@Test
public void testBindUnbindPrivilegeConfiguration() throws Exception {
    Field f = registration.getClass().getDeclaredField("privilegeConfiguration");
    f.setAccessible(true);
    assertNull(f.get(registration));
    PrivilegeConfiguration pc = mockConfiguration(PrivilegeConfiguration.class);
    registration.bindPrivilegeConfiguration(pc);
    assertSame(pc, f.get(registration));
    registration.unbindPrivilegeConfiguration(pc);
    assertNull(f.get(registration));
}
Also used : Field(java.lang.reflect.Field) PrivilegeConfiguration(org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConfiguration) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

PrivilegeConfiguration (org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConfiguration)6 SecurityConfiguration (org.apache.jackrabbit.oak.spi.security.SecurityConfiguration)4 Test (org.junit.Test)4 SecurityProvider (org.apache.jackrabbit.oak.spi.security.SecurityProvider)2 Stopwatch (com.google.common.base.Stopwatch)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 NamespaceException (javax.jcr.NamespaceException)1 RepositoryException (javax.jcr.RepositoryException)1 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)1 PrivilegeManager (org.apache.jackrabbit.api.security.authorization.PrivilegeManager)1 RepositoryConfig (org.apache.jackrabbit.core.config.RepositoryConfig)1 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)1 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)1 InitialContent (org.apache.jackrabbit.oak.InitialContent)1 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)1 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)1 Root (org.apache.jackrabbit.oak.api.Root)1 Tree (org.apache.jackrabbit.oak.api.Tree)1 CompositeIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider)1