rishabhdaim commented on code in PR #2936:
URL: https://github.com/apache/jackrabbit-oak/pull/2936#discussion_r3369602027


##########
oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/ExternalLoginModuleFactory.java:
##########
@@ -149,18 +153,29 @@ public ExternalLoginModuleFactory(
         this.syncManager = syncManager;
         this.idpManager = idpManager;
 
+        // TODO: context cannot be null, but tests are invoked with this being 
null. Tests should
+        // be adjusted accordingly, and then all these implicit and explicit 
null checks should be removed. 
         this.osgiConfig = Optional.ofNullable(context)
                 .map(ctx -> ConfigurationParameters.of(ctx.getProperties()))
                 .orElse(ConfigurationParameters.EMPTY);
         this.bundleContext = 
Optional.ofNullable(context).map(ComponentContext::getBundleContext).orElse(null);
 
+        if (this.bundleContext != null) {
+            monitorTracker = new ServiceTracker<>(this.bundleContext, 
ExternalIdentityMonitor.class, null);
+            monitorTracker.open();
+        }
+
         mayRegisterSyncMBean();
     }
 
     @SuppressWarnings("UnusedDeclaration")
     @Deactivate
     private void deactivate() {
         unregisterSyncMBean();
+        if (monitorTracker != null) {

Review Comment:
   This PR adds `monitorTracker.close()` in `deactivate()`, but no test asserts 
the tracker is cleaned up. `oak-auth-external` requires 100% test coverage for 
security modules.
   
   Extend an existing factory deactivate test (or add one) to verify 
`monitorTracker` is closed/nulled after `MockOsgi.deactivate(factory, 
context.bundleContext())`.



##########
oak-auth-external/src/test/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/ExternalLoginModuleFactoryTest.java:
##########
@@ -213,6 +214,32 @@ public void testMBeanRegistrationAlreadyPresent() throws 
Exception {
         assertSame(mbeanregistration, getMBeanRegistration());
     }
 
+    @Test
+    public void testCreateLoginModuleInjectsMonitor() {
+        ExternalIdentityMonitor monitor = mock(ExternalIdentityMonitor.class);
+        context.registerService(ExternalIdentityMonitor.class, monitor);
+        context.registerService(SyncManager.class, mock(SyncManager.class));
+        context.registerService(ExternalIdentityProviderManager.class, 
mock(ExternalIdentityProviderManager.class));
+
+        ExternalLoginModuleFactory factory = 
context.registerInjectActivateService(ExternalLoginModuleFactory.class);
+        ExternalLoginModule lm = (ExternalLoginModule) 
factory.createLoginModule();
+
+        // The monitor must be pre-injected so that initialize() does not open 
a
+        // ServiceTracker on every login (which causes Felix EventDispatcher 
contention).
+        assertSame(monitor, lm.getMonitor());
+    }
+
+    @Test
+    public void testCreateLoginModuleNullBundleContextNoMonitor() {

Review Comment:
   `testCreateLoginModuleNullBundleContextNoMonitor` only checks `getMonitor()` 
is null immediately after `createLoginModule()`; it never calls `initialize()`.
   
   The comment says the monitor falls back to whiteboard lookup, but that 
branch (`if (monitor == null) { WhiteboardUtils.getService(...) }` plus NOOP) 
is untested. Add cases that call `initialize()` and assert the monitor comes 
from the whiteboard service or `ExternalIdentityMonitor.NOOP`.



##########
oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/ExternalLoginModuleFactory.java:
##########
@@ -149,18 +153,29 @@ public ExternalLoginModuleFactory(
         this.syncManager = syncManager;
         this.idpManager = idpManager;
 
+        // TODO: context cannot be null, but tests are invoked with this being 
null. Tests should
+        // be adjusted accordingly, and then all these implicit and explicit 
null checks should be removed. 
         this.osgiConfig = Optional.ofNullable(context)
                 .map(ctx -> ConfigurationParameters.of(ctx.getProperties()))
                 .orElse(ConfigurationParameters.EMPTY);
         this.bundleContext = 
Optional.ofNullable(context).map(ComponentContext::getBundleContext).orElse(null);
 
+        if (this.bundleContext != null) {
+            monitorTracker = new ServiceTracker<>(this.bundleContext, 
ExternalIdentityMonitor.class, null);

Review Comment:
   Optional: `idpManager` and `syncManager` are injected via SCR `@Reference` 
on the factory constructor, while the monitor uses a manual `ServiceTracker` 
with separate activate/deactivate lifecycle.
   
   Consider `@Reference(name = "monitor", cardinality = OPTIONAL, policy = 
DYNAMIC)` bind/unbind for `ExternalIdentityMonitor` to match the existing 
factory wiring style.



##########
oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/ExternalLoginModuleFactory.java:
##########
@@ -245,6 +260,11 @@ public LoginModule createLoginModule() {
         ExternalLoginModule lm = new ExternalLoginModule(osgiConfig);
         lm.setIdpManager(idpManager);
         lm.setSyncManager(syncManager);
+        // TODO: the monitorTracker cannot be null either (see the TODO in the 
c'tor)
+        ExternalIdentityMonitor monitor = monitorTracker != null ? 
monitorTracker.getService() : null;
+        if (monitor != null) {
+            lm.setMonitor(monitor);
+        }
         return lm;
     }

Review Comment:
   Optional: this file is missing the trailing newline at EOF.



##########
oak-auth-external/src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/external/impl/ExternalLoginModuleFactory.java:
##########
@@ -29,6 +29,8 @@
 import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
 import 
org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityProviderManager;
 import 
org.apache.jackrabbit.oak.spi.security.authentication.external.SyncManager;
+import 
org.apache.jackrabbit.oak.spi.security.authentication.external.impl.monitor.ExternalIdentityMonitor;
+import org.osgi.util.tracker.ServiceTracker;

Review Comment:
   Optional: `org.osgi.util.tracker.ServiceTracker` sits between Oak security 
imports; group it with the other `org.osgi` imports below.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to