use of org.apache.jackrabbit.core.RepositoryImpl in project jackrabbit-oak by apache.
the class SameNodeSiblingsTest method migrate.
private DocumentNodeStore migrate(SourceDataCreator sourceDataCreator) throws RepositoryException, IOException {
RepositoryConfig config = RepositoryConfig.install(crx2RepoDir);
RepositoryImpl repository = RepositoryImpl.create(config);
try {
Session session = repository.login(CREDENTIALS);
sourceDataCreator.create(session);
session.logout();
} finally {
repository.shutdown();
}
// re-create the config
config = RepositoryConfig.install(crx2RepoDir);
RepositoryContext context = RepositoryContext.create(config);
DocumentNodeStore target = new DocumentMK.Builder().getNodeStore();
try {
RepositoryUpgrade upgrade = new RepositoryUpgrade(context, target);
upgrade.copy(null);
} finally {
context.getRepository().shutdown();
}
return target;
}
use of org.apache.jackrabbit.core.RepositoryImpl in project jackrabbit-oak by apache.
the class UpgradeFromTwoSourcesTest method upgradeRepository.
@Before
public synchronized void upgradeRepository() throws Exception {
if (!upgradeComplete) {
final File sourceDir1 = new File(getTestDirectory(), "source1");
final File sourceDir2 = new File(getTestDirectory(), "source2");
sourceDir1.mkdirs();
sourceDir2.mkdirs();
final RepositoryImpl source1 = createSourceRepository(sourceDir1);
final RepositoryImpl source2 = createSourceRepository(sourceDir2);
final Session session1 = source1.login(CREDENTIALS);
final Session session2 = source2.login(CREDENTIALS);
try {
createSourceContent(session1);
createSourceContent2(session2);
} finally {
session1.save();
session2.save();
session1.logout();
session2.logout();
source1.shutdown();
source2.shutdown();
}
final NodeStore target = getTargetNodeStore();
doUpgradeRepository(sourceDir1, target, "/left");
doUpgradeRepository(sourceDir2, target, "/right", "/left/child2", "/left/child3");
fileStore.flush();
upgradeComplete = true;
}
}
use of org.apache.jackrabbit.core.RepositoryImpl in project jackrabbit by apache.
the class SimpleSecurityManager method init.
//------------------------------------------< JackrabbitSecurityManager >---
/**
* @see JackrabbitSecurityManager#init(Repository, Session)
*/
public void init(Repository repository, Session systemSession) throws RepositoryException {
if (initialized) {
throw new IllegalStateException("already initialized");
}
if (!(repository instanceof RepositoryImpl)) {
throw new RepositoryException("RepositoryImpl expected");
}
this.systemSession = systemSession;
config = ((RepositoryImpl) repository).getConfig().getSecurityConfig();
// read the LoginModule configuration
LoginModuleConfig loginModConf = config.getLoginModuleConfig();
authCtxProvider = new AuthContextProvider(config.getAppName(), loginModConf);
if (authCtxProvider.isLocal()) {
log.info("init: using Repository LoginModule configuration for " + config.getAppName());
} else if (authCtxProvider.isJAAS()) {
log.info("init: using JAAS LoginModule configuration for " + config.getAppName());
} else {
String msg = "No valid LoginModule configuriation for " + config.getAppName();
log.error(msg);
throw new RepositoryException(msg);
}
Properties[] moduleConfig = authCtxProvider.getModuleConfig();
// retrieve default-ids (admin and anonymous) from login-module-configuration.
for (Properties aModuleConfig1 : moduleConfig) {
if (aModuleConfig1.containsKey(LoginModuleConfig.PARAM_ADMIN_ID)) {
adminID = aModuleConfig1.getProperty(LoginModuleConfig.PARAM_ADMIN_ID);
}
if (aModuleConfig1.containsKey(LoginModuleConfig.PARAM_ANONYMOUS_ID)) {
anonymID = aModuleConfig1.getProperty(LoginModuleConfig.PARAM_ANONYMOUS_ID);
}
}
// fallback:
if (adminID == null) {
log.debug("No adminID defined in LoginModule/JAAS config -> using default.");
adminID = SecurityConstants.ADMIN_ID;
}
if (anonymID == null) {
log.debug("No anonymousID defined in LoginModule/JAAS config -> using default.");
anonymID = SecurityConstants.ANONYMOUS_ID;
}
// most simple principal provider registry, that does not read anything
// from configuration
PrincipalProvider principalProvider = new SimplePrincipalProvider();
// skip init of provider (nop)
principalProviderRegistry = new ProviderRegistryImpl(principalProvider);
// register all configured principal providers.
for (Properties aModuleConfig : moduleConfig) {
principalProviderRegistry.registerProvider(aModuleConfig);
}
SecurityManagerConfig smc = config.getSecurityManagerConfig();
if (smc != null && smc.getWorkspaceAccessConfig() != null) {
workspaceAccessManager = smc.getWorkspaceAccessConfig().newInstance(WorkspaceAccessManager.class);
} else {
// fallback -> the default simple implementation
log.debug("No WorkspaceAccessManager configured; using default.");
workspaceAccessManager = new SimpleWorkspaceAccessManager();
}
workspaceAccessManager.init(systemSession);
initialized = true;
}
use of org.apache.jackrabbit.core.RepositoryImpl in project jackrabbit by apache.
the class IndexingQueueTest method testReaderUpToDate.
/*
* Test case for JCR-2082
*/
public void testReaderUpToDate() throws Exception {
BlockingParser.block();
SearchIndex index = getSearchIndex();
File indexDir = new File(index.getPath());
// shutdown workspace
RepositoryImpl repo = (RepositoryImpl) session.getRepository();
session.logout();
session = null;
superuser.logout();
superuser = null;
TestHelper.shutdownWorkspace(getWorkspaceName(), repo);
// delete index
try {
FileUtil.delete(indexDir);
} catch (IOException e) {
fail("Unable to delete index directory");
}
BlockingParser.unblock();
// start workspace again by getting a session
session = getHelper().getSuperuserSession(getWorkspaceName());
qm = session.getWorkspace().getQueryManager();
Query q = qm.createQuery(testPath, Query.XPATH);
assertEquals(1, getSize(q.execute().getNodes()));
}
use of org.apache.jackrabbit.core.RepositoryImpl in project jackrabbit by apache.
the class PersistenceManagerIteratorTest method testGetAllNodeIds.
public void testGetAllNodeIds() throws Exception {
Node root = testRootNode;
Session session = root.getSession();
Repository rep = session.getRepository();
if (!(rep instanceof RepositoryImpl)) {
log("Test skipped. Required repository class: " + RepositoryImpl.class + " got: " + rep.getClass());
return;
}
RepositoryImpl r = (RepositoryImpl) rep;
RepositoryConfig conf = r.getConfig();
Collection<WorkspaceConfig> coll = conf.getWorkspaceConfigs();
String[] names = new String[coll.size()];
Iterator<WorkspaceConfig> wspIt = coll.iterator();
for (int i = 0; wspIt.hasNext(); i++) {
WorkspaceConfig wsc = wspIt.next();
names[i] = wsc.getName();
}
for (int i = 0; i < names.length && i < 1; i++) {
Session s = getHelper().getSuperuserSession(names[i]);
try {
Method m = r.getClass().getDeclaredMethod("getWorkspaceInfo", new Class[] { String.class });
m.setAccessible(true);
Object info = m.invoke(r, names[i]);
m = info.getClass().getDeclaredMethod("getPersistenceManager", new Class[0]);
m.setAccessible(true);
PersistenceManager pm = (PersistenceManager) m.invoke(info, new Object[0]);
if (!(pm instanceof AbstractBundlePersistenceManager)) {
log("PM skipped: " + pm.getClass());
continue;
}
AbstractBundlePersistenceManager apm = (AbstractBundlePersistenceManager) pm;
log("PM: " + pm.getClass().getName());
log("All nodes in one step");
NodeId after = null;
NodeId first = null;
for (NodeId id : apm.getAllNodeIds(null, 0)) {
log(" " + id);
if (first == null) {
// initialize first node id
first = id;
}
if (after != null) {
assertFalse(id.compareTo(after) == 0);
}
after = id;
}
// start with first
after = first;
log("All nodes using batches");
while (true) {
log(" bigger than: " + after);
Iterator<NodeId> it = apm.getAllNodeIds(after, 2).iterator();
if (!it.hasNext()) {
break;
}
while (it.hasNext()) {
NodeId id = it.next();
log(" " + id);
assertFalse(id.compareTo(after) == 0);
after = id;
}
}
log("Random access");
for (int j = 0; j < 50; j++) {
after = NodeId.randomId();
log(" bigger than: " + after);
for (NodeId id : apm.getAllNodeIds(after, 2)) {
log(" " + id);
assertFalse(id.compareTo(after) == 0);
after = id;
}
}
} finally {
s.logout();
}
}
}
Aggregations