SLING-8815 - [API Regions] Prevent from resolving to customer-provided
bundles

register the new PlatformIsolationEnforcer via Activator
diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/Activator.java b/src/main/java/org/apache/sling/feature/apiregions/impl/Activator.java
index 190e29b..39b5a0e 100644
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/Activator.java
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/Activator.java
@@ -49,12 +49,16 @@
     BundleContext bundleContext;
     ServiceRegistration<ResolverHookFactory> hookRegistration;
 
+    ServiceRegistration<ResolverHookFactory> platformIsolationRegistration;
+
     @Override
     public synchronized void start(BundleContext context) throws Exception {
         bundleContext = context;
 
         registerHook();
 
+        registerPlatformIsolationEnforcer();
+
         context.addFrameworkListener(this);
     }
 
@@ -80,11 +84,29 @@
         }
     }
 
-    synchronized void unregisterHook() {
-        if (hookRegistration != null) {
-            hookRegistration.unregister();
-            hookRegistration = null;
+    synchronized void registerPlatformIsolationEnforcer() {
+        if (platformIsolationRegistration != null) {
+            return;
         }
+
+        try {
+            PlatformIsolationEnforcer enforcer = new PlatformIsolationEnforcer(bundleContext);
+            platformIsolationRegistration = bundleContext.registerService(ResolverHookFactory.class, enforcer, new Hashtable<>());
+        } catch (Exception e) {
+            RegionEnforcer.LOG.log(Level.SEVERE, "Problem activating Platform Isolation runtime enforcement component", e);
+        }
+    }
+
+    synchronized void unregisterHooks() {
+        hookRegistration = unregisterService(hookRegistration);
+        platformIsolationRegistration = unregisterService(platformIsolationRegistration);
+    }
+
+    private <S> ServiceRegistration<S> unregisterService(ServiceRegistration<S> serviceRegistration) {
+        if (serviceRegistration != null) {
+            serviceRegistration.unregister();
+        }
+        return null;
     }
 
     @Override
@@ -133,9 +155,10 @@
                                         Dictionary<?,?> props = (Dictionary<?,?>) args[0];
                                         Object disabled = props.get("disable");
                                         if ("true".equals(disabled)) {
-                                            unregisterHook();
+                                            unregisterHooks();
                                         } else {
                                             registerHook();
+                                            registerPlatformIsolationEnforcer();
                                         }
                                     }
                                 }
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/ActivatorTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/ActivatorTest.java
index 7deb0ea..faf1098 100644
--- a/src/test/java/org/apache/sling/feature/apiregions/impl/ActivatorTest.java
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/ActivatorTest.java
@@ -133,7 +133,7 @@
     @Test
     public void testUnregisterHook() {
         Activator a = new Activator();
-        a.unregisterHook(); // Should not throw an exception
+        a.unregisterHooks(); // Should not throw an exception
         assertNull(a.hookRegistration);
     }
 
@@ -145,7 +145,7 @@
         Activator a = new Activator();
         a.hookRegistration = reg;
 
-        a.unregisterHook();
+        a.unregisterHooks();
         Mockito.verify(reg).unregister();
         assertNull(a.hookRegistration);
     }