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);
}
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());
}
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());
}
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());
}
Aggregations