CugConfiguration extends ConfigurationBase implements AuthorizationConfiguration, CugConstants { @NotNull @Override public PermissionProvider getPermissionProvider(@NotNull Root root, @NotNull String workspaceName, @NotNull Set<Principal> principals) { ConfigurationParameters params = getParameters(); boolean enabled = params.getConfigValue(CugConstants.PARAM_CUG_ENABLED, false); if (!enabled || supportedPaths.isEmpty() || getExclude().isExcluded(principals)) { return EmptyPermissionProvider.getInstance(); } else { return new CugPermissionProvider(root, workspaceName, principals, supportedPaths, getSecurityProvider().getConfiguration(AuthorizationConfiguration.class).getContext(), getRootProvider(), getTreeProvider()); } } @SuppressWarnings("UnusedDeclaration")  CugConfiguration();  CugConfiguration(@NotNull SecurityProvider securityProvider); @NotNull @Override AccessControlManager getAccessControlManager(@NotNull Root root, @NotNull NamePathMapper namePathMapper); @NotNull @Override RestrictionProvider getRestrictionProvider(); @NotNull @Override PermissionProvider getPermissionProvider(@NotNull Root root, @NotNull String workspaceName, @NotNull Set<Principal> principals); @NotNull @Override String getName(); @NotNull @Override RepositoryInitializer getRepositoryInitializer(); @NotNull @Override List<? extends CommitHook> getCommitHooks(@NotNull String workspaceName); @NotNull @Override List<? extends ValidatorProvider> getValidators(@NotNull String workspaceName, @NotNull Set<Principal> principals, @NotNull MoveTracker moveTracker); @NotNull @Override List<ProtectedItemImporter> getProtectedItemImporters(); @NotNull @Override Context getContext(); @Override void setParameters(@NotNull ConfigurationParameters config); @Reference(name="mountInfoProvider") void bindMountInfoProvider(MountInfoProvider mountInfoProvider); void unbindMountInfoProvider(MountInfoProvider mountInfoProvider); @Reference(name="exclude", cardinality = ReferenceCardinality.MANDATORY) void bindExclude(CugExclude exclude); void unbindExclude(CugExclude exclude);  }
@Test public void testGetPermissionProviderDisabled() { CugConfiguration cc = createConfiguration(ConfigurationParameters.of(CugConstants.PARAM_CUG_ENABLED, false)); PermissionProvider pp = cc.getPermissionProvider(root, root.getContentSession().getWorkspaceName(), ImmutableSet.of(EveryonePrincipal.getInstance())); assertSame(EmptyPermissionProvider.getInstance(), pp); }
@Test public void testGetPermissionProviderDisabled2() { ConfigurationParameters params = ConfigurationParameters.of( CugConstants.PARAM_CUG_ENABLED, false, CugConstants.PARAM_CUG_SUPPORTED_PATHS, "/content"); CugConfiguration cc = createConfiguration(params); PermissionProvider pp = cc.getPermissionProvider(root, "default", ImmutableSet.of(EveryonePrincipal.getInstance())); assertSame(EmptyPermissionProvider.getInstance(), pp); }
@Test public void testGetPermissionProviderDisabled3() { CugConfiguration cc = createConfiguration(ConfigurationParameters.EMPTY); PermissionProvider pp = cc.getPermissionProvider(root, "default", ImmutableSet.of(EveryonePrincipal.getInstance())); assertSame(EmptyPermissionProvider.getInstance(), pp); }
@Test public void testGetPermissionProviderNoSupportedPaths() { CugConfiguration cc = createConfiguration(ConfigurationParameters.of(CugConstants.PARAM_CUG_ENABLED, true)); PermissionProvider pp = cc.getPermissionProvider(root, "default", ImmutableSet.of(EveryonePrincipal.getInstance())); assertSame(EmptyPermissionProvider.getInstance(), pp); }
@Test public void testGetPermissionProviderSupportedPaths() { ConfigurationParameters params = ConfigurationParameters.of( CugConstants.PARAM_CUG_ENABLED, true, CugConstants.PARAM_CUG_SUPPORTED_PATHS, "/content"); CugConfiguration cc = createConfiguration(params); PermissionProvider pp = cc.getPermissionProvider(root, "default", ImmutableSet.of(EveryonePrincipal.getInstance())); assertTrue(pp instanceof CugPermissionProvider); }
@Test public void testExcludedPrincipals() { ConfigurationParameters params = ConfigurationParameters.of( CugConstants.PARAM_CUG_ENABLED, true, CugConstants.PARAM_CUG_SUPPORTED_PATHS, "/content"); CugConfiguration cc = createConfiguration(params); List<Principal> excluded = ImmutableList.of( SystemPrincipal.INSTANCE, (AdminPrincipal) () -> "admin", (SystemUserPrincipal) () -> "systemUser"); for (Principal p : excluded) { Set<Principal> principals = ImmutableSet.of(p, EveryonePrincipal.getInstance()); PermissionProvider pp = cc.getPermissionProvider(root, "default", principals); assertSame(EmptyPermissionProvider.getInstance(), pp); } }