use of javax.jcr.SimpleCredentials in project jackrabbit by apache.
the class UserPerWorkspaceSecurityManagerTest method testUsersArePerWorkspace.
public void testUsersArePerWorkspace() throws Exception {
String altWsp = getAlternativeWorkspaceName();
if (altWsp == null) {
throw new NotExecutableException();
}
Session s = getHelper().getSuperuserSession(altWsp);
User u = null;
try {
// other users created in the default workspace...
u = ((JackrabbitSession) superuser).getUserManager().createUser("testUser", "testUser");
superuser.save();
// ... must not be present in the alternate-workspace
UserManager umgr = ((JackrabbitSession) s).getUserManager();
assertNull(umgr.getAuthorizable("testUser"));
try {
Session us = getHelper().getRepository().login(new SimpleCredentials("testUser", "testUser".toCharArray()), altWsp);
us.logout();
fail("testUser must not be able to login to a workspace without this user.");
} catch (LoginException e) {
// success
}
} finally {
s.logout();
if (u != null) {
u.remove();
superuser.save();
}
}
}
use of javax.jcr.SimpleCredentials in project jackrabbit by apache.
the class UserPerWorkspaceSecurityManagerTest method testCloneUser.
public void testCloneUser() throws Exception {
String altWsp = getAlternativeWorkspaceName();
if (altWsp == null) {
throw new NotExecutableException();
}
UserManager uMgr = ((JackrabbitSession) superuser).getUserManager();
Session s = getHelper().getSuperuserSession(altWsp);
User u = null;
try {
// other users created in the default workspace...
u = uMgr.createUser("testUser", "testUser");
superuser.save();
String userPath = null;
if (u.getPrincipal() instanceof ItemBasedPrincipal) {
userPath = ((ItemBasedPrincipal) u.getPrincipal()).getPath();
assertTrue(superuser.nodeExists(userPath));
} else {
throw new NotExecutableException();
}
// ... must not be present in the alternate-workspace
UserManager umgr = ((JackrabbitSession) s).getUserManager();
assertNull(umgr.getAuthorizable("testUser"));
assertFalse(s.nodeExists(userPath));
String clonePath = userPath;
String parentPath = Text.getRelativeParent(clonePath, 1);
while (!s.nodeExists(parentPath)) {
clonePath = parentPath;
parentPath = Text.getRelativeParent(parentPath, 1);
}
// clone the user into the second workspace
s.getWorkspace().clone(superuser.getWorkspace().getName(), clonePath, clonePath, true);
// ... now the user must be visible
assertNotNull(umgr.getAuthorizable("testUser"));
if (userPath != null) {
assertTrue(s.nodeExists(userPath));
}
// ... and able to login to that workspace
Session us = getHelper().getRepository().login(new SimpleCredentials("testUser", "testUser".toCharArray()), altWsp);
us.logout();
} finally {
// remove the test user in the second workspace
Authorizable dest = ((JackrabbitSession) s).getUserManager().getAuthorizable("testUser");
if (dest != null) {
dest.remove();
s.save();
}
// logout the session
s.logout();
if (u != null) {
// remove as well in the first workspace
u.remove();
superuser.save();
}
}
}
use of javax.jcr.SimpleCredentials in project jackrabbit by apache.
the class UserPerWorkspaceSecurityManagerTest method testTransientUserCannotLogin.
public void testTransientUserCannotLogin() throws RepositoryException, UnsupportedRepositoryOperationException {
Session s = null;
String uid = "testUser";
UserManager umgr = ((JackrabbitSession) superuser).getUserManager();
umgr.autoSave(false);
try {
// other users created in the default workspace...
umgr.createUser(uid, uid);
// the new user must be able to login to the repo
s = getHelper().getRepository().login(new SimpleCredentials(uid, uid.toCharArray()));
fail("Non-saved user node -> must not be able to login.");
} catch (LoginException e) {
// success
} finally {
if (s != null) {
s.logout();
}
superuser.refresh(false);
Authorizable a = ((JackrabbitSession) superuser).getUserManager().getAuthorizable(uid);
if (a != null) {
a.remove();
superuser.save();
}
umgr.autoSave(true);
}
}
use of javax.jcr.SimpleCredentials in project jackrabbit by apache.
the class BasicCredentialsProviderTest method testDefaultPassword.
public void testDefaultPassword() throws ServletException, LoginException {
Map<String, char[]> m = new HashMap<String, char[]>();
m.put("userId", new char[0]);
m.put("userId:", new char[0]);
m.put("userId:pw", "pw".toCharArray());
for (String uid : m.keySet()) {
char[] pw = m.get(uid);
CredentialsProvider cb = new BasicCredentialsProvider(uid);
Credentials creds = cb.getCredentials(new RequestImpl(null));
assertNotNull(creds);
assertTrue(creds instanceof SimpleCredentials);
assertEquals("userId", ((SimpleCredentials) creds).getUserID());
if (pw.length == 0) {
assertEquals(0, ((SimpleCredentials) creds).getPassword().length);
} else {
assertEquals(new String(pw), new String(((SimpleCredentials) creds).getPassword()));
}
}
}
use of javax.jcr.SimpleCredentials in project jackrabbit-oak by apache.
the class WikipediaImport method run.
private void run(Repository repository) throws Exception {
Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
try {
int before = importWikipedia(session);
int after = new Traversal().traverse(session);
checkState(before == after, "Import vs. traverse mismatch");
} finally {
session.logout();
}
}
Aggregations