use of javax.jcr.SimpleCredentials in project jackrabbit-oak by apache.
the class UserManagerTest method testNewUserCanLogin.
@Test
public void testNewUserCanLogin() throws RepositoryException, NotExecutableException {
String uid = createUserId();
User u = null;
Session s = null;
try {
u = userMgr.createUser(uid, "pw");
superuser.save();
Credentials creds = new SimpleCredentials(uid, "pw".toCharArray());
s = superuser.getRepository().login(creds);
} finally {
if (u != null) {
u.remove();
superuser.save();
}
if (s != null) {
s.logout();
}
}
}
use of javax.jcr.SimpleCredentials in project jackrabbit-oak by apache.
the class UserManagerTest method testCreateUserIdDifferentFromPrincipalName.
@Test
public void testCreateUserIdDifferentFromPrincipalName() throws RepositoryException, NotExecutableException {
User u = null;
Session uSession = null;
try {
Principal p = getTestPrincipal();
String uid = createUserId();
u = userMgr.createUser(uid, "pw", p, null);
superuser.save();
String msg = "Creating a User with principal-name distinct from Principal-name must succeed as long as both are unique.";
assertEquals(msg, u.getID(), uid);
assertEquals(msg, p.getName(), u.getPrincipal().getName());
assertFalse(msg, u.getID().equals(u.getPrincipal().getName()));
// make sure the userID exposed by a Session corresponding to that
// user is equal to the users ID.
uSession = superuser.getRepository().login(new SimpleCredentials(uid, "pw".toCharArray()));
assertEquals(uid, uSession.getUserID());
} finally {
if (uSession != null) {
uSession.logout();
}
if (u != null) {
u.remove();
superuser.save();
}
}
}
use of javax.jcr.SimpleCredentials in project jackrabbit-oak by apache.
the class UserManagerTest method testUnknownUserLogin.
@Test
public void testUnknownUserLogin() throws RepositoryException {
String uid = createUserId();
assertNull(userMgr.getAuthorizable(uid));
try {
Session s = superuser.getRepository().login(new SimpleCredentials(uid, uid.toCharArray()));
s.logout();
fail("An unknown user should not be allowed to execute the login.");
} catch (Exception e) {
// ok.
}
}
use of javax.jcr.SimpleCredentials in project jackrabbit-oak by apache.
the class UserManagerTest method testUserIDFromSession.
@Test
public void testUserIDFromSession() throws RepositoryException, NotExecutableException {
User u = null;
Session uSession = null;
try {
String uid = createUserId();
u = userMgr.createUser(uid, "pw");
superuser.save();
uSession = superuser.getRepository().login(new SimpleCredentials(uid, "pw".toCharArray()));
assertEquals(u.getID(), uSession.getUserID());
} finally {
if (uSession != null) {
uSession.logout();
}
if (u != null) {
u.remove();
superuser.save();
}
}
}
use of javax.jcr.SimpleCredentials in project jackrabbit-oak by apache.
the class JsonIndexCommand method openSession.
public static Session openSession(NodeStore nodeStore) throws RepositoryException {
if (nodeStore == null) {
return null;
}
StatisticsProvider statisticsProvider = StatisticsProvider.NOOP;
Oak oak = new Oak(nodeStore).with(ManagementFactory.getPlatformMBeanServer());
oak.getWhiteboard().register(StatisticsProvider.class, statisticsProvider, Collections.emptyMap());
LuceneIndexProvider provider = createLuceneIndexProvider();
oak.with((QueryIndexProvider) provider).with((Observer) provider).with(createLuceneIndexEditorProvider());
Jcr jcr = new Jcr(oak);
Repository repository = jcr.createRepository();
return repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
}
Aggregations