use of org.apache.jackrabbit.oak.api.ContentSession in project jackrabbit-oak by apache.
the class ImmutableRootTest method setUp.
@Before
public void setUp() throws CommitFailedException {
ContentSession session = createContentSession();
// Add test content
Root root = session.getLatestRoot();
Tree tree = root.getTree("/");
Tree x = tree.addChild("x");
Tree y = x.addChild("y");
Tree z = y.addChild("z");
root.commit();
// Acquire a fresh new root to avoid problems from lingering state
this.root = new ImmutableRoot(session.getLatestRoot());
}
use of org.apache.jackrabbit.oak.api.ContentSession in project jackrabbit-oak by apache.
the class OakServlet method service.
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
Credentials credentials = null;
String authorization = request.getHeader("Authorization");
if (authorization != null && authorization.startsWith("Basic ")) {
String[] basic = Base64.decode(authorization.substring("Basic ".length())).split(":");
credentials = new SimpleCredentials(basic[0], basic[1].toCharArray());
} else {
throw new LoginException();
}
ContentSession session = repository.login(credentials, null);
try {
Root root = session.getLatestRoot();
request.setAttribute("root", root);
// Find the longest part of the given path that matches
// an existing node. The tail part might be used when
// creating new nodes or when exposing virtual resources.
// Note that we need to traverse the path in reverse
// direction as some parent nodes may be read-protected.
String head = request.getPathInfo();
String tail = "";
Tree tree = root.getTree(head);
while (!tree.exists()) {
if (tree.isRoot()) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
tail = "/" + tree.getName() + tail;
tree = tree.getParent();
}
request.setAttribute("tree", tree);
request.setAttribute("path", tail);
super.service(request, response);
} finally {
session.close();
}
} catch (NoSuchWorkspaceException e) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
} catch (LoginException e) {
response.setHeader("WWW-Authenticate", "Basic realm=\"Oak\"");
response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
}
use of org.apache.jackrabbit.oak.api.ContentSession in project jackrabbit-oak by apache.
the class PrivateStoreValidatorProviderTest method testDefaultMount.
@Test
public void testDefaultMount() throws Exception {
setUp();
ContentSession s = repository.login(null, null);
Root r = s.getLatestRoot();
Tree t = r.getTree("/").addChild("test");
t.addChild("node1").setProperty("jcr:primaryType", "nt:base");
t.addChild("node2").setProperty("jcr:primaryType", "nt:base");
t.addChild("node3").setProperty("jcr:primaryType", "nt:base");
r.commit();
t.getChild("node1").removeProperty("jcr:primaryType");
r.commit();
t.getChild("node1").remove();
r.commit();
}
use of org.apache.jackrabbit.oak.api.ContentSession in project jackrabbit-oak by apache.
the class UserInitializerTest method testAnonymousConfiguration.
/**
* @since OAK 1.0 The anonymous user is optional.
*/
@Test
public void testAnonymousConfiguration() throws Exception {
Map<String, Object> userParams = new HashMap();
userParams.put(UserConstants.PARAM_ANONYMOUS_ID, "");
ConfigurationParameters params = ConfigurationParameters.of(UserConfiguration.NAME, ConfigurationParameters.of(userParams));
SecurityProvider sp = new SecurityProviderImpl(params);
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 anonymous = umgr.getAuthorizable(UserConstants.DEFAULT_ANONYMOUS_ID);
assertNull(anonymous);
} finally {
cs.close();
}
// login as admin should fail
ContentSession anonymousSession = null;
try {
anonymousSession = repo.login(new GuestCredentials(), null);
fail();
} catch (LoginException e) {
//success
} finally {
if (anonymousSession != null) {
anonymousSession.close();
}
}
}
use of org.apache.jackrabbit.oak.api.ContentSession in project jackrabbit-oak by apache.
the class ContentRemoteSessionTest method testReadBinaryIdWithInvalidReference.
@Test
public void testReadBinaryIdWithInvalidReference() {
Root root = mock(Root.class);
doReturn(null).when(root).getBlob(anyString());
ContentSession session = mock(ContentSession.class);
doReturn(root).when(session).getLatestRoot();
ContentRemoteSession remoteSession = createSession(session);
assertNull(remoteSession.readBinaryId("id"));
}
Aggregations