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