SecurityProviderRegistration { public void unbindAggregationFilter(@NotNull ServiceReference serviceReference, @NotNull AggregationFilter aggregationFilter) { synchronized (this) { aggregationFilters.remove(serviceReference); removeCandidate(serviceReference); } maybeUnregister(); }  @Activate void activate(BundleContext context, Configuration configuration); @Modified void modified(Configuration configuration); @Deactivate void deactivate(); @Reference(name = "authenticationConfiguration") void bindAuthenticationConfiguration(AuthenticationConfiguration authenticationConfiguration); void unbindAuthenticationConfiguration(AuthenticationConfiguration authenticationConfiguration); @Reference(name = "privilegeConfiguration") void bindPrivilegeConfiguration(PrivilegeConfiguration privilegeConfiguration); void unbindPrivilegeConfiguration(PrivilegeConfiguration privilegeConfiguration); @Reference(name = "userConfiguration") void bindUserConfiguration(UserConfiguration userConfiguration); void unbindUserConfiguration(UserConfiguration userConfiguration); @Reference(name = "rootProvider") void bindRootProvider(RootProvider rootProvider); void unbindRootProvider(RootProvider rootProvider); @Reference(name = "treeProvider") void bindTreeProvider(TreeProvider treeProvider); void unbindTreeProvider(TreeProvider treeProvider); @Reference( name = "authorizationConfiguration", service = AuthorizationConfiguration.class, cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC ) void bindAuthorizationConfiguration(AuthorizationConfiguration configuration, Map<String, Object> properties); void unbindAuthorizationConfiguration(AuthorizationConfiguration configuration, Map<String, Object> properties); @Reference( name = "principalConfiguration", service = PrincipalConfiguration.class, cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC ) void bindPrincipalConfiguration(PrincipalConfiguration configuration, Map<String, Object> properties); void unbindPrincipalConfiguration(PrincipalConfiguration configuration, Map<String, Object> properties); @Reference( name = "tokenConfiguration", service = TokenConfiguration.class, cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC ) void bindTokenConfiguration(TokenConfiguration configuration, Map<String, Object> properties); void unbindTokenConfiguration(TokenConfiguration configuration, Map<String, Object> properties); @Reference( name = "authorizableNodeName", service = AuthorizableNodeName.class, cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC ) void bindAuthorizableNodeName(@NotNull ServiceReference serviceReference, @NotNull AuthorizableNodeName authorizableNodeName); void unbindAuthorizableNodeName(@NotNull ServiceReference serviceReference, @NotNull AuthorizableNodeName authorizableNodeName); @Reference( name = "authorizableActionProvider", service = AuthorizableActionProvider.class, cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC ) void bindAuthorizableActionProvider(@NotNull ServiceReference serviceReference, @NotNull AuthorizableActionProvider authorizableActionProvider); void unbindAuthorizableActionProvider(@NotNull ServiceReference serviceReference, @NotNull AuthorizableActionProvider authorizableActionProvider); @Reference( name = "restrictionProvider", service = RestrictionProvider.class, cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC ) void bindRestrictionProvider(@NotNull ServiceReference serviceReference, @NotNull RestrictionProvider restrictionProvider); void unbindRestrictionProvider(@NotNull ServiceReference serviceReference, @NotNull RestrictionProvider restrictionProvider); @Reference( name = "userAuthenticationFactory", service = UserAuthenticationFactory.class, cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC ) void bindUserAuthenticationFactory(@NotNull ServiceReference serviceReference, @NotNull UserAuthenticationFactory userAuthenticationFactory); void unbindUserAuthenticationFactory(@NotNull ServiceReference serviceReference, @NotNull UserAuthenticationFactory userAuthenticationFactory); @Reference( name = "aggregationFilters", service = AggregationFilter.class, cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) void bindAggregationFilter(@NotNull ServiceReference serviceReference, @NotNull AggregationFilter aggregationFilter); void unbindAggregationFilter(@NotNull ServiceReference serviceReference, @NotNull AggregationFilter aggregationFilter);  }
@Test public void testUnbindAggregationFilter() { registration.activate(context.bundleContext(), configWithRequiredServiceIds("a1", "a2", "f1")); AggregationFilter filter = mock(AggregationFilter.class, withSettings().defaultAnswer(invocationOnMock -> Boolean.TRUE)); ServiceRegistration sr = context.bundleContext().registerService(AggregationFilter.class.getName(), filter, new Hashtable(ImmutableMap.of(SERVICE_PID, "f1"))); registration.bindAggregationFilter(sr.getReference(), filter); AggregatedPermissionProvider pp = mock(AggregatedPermissionProvider.class); AuthorizationConfiguration ac1 = mock(AuthorizationConfiguration.class); AuthorizationConfiguration ac2 = mock(AuthorizationConfiguration.class); for (AuthorizationConfiguration ac : new AuthorizationConfiguration[]{ac1, ac2}) { when(ac.getPermissionProvider(any(Root.class), anyString(), any(Set.class))).thenReturn(pp); when(ac.getParameters()).thenReturn(ConfigurationParameters.EMPTY); when(ac.getContext()).thenReturn(Context.DEFAULT); } registration.bindAuthorizationConfiguration(ac1, new Hashtable(ImmutableMap.of(SERVICE_PID, "a1"))); registration.bindAuthorizationConfiguration(ac2, new Hashtable(ImmutableMap.of(SERVICE_PID, "a2"))); AuthorizationConfiguration ac = context.getService(SecurityProvider.class).getConfiguration(AuthorizationConfiguration.class); assertTrue(ac instanceof CompositeAuthorizationConfiguration); PermissionProvider permissionProvider = ac.getPermissionProvider(root, adminSession.getWorkspaceName(), ImmutableSet.of()); assertSame(pp, permissionProvider); verify(filter, times(1)).stop(pp, ImmutableSet.of()); registration.unbindAggregationFilter(sr.getReference(), filter); assertNull(context.getService(SecurityProvider.class)); registration.modified(configWithRequiredServiceIds("a1", "a2")); context.getService(SecurityProvider.class).getConfiguration(AuthorizationConfiguration.class).getPermissionProvider(root, adminSession.getWorkspaceName(), ImmutableSet.of()); verify(filter, times(1)).stop(pp, ImmutableSet.of()); }