PrivilegeManagerImpl implements PrivilegeManager { @NotNull @Override public Privilege getPrivilege(@NotNull String privilegeName) throws RepositoryException { PrivilegeDefinition def = getPrivilegeDefinition(getOakName(privilegeName)); if (def == null) { throw new AccessControlException("No such privilege " + privilegeName); } else { return getPrivilege(def); } } PrivilegeManagerImpl(Root root, NamePathMapper namePathMapper); @NotNull @Override Privilege[] getRegisteredPrivileges(); @NotNull @Override Privilege getPrivilege(@NotNull String privilegeName); @NotNull @Override Privilege registerPrivilege(@NotNull String privilegeName, boolean isAbstract,
                                       @Nullable String[] declaredAggregateNames);  }
@Test public void testGetPrivilege() throws Exception { Privilege p = privilegeManager.getPrivilege(PrivilegeConstants.JCR_VERSION_MANAGEMENT); assertNotNull(p); assertEquals(PrivilegeConstants.JCR_VERSION_MANAGEMENT, p.getName()); }
@Test(expected = AccessControlException.class) public void testGetPrivilegeExpandedNameMissingMapper() throws Exception { Privilege p = privilegeManager.getPrivilege(Privilege.JCR_VERSION_MANAGEMENT); assertNotNull(p); assertEquals(PrivilegeConstants.JCR_VERSION_MANAGEMENT, p.getName()); }
@Test public void testGetPrivilegeExpandedName() throws Exception { Privilege p = create(root, new NamePathMapperImpl(new GlobalNameMapper(root))).getPrivilege(Privilege.JCR_VERSION_MANAGEMENT); assertNotNull(p); assertNotEquals(Privilege.JCR_VERSION_MANAGEMENT, p.getName()); assertEquals(PrivilegeConstants.JCR_VERSION_MANAGEMENT, p.getName()); }
@Test public void testGetPrivilegeRemappedNamespace() throws Exception { NamePathMapper mapper = new NamePathMapperImpl(new LocalNameMapper(root, ImmutableMap.of("prefix", NamespaceRegistry.NAMESPACE_JCR))); Privilege p = create(root, mapper).getPrivilege("prefix:read"); assertNotNull(p); assertNotEquals(Privilege.JCR_READ, p.getName()); assertNotEquals(PrivilegeConstants.JCR_READ, p.getName()); assertEquals("prefix:read", p.getName()); }
@Test(expected = AccessControlException.class) public void testGetPrivilegeInvalidRemappedNamespace() throws Exception { NamePathMapper mapper = new NamePathMapperImpl(new LocalNameMapper(root, ImmutableMap.of("prefix", "unknownUri"))); create(root, mapper).getPrivilege("prefix:read"); }
@Test(expected = AccessControlException.class) public void testGetPrivilegeFromEmptyRoot() throws Exception { create(getRootProvider().createReadOnlyRoot(EmptyNodeState.EMPTY_NODE)).getPrivilege(PrivilegeConstants.JCR_READ); }
@Test(expected = AccessControlException.class) public void testGetUnknownPrivilege() throws Exception { create(getRootProvider().createReadOnlyRoot(EmptyNodeState.EMPTY_NODE)).getPrivilege("jcr:someName"); }
@Test(expected = AccessControlException.class) public void testGetPrivilegeEmptyName() throws Exception { create(getRootProvider().createReadOnlyRoot(EmptyNodeState.EMPTY_NODE)).getPrivilege(""); }
@Test(expected = AccessControlException.class) public void testGetPrivilegeNullName() throws Exception { create(getRootProvider().createReadOnlyRoot(EmptyNodeState.EMPTY_NODE)).getPrivilege(null); }