Search in sources :

Example 1 with ValidatorProvider

use of org.apache.jackrabbit.oak.spi.commit.ValidatorProvider in project jackrabbit-oak by apache.

the class MutableRoot method getCommitHook.

/**
 * Combine the globally defined commit hook(s) and the hooks and validators defined by the
 * various security related configurations.
 *
 * @return A commit hook combining repository global commit hook(s) with the pluggable hooks
 *         defined with the security modules and the padded {@code hooks}.
 */
private CommitHook getCommitHook() {
    List<CommitHook> hooks = newArrayList();
    hooks.add(ResetCommitAttributeHook.INSTANCE);
    hooks.add(hook);
    List<CommitHook> postValidationHooks = new ArrayList<CommitHook>();
    List<ValidatorProvider> validators = new ArrayList<>();
    for (SecurityConfiguration sc : securityProvider.getConfigurations()) {
        for (CommitHook ch : sc.getCommitHooks(workspaceName)) {
            if (ch instanceof PostValidationHook) {
                postValidationHooks.add(ch);
            } else if (ch != EmptyHook.INSTANCE) {
                hooks.add(ch);
            }
        }
        validators.addAll(sc.getValidators(workspaceName, subject.getPrincipals(), moveTracker));
    }
    if (!validators.isEmpty()) {
        hooks.add(new EditorHook(CompositeEditorProvider.compose(validators)));
    }
    hooks.addAll(postValidationHooks);
    return CompositeHook.compose(hooks);
}
Also used : CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) PostValidationHook(org.apache.jackrabbit.oak.spi.commit.PostValidationHook) SecurityConfiguration(org.apache.jackrabbit.oak.spi.security.SecurityConfiguration) ValidatorProvider(org.apache.jackrabbit.oak.spi.commit.ValidatorProvider)

Example 2 with ValidatorProvider

use of org.apache.jackrabbit.oak.spi.commit.ValidatorProvider in project jackrabbit-oak by apache.

the class UserConfigurationImplTest method testValidators.

@Test
public void testValidators() {
    UserConfigurationImpl configuration = new UserConfigurationImpl(getSecurityProvider());
    configuration.setRootProvider(getRootProvider());
    configuration.setTreeProvider(getTreeProvider());
    List<? extends ValidatorProvider> validators = configuration.getValidators(adminSession.getWorkspaceName(), Collections.<Principal>emptySet(), new MoveTracker());
    assertEquals(2, validators.size());
    List<String> clNames = Lists.newArrayList(UserValidatorProvider.class.getName(), CacheValidatorProvider.class.getName());
    for (ValidatorProvider vp : validators) {
        clNames.remove(vp.getClass().getName());
    }
    assertTrue(clNames.isEmpty());
}
Also used : MoveTracker(org.apache.jackrabbit.oak.spi.commit.MoveTracker) ValidatorProvider(org.apache.jackrabbit.oak.spi.commit.ValidatorProvider) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 3 with ValidatorProvider

use of org.apache.jackrabbit.oak.spi.commit.ValidatorProvider in project jackrabbit-oak by apache.

the class CompositeConfigurationTest method testGetValidators.

@Test
public void testGetValidators() {
    assertTrue(compositeConfiguration.getValidators(null, ImmutableSet.of(), new MoveTracker()).isEmpty());
    addConfiguration(new SecurityConfiguration.Default());
    assertTrue(compositeConfiguration.getValidators(null, ImmutableSet.of(), new MoveTracker()).isEmpty());
    SecurityConfiguration withValidator = new SecurityConfiguration.Default() {

        @Nonnull
        @Override
        public List<? extends ValidatorProvider> getValidators(@Nonnull String workspaceName, @Nonnull Set<Principal> principals, @Nonnull MoveTracker moveTracker) {
            return ImmutableList.of(Mockito.mock(ValidatorProvider.class));
        }
    };
    addConfiguration(withValidator);
    assertEquals(1, compositeConfiguration.getValidators(null, ImmutableSet.of(), new MoveTracker()).size());
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Nonnull(javax.annotation.Nonnull) MoveTracker(org.apache.jackrabbit.oak.spi.commit.MoveTracker) ValidatorProvider(org.apache.jackrabbit.oak.spi.commit.ValidatorProvider) Test(org.junit.Test)

Example 4 with ValidatorProvider

use of org.apache.jackrabbit.oak.spi.commit.ValidatorProvider in project jackrabbit-oak by apache.

the class PropertyIndexTest method mountWithCommitInWritableMount.

@Test
public void mountWithCommitInWritableMount() throws Exception {
    NodeState root = INITIAL_CONTENT;
    // Add index definition
    NodeBuilder builder = root.builder();
    NodeBuilder index = createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", true, false, ImmutableSet.of("foo"), null);
    index.setProperty("entryCount", -1);
    NodeState before = builder.getNodeState();
    // Add some content and process it through the property index hook
    builder.child("content").setProperty("foo", "abc");
    NodeState after = builder.getNodeState();
    MountInfoProvider mip = Mounts.newBuilder().readOnlyMount("foo", "/readOnly").build();
    CompositeHook hook = new CompositeHook(new EditorHook(new IndexUpdateProvider(new PropertyIndexEditorProvider().with(mip))), new EditorHook(new ValidatorProvider() {

        protected Validator getRootValidator(NodeState before, NodeState after, CommitInfo info) {
            return new PrivateStoreValidator("/", mip);
        }
    }));
    NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
    Mount defMount = mip.getDefaultMount();
    assertTrue(getNode(indexed, pathInIndex(defMount, "/oak:index/foo", "/content", "abc")).exists());
}
Also used : CompositeHook(org.apache.jackrabbit.oak.spi.commit.CompositeHook) IndexUpdateProvider(org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) Mount(org.apache.jackrabbit.oak.spi.mount.Mount) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) MountInfoProvider(org.apache.jackrabbit.oak.spi.mount.MountInfoProvider) ValidatorProvider(org.apache.jackrabbit.oak.spi.commit.ValidatorProvider) Test(org.junit.Test)

Aggregations

ValidatorProvider (org.apache.jackrabbit.oak.spi.commit.ValidatorProvider)4 Test (org.junit.Test)3 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)2 MoveTracker (org.apache.jackrabbit.oak.spi.commit.MoveTracker)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 Nonnull (javax.annotation.Nonnull)1 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)1 IndexUpdateProvider (org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider)1 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)1 CommitHook (org.apache.jackrabbit.oak.spi.commit.CommitHook)1 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)1 CompositeHook (org.apache.jackrabbit.oak.spi.commit.CompositeHook)1 PostValidationHook (org.apache.jackrabbit.oak.spi.commit.PostValidationHook)1 Mount (org.apache.jackrabbit.oak.spi.mount.Mount)1 MountInfoProvider (org.apache.jackrabbit.oak.spi.mount.MountInfoProvider)1 SecurityConfiguration (org.apache.jackrabbit.oak.spi.security.SecurityConfiguration)1 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)1