use of org.apache.jackrabbit.oak.api.ContentSession in project jackrabbit-oak by apache.
the class OakTest method testWithDefaultWorkspaceName.
@Test
public void testWithDefaultWorkspaceName() throws Exception {
ContentRepository repo = new Oak().with("test").with(new OpenSecurityProvider()).createContentRepository();
String[] valid = new String[] { null, "test" };
for (String wspName : valid) {
ContentSession cs = null;
try {
cs = repo.login(null, wspName);
assertEquals("test", cs.getWorkspaceName());
} finally {
if (cs != null) {
cs.close();
}
}
}
String[] invalid = new String[] { "", "another", Oak.DEFAULT_WORKSPACE_NAME };
for (String wspName : invalid) {
ContentSession cs = null;
try {
cs = repo.login(null, wspName);
fail("invalid workspace nam");
} catch (NoSuchWorkspaceException e) {
// success
} finally {
if (cs != null) {
cs.close();
}
}
}
}
use of org.apache.jackrabbit.oak.api.ContentSession in project jackrabbit-oak by apache.
the class OakTest method checkMissingStrategySetting.
@Test(expected = CommitFailedException.class)
public void checkMissingStrategySetting() throws Exception {
Whiteboard wb = new DefaultWhiteboard();
WhiteboardIndexEditorProvider wbProvider = new WhiteboardIndexEditorProvider();
wbProvider.start(wb);
Registration r1 = wb.register(IndexEditorProvider.class, new PropertyIndexEditorProvider(), null);
Registration r2 = wb.register(IndexEditorProvider.class, new ReferenceEditorProvider(), null);
Oak oak = new Oak().with(new OpenSecurityProvider()).with(new InitialContent()).with(wb).with(wbProvider).withFailOnMissingIndexProvider();
ContentRepository repo = oak.createContentRepository();
ContentSession cs = repo.login(null, null);
Root root = cs.getLatestRoot();
Tree t = root.getTree("/");
t.setProperty("foo", "u1", Type.REFERENCE);
r1.unregister();
root.commit();
cs.close();
((Closeable) repo).close();
}
use of org.apache.jackrabbit.oak.api.ContentSession in project jackrabbit-oak by apache.
the class DefaultConflictHandlerTheirsTest method setUp.
@Before
public void setUp() throws CommitFailedException {
ContentSession session = new Oak().with(new OpenSecurityProvider()).with(DefaultConflictHandler.THEIRS).createContentSession();
// Add test content
Root root = session.getLatestRoot();
Tree tree = root.getTree("/");
tree.setProperty("a", 1);
tree.setProperty("b", 2);
tree.setProperty("c", 3);
tree.addChild("x");
tree.addChild("y");
tree.addChild("z");
root.commit();
ourRoot = session.getLatestRoot();
theirRoot = session.getLatestRoot();
}
use of org.apache.jackrabbit.oak.api.ContentSession in project jackrabbit-oak by apache.
the class Jackrabbit2ConfigurationTest method testTokenCreationAndImpersonation.
@Test
public void testTokenCreationAndImpersonation() throws Exception {
ContentSession cs = null;
try {
SimpleCredentials sc = (SimpleCredentials) getAdminCredentials();
sc.setAttribute(".token", "");
ImpersonationCredentials ic = new ImpersonationCredentials(sc, new AuthInfoImpl(((SimpleCredentials) getAdminCredentials()).getUserID(), Collections.<String, Object>emptyMap(), Collections.<Principal>emptySet()));
cs = login(ic);
Object token = sc.getAttribute(".token").toString();
assertNotNull(token);
TokenCredentials tc = new TokenCredentials(token.toString());
cs.close();
cs = login(tc);
} finally {
if (cs != null) {
cs.close();
}
}
}
use of org.apache.jackrabbit.oak.api.ContentSession in project jackrabbit-oak by apache.
the class Jackrabbit2ConfigurationTest method testInvalidSimpleCredentialsWithAttribute.
@Test
public void testInvalidSimpleCredentialsWithAttribute() throws Exception {
ContentSession cs = null;
try {
SimpleCredentials sc = new SimpleCredentials("test", new char[0]);
sc.setAttribute(".token", "");
cs = login(sc);
fail("Invalid simple credentials login should fail");
} catch (LoginException e) {
// success
} finally {
if (cs != null) {
cs.close();
}
}
}
Aggregations