use of javax.jcr.Repository in project jackrabbit by apache.
the class Login method execute.
/**
* {@inheritDoc}
*/
public boolean execute(Context ctx) throws Exception {
String anon = "anonymous";
String user = (String) ctx.get(this.userKey);
String password = (String) ctx.get(this.passwordKey);
String workspace = (String) ctx.get(this.workspaceKey);
if (user == null) {
user = anon;
}
if (password == null || (password.equals(anon) && !user.equals(anon))) {
ConsoleReader reader = new ConsoleReader();
password = reader.readLine("Password: ", (char) 0);
}
if (log.isDebugEnabled()) {
log.debug("logging in as " + user);
}
Session session = null;
Repository repo = CommandHelper.getRepository(ctx);
Credentials credentials = new SimpleCredentials(user, password.toCharArray());
if (workspace == null) {
session = repo.login(credentials);
} else {
session = repo.login(credentials, workspace);
}
CommandHelper.setSession(ctx, session);
CommandHelper.setCurrentNode(ctx, session.getRootNode());
return false;
}
use of javax.jcr.Repository in project jackrabbit-oak by apache.
the class PersistentCacheTest method createRepository.
@Override
protected Repository[] createRepository(RepositoryFixture fixture) throws Exception {
System.setProperty("PersistentCacheStats.rejectedPut", "true");
if (fixture instanceof OakRepositoryFixture) {
OakFixture oakFixture = ((OakRepositoryFixture) fixture).getOakFixture();
if (oakFixture instanceof OakFixture.MongoFixture) {
OakFixture.MongoFixture mongoFixture = (OakFixture.MongoFixture) oakFixture;
DocumentMK.Builder builder = mongoFixture.getBuilder(1);
builder.setStatisticsProvider(statsProvider);
builder.setPersistentCache("target/persistentCache,time," + CACHE_OPTIONS);
dns = builder.getNodeStore();
nodesCache = DocumentNodeStoreHelper.getNodesCache(dns);
Oak[] cluster = mongoFixture.setUpCluster(new DocumentMK.Builder[] { builder }, statsProvider);
return new Repository[] { new Jcr(cluster[0]).createRepository() };
}
}
throw new IllegalArgumentException("Fixture " + fixture + " not supported for this benchmark.");
}
use of javax.jcr.Repository in project jackrabbit-oak by apache.
the class ObservationTest method run.
@Override
public void run(Iterable<RepositoryFixture> fixtures) {
for (RepositoryFixture fixture : fixtures) {
if (fixture.isAvailable(1)) {
System.out.format("%s: Observation throughput benchmark%n", fixture);
try {
final AtomicReference<Whiteboard> whiteboardRef = new AtomicReference<Whiteboard>();
Repository[] cluster;
if (fixture instanceof OakRepositoryFixture) {
cluster = ((OakRepositoryFixture) fixture).setUpCluster(1, new JcrCreator() {
@Override
public Jcr customize(Oak oak) {
whiteboardRef.set(oak.getWhiteboard());
return new Jcr(oak);
}
});
} else {
cluster = fixture.setUpCluster(1);
}
try {
run(cluster[0], whiteboardRef.get());
} finally {
fixture.tearDownCluster();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
use of javax.jcr.Repository in project jackrabbit by apache.
the class AbstractRepositoryTest method testLoginWithNullWorkspace.
/**
* Tests the {@link AbstractRepository#login(String)} method with a
* <code>null</code> workspace name.
*
* @throws RepositoryException if an error occurs
*/
public void testLoginWithNullWorkspace() throws RepositoryException {
Repository repository = (Repository) record(AbstractRepository.class);
repository.login(null, null);
replay();
repository.login((String) null);
verify();
}
use of javax.jcr.Repository in project jackrabbit by apache.
the class AbstractRepositoryTest method testLoginWithCredentials.
/**
* Tests the {@link AbstractRepository#login(Credentials)} method.
*
* @throws RepositoryException if an error occurs
*/
public void testLoginWithCredentials() throws RepositoryException {
Credentials credentials = new SimpleCredentials("", "".toCharArray());
Repository repository = (Repository) record(AbstractRepository.class);
repository.login(credentials, null);
replay();
repository.login(credentials);
verify();
}
Aggregations