JcrPackageManagerImpl extends PackageManagerImpl implements JcrPackageManager { @Override public Node getPackageRoot() throws RepositoryException { return registry.getPrimaryPackageRoot(true); } JcrPackageManagerImpl(@NotNull Session session, @Nullable String[] roots);  JcrPackageManagerImpl(@NotNull Session session, @Nullable String[] roots, @Nullable String[] authIdsForHookExecution, @Nullable String[] authIdsForRootInstallation); protected  JcrPackageManagerImpl(JcrPackageRegistry registry); PackageRegistry getRegistry(); JcrPackageRegistry getInternalRegistry(); @Override JcrPackage open(PackageId id); @Override JcrPackage open(Node node); @Override JcrPackage open(Node node, boolean allowInvalid); @Override PackageId resolve(Dependency dependency, boolean onlyInstalled); @Override PackageId[] usage(PackageId id); @Override JcrPackage upload(InputStream in, boolean replace); @Override JcrPackage upload(InputStream in, boolean replace, boolean strict); @NotNull @Override PackageId[] extract(@NotNull Archive archive, @NotNull ImportOptions options, boolean replace); @Override JcrPackage upload(File file, boolean isTmpFile, boolean replace, String nameHint); @Override JcrPackage upload(File file, boolean isTmpFile, boolean replace, String nameHint, boolean strict); @Override JcrPackage create(Node folder, String name); @Override JcrPackage create(String group, String name); @Override JcrPackage create(String group, String name, String version); @Override void remove(JcrPackage pack); @Override JcrPackage rename(JcrPackage pack, String group, String name); @Override JcrPackage rename(JcrPackage pack, String group, String name, String version); @Override void assemble(JcrPackage pack, ProgressTrackerListener listener); @Override void assemble(Node packNode, JcrPackageDefinition definition,
                         ProgressTrackerListener listener); @Override void assemble(JcrPackageDefinition definition,
                         ProgressTrackerListener listener, OutputStream out); @Override void rewrap(JcrPackage pack, ProgressTrackerListener listener); @Override Node getPackageRoot(); @Override Node getPackageRoot(boolean noCreate); @Override List<JcrPackage> listPackages(); @Override List<JcrPackage> listPackages(WorkspaceFilter filter); @Override List<JcrPackage> listPackages(String group, boolean built); @Override void setDispatcher(@Nullable PackageEventDispatcher dispatcher); final static String ARCHIVE_PACKAGE_ROOT_PATH; }
@Test public void testGetPackageRootNoCreate() throws Exception { JcrPackageManagerImpl jcrPackageManager = new JcrPackageManagerImpl(admin, new String[0]); assertNull(jcrPackageManager.getPackageRoot(true)); }
@Test public void testGetPackageRootWithCreate() throws Exception { JcrPackageManagerImpl jcrPackageManager = new JcrPackageManagerImpl(admin, new String[0]); Node packageNode = jcrPackageManager.getPackageRoot(false); assertEquals("/etc/packages", packageNode.getPath()); }
@Test public void testGetPackageRootTwice() throws Exception { JcrPackageManagerImpl jcrPackageManager = new JcrPackageManagerImpl(admin, new String[0]); Node packageNode = jcrPackageManager.getPackageRoot(false); assertSame(packageNode, jcrPackageManager.getPackageRoot()); }
@Test public void testAlternativePackageRootCreatesOnlyOneNode() throws RepositoryException { JcrPackageManagerImpl jcrPackageManager = new JcrPackageManagerImpl(admin, new String[]{"/var/packages", "/etc/packages"}); Node packageNode = jcrPackageManager.getPackageRoot(false); assertEquals("/var/packages", packageNode.getPath()); assertNodeMissing("/etc/packages"); }
@Test public void testGetPackageRootWithAdminPendingChanges() throws Exception { admin.getRootNode().addNode("testNode"); JcrPackageManagerImpl jcrPackageManager = new JcrPackageManagerImpl(admin, new String[0]); try { jcrPackageManager.getPackageRoot(false); fail("transient modifications must fail the package root creation."); } catch (RepositoryException e) { } }
@Test public void testGetPackageRootNoRootAccess() throws Exception { Node packageRoot = packMgr.getPackageRoot(); AccessControlManager acMgr = admin.getAccessControlManager(); JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, "/"); acMgr.removePolicy(acl.getPath(), acl); AccessControlUtils.getAccessControlList(acMgr, "/etc/packages"); AccessControlUtils.allow(packageRoot, org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal.NAME, javax.jcr.security.Privilege.JCR_READ); admin.save(); Session anonymous = repository.login(new GuestCredentials()); try { assertFalse(anonymous.nodeExists("/")); assertFalse(anonymous.nodeExists("/etc")); assertTrue(anonymous.nodeExists("/etc/packages")); JcrPackageManagerImpl jcrPackageManager = new JcrPackageManagerImpl(anonymous, new String[0]); jcrPackageManager.getPackageRoot(false); } finally { anonymous.logout(); } }
@Test public void testGetPackageRootNoCreateAccess() throws Exception { AccessControlManager acMgr = admin.getAccessControlManager(); JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, "/"); for (AccessControlEntry ace : acl.getAccessControlEntries()) { acl.removeAccessControlEntry(ace); } acl.addEntry(AccessControlUtils.getEveryonePrincipal(admin), AccessControlUtils.privilegesFromNames(admin, javax.jcr.security.Privilege.JCR_READ), true, Collections.singletonMap("rep:glob", admin.getValueFactory().createValue("etc/*"))); admin.save(); Session anonymous = repository.login(new GuestCredentials()); try { JcrPackageManagerImpl jcrPackageManager = new JcrPackageManagerImpl(anonymous, new String[0]); assertNull(jcrPackageManager.getPackageRoot(true)); try { jcrPackageManager.getPackageRoot(false); fail(); } catch (AccessDeniedException | PathNotFoundException e) { } } finally { anonymous.logout(); } }