use of javax.jcr.Credentials in project jackrabbit-oak by apache.
the class UserImplTest method testGetCredentials.
@Test
public void testGetCredentials() throws Exception {
user = userMgr.createUser(uid, uid);
root.commit();
Credentials creds = user.getCredentials();
assertTrue(creds instanceof CredentialsImpl);
CredentialsImpl cImpl = (CredentialsImpl) creds;
assertEquals(uid, cImpl.getUserId());
assertTrue(PasswordUtil.isSame(cImpl.getPasswordHash(), uid));
}
use of javax.jcr.Credentials in project jackrabbit-oak by apache.
the class L11_PasswordTest method testCreateUserWithoutPasswordAndLogin.
public void testCreateUserWithoutPasswordAndLogin() throws RepositoryException {
testUser = userManager.createUser(testId, null);
superuser.save();
// EXERCISE: build the credentials and fix the test-case such that it no longer fails
Credentials creds = null;
getHelper().getRepository().login(creds).logout();
}
use of javax.jcr.Credentials in project jackrabbit-oak by apache.
the class L13_SystemUserTest method testGetCredentials.
@Test
public void testGetCredentials() throws RepositoryException {
// EXERCISE look at the Credentials object returned from the system user and compare it with the result from PasswordTest#getCredentials()
Credentials creds = systemUser.getCredentials();
// EXERCISE fix the expectation
Credentials expected = null;
assertEquals(expected, creds);
}
use of javax.jcr.Credentials in project jackrabbit-oak by apache.
the class CompositeTokenProviderTest method testNullProvider.
@Test
public void testNullProvider() {
TokenProvider tp = CompositeTokenProvider.newInstance();
assertSame(tp, CompositeTokenProvider.newInstance(ImmutableList.<TokenProvider>of()));
Credentials creds = new Credentials() {
};
assertFalse(tp.doCreateToken(null));
assertFalse(tp.doCreateToken(creds));
assertNull(tp.createToken(null, null));
assertNull(tp.createToken("userID", ImmutableMap.<String, String>of()));
assertNull(tp.createToken(null));
assertNull(tp.createToken(creds));
assertNull(tp.getTokenInfo(null));
assertNull(tp.getTokenInfo("anyString"));
}
use of javax.jcr.Credentials 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);
}
}
Aggregations