SecurityService extends DefaultComponent { public PermissionProvider getPermissionProvider() { return permissionProvider; }  @Override void activate(ComponentContext context); @Override void deactivate(ComponentContext context); @Override void registerContribution(Object contribution,
            String extensionPoint, ComponentInstance contributor); @Override void unregisterContribution(Object contribution,
            String extensionPoint, ComponentInstance contributor); PermissionProvider getPermissionProvider(); boolean arePoliciesRestrictingPermission(String permission); boolean arePoliciesExpressibleInQuery(String repositoryName); Collection<SQLQuery.Transformer> getPoliciesQueryTransformers(
            String repositoryName); boolean checkPermission(Document doc, Principal principal,
            String permission); String[] getPermissionsToCheck(String permission); static String[] getPrincipalsToCheck(Principal principal); @SuppressWarnings("unchecked") @Override T getAdapter(Class<T> adapter); static final ComponentName NAME; static final String PERMISSIONS_EXTENSION_POINT; }
@Test public void testDefaultPermissions() { PermissionProvider pp = service.getPermissionProvider(); String[] groups = pp.getPermissionGroups("Read"); assertNotNull(groups); assertEquals(Arrays.asList("ReadRemove", "ReadWrite"), Arrays.asList(groups)); groups = pp.getPermissionGroups("ReadProperties"); assertNotNull(groups); assertEquals(Arrays.asList("Read", "ReadRemove", "ReadWrite"), Arrays.asList(groups)); groups = pp.getPermissionGroups("ReadChildren"); assertNotNull(groups); assertEquals(Arrays.asList("Read", "ReadRemove", "ReadWrite"), Arrays.asList(groups)); groups = pp.getPermissionGroups("Browse"); assertNotNull(groups); assertEquals(Arrays.asList("Read", "ReadProperties", "ReadRemove", "ReadWrite"), Arrays.asList(groups)); }
@Test public void testDefaultVisiblePermission() throws Exception { PermissionProvider pp = service.getPermissionProvider(); List<UserVisiblePermission> orderedVisiblePermissions = pp.getUserVisiblePermissionDescriptors(); assertNotNull(orderedVisiblePermissions); assertEquals( Arrays.asList("Read", "ReadWrite", "ReadRemove", "Everything"), permStrings(orderedVisiblePermissions)); orderedVisiblePermissions = pp.getUserVisiblePermissionDescriptors("Section"); assertNotNull(orderedVisiblePermissions); assertEquals( Arrays.asList("Read", "ReadWrite", "ReadRemove", "Everything"), permStrings(orderedVisiblePermissions)); orderedVisiblePermissions = pp.getUserVisiblePermissionDescriptors("Workspace"); assertNotNull(orderedVisiblePermissions); assertEquals( Arrays.asList("Read", "ReadWrite", "ReadRemove", "Everything"), permStrings(orderedVisiblePermissions)); }
@Test public void testOverridedPermissions1() throws Exception { deployContrib(CoreUTConstants.CORE_TESTS_BUNDLE, "permissions-override1-contrib.xml"); PermissionProvider pp = service.getPermissionProvider(); String[] groups = pp.getPermissionGroups("Read"); assertNotNull(groups); assertEquals( Arrays.asList("CustomCompoundPerm", "ReadRemove", "ReadWrite"), Arrays.asList(groups)); groups = pp.getPermissionGroups("ReadProperties"); assertNotNull(groups); assertEquals(Arrays.asList("CustomCompoundPerm", "Read", "ReadRemove", "ReadWrite"), Arrays.asList(groups)); groups = pp.getPermissionGroups("ReadChildren"); assertNotNull(groups); assertEquals(Arrays.asList("CustomCompoundPerm", "Read", "ReadRemove", "ReadWrite"), Arrays.asList(groups)); groups = pp.getPermissionGroups("Browse"); assertNotNull(groups); assertEquals(Arrays.asList("CustomCompoundPerm", "Read", "ReadProperties", "ReadRemove", "ReadWrite"), Arrays.asList(groups)); groups = pp.getPermissionGroups("CustomCompoundPerm"); assertNull(groups); groups = pp.getPermissionGroups("CustomAtomicPerm"); assertNotNull(groups); assertEquals(Arrays.asList("CustomCompoundPerm"), Arrays.asList(groups)); }
@Test public void testOverridedVisiblePermission1() throws Exception { deployContrib(CoreUTConstants.CORE_TESTS_BUNDLE, "permissions-override1-contrib.xml"); PermissionProvider pp = service.getPermissionProvider(); List<UserVisiblePermission> orderedVisiblePermissions = pp.getUserVisiblePermissionDescriptors(); assertNotNull(orderedVisiblePermissions); assertEquals(Arrays.asList("Read", "CustomCompoundPerm", "ReadWrite", "ReadRemove", "Everything"), permStrings(orderedVisiblePermissions)); orderedVisiblePermissions = pp.getUserVisiblePermissionDescriptors("Section"); assertNotNull(orderedVisiblePermissions); assertEquals(Arrays.asList("Read", "CustomCompoundPerm", "ReadWrite", "ReadRemove", "Everything"), permStrings(orderedVisiblePermissions)); orderedVisiblePermissions = pp.getUserVisiblePermissionDescriptors("Workspace"); assertNotNull(orderedVisiblePermissions); assertEquals(Arrays.asList("Read", "CustomCompoundPerm", "ReadWrite", "ReadRemove", "Everything"), permStrings(orderedVisiblePermissions)); }
@Test public void testOverriddenPermissions2() throws Exception { deployContrib(CoreUTConstants.CORE_TESTS_BUNDLE, "permissions-override2-contrib.xml"); PermissionProvider pp = service.getPermissionProvider(); testDefaultPermissions(); String[] groups = pp.getPermissionGroups("CustomCompoundPerm"); assertNull(groups); groups = pp.getPermissionGroups("CustomAtomicPerm"); assertNotNull(groups); assertEquals(Arrays.asList("ReadWrite", "Write"), Arrays.asList(groups)); }
@Test public void testOverridedVisiblePermission2() throws Exception { deployContrib(CoreUTConstants.CORE_TESTS_BUNDLE, "permissions-override2-contrib.xml"); PermissionProvider pp = service.getPermissionProvider(); List<UserVisiblePermission> orderedVisiblePermissions = pp.getUserVisiblePermissionDescriptors(); assertNotNull(orderedVisiblePermissions); assertEquals(Arrays.asList("Write", "Read", "ReadRemove", "Everything"), permStrings(orderedVisiblePermissions)); orderedVisiblePermissions = pp.getUserVisiblePermissionDescriptors("Section"); assertNotNull(orderedVisiblePermissions); assertEquals(Arrays.asList("Write", "Read", "ReadRemove", "Everything"), permStrings(orderedVisiblePermissions)); orderedVisiblePermissions = pp.getUserVisiblePermissionDescriptors("Workspace"); assertNotNull(orderedVisiblePermissions); assertEquals(Arrays.asList("Write", "Read", "ReadRemove", "Everything"), permStrings(orderedVisiblePermissions)); }
@Test public void testOverridedVisiblePermission3() throws Exception { deployContrib(CoreUTConstants.CORE_TESTS_BUNDLE, "permissions-override3-contrib.xml"); PermissionProvider pp = service.getPermissionProvider(); List<UserVisiblePermission> orderedVisiblePermissions = pp.getUserVisiblePermissionDescriptors(); assertNotNull(orderedVisiblePermissions); assertEquals(Arrays.asList("Write", "Read", "ReadRemove", "Everything"), permStrings(orderedVisiblePermissions)); orderedVisiblePermissions = pp.getUserVisiblePermissionDescriptors("Section"); assertNotNull(orderedVisiblePermissions); assertEquals( Arrays.asList("Write", "ReadRemove", "Everything", "Read"), permStrings(orderedVisiblePermissions)); orderedVisiblePermissions = pp.getUserVisiblePermissionDescriptors("Workspace"); assertNotNull(orderedVisiblePermissions); assertEquals(Arrays.asList("Write", "Read", "ReadRemove", "Everything"), permStrings(orderedVisiblePermissions)); }
@Test public void testPermissionsVsDeny() throws Exception { PermissionProvider pp = service.getPermissionProvider(); List<UserVisiblePermission> vp = pp.getUserVisiblePermissionDescriptors(); assertNotNull(vp); UserVisiblePermission deleteVP = null; for (UserVisiblePermission uvp : vp) { if (uvp.getId().equals("ReadRemove")) { deleteVP = uvp; break; } } assertNotNull(deleteVP); assertEquals("Remove", deleteVP.getDenyPermission()); assertEquals("ReadRemove", deleteVP.getPermission()); }