This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-auth-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 809e2f5  SLING-10164 : Add basic metrics to SlingAuthenticator
809e2f5 is described below

commit 809e2f59f97f90f62f011aed552f3ab3bac77a5d
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Fri Mar 19 07:39:22 2021 +0100

    SLING-10164 : Add basic metrics to SlingAuthenticator
---
 .gitignore                                         |  1 +
 pom.xml                                            |  4 +--
 .../sling/auth/core/impl/SlingAuthenticator.java   | 35 ++++++++++++----------
 .../auth/core/impl/SlingAuthenticatorOsgiTest.java |  4 +--
 4 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/.gitignore b/.gitignore
index 5b783ed..d4bfe7c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+.vscode
 /target
 .idea
 .classpath
diff --git a/pom.xml b/pom.xml
index dfbfab8..f852f27 100644
--- a/pom.xml
+++ b/pom.xml
@@ -121,7 +121,7 @@
         <dependency>
             <groupId>commons-codec</groupId>
             <artifactId>commons-codec</artifactId>
-            <version>1.4</version>
+            <version>1.13</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
@@ -166,7 +166,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
-            <version>3.0.0</version>
+            <version>3.1.0</version>
             <scope>test</scope>
         </dependency>
     </dependencies>
diff --git 
a/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java 
b/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java
index 5d1a329..d084c77 100644
--- a/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java
+++ b/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java
@@ -73,6 +73,7 @@ import org.osgi.service.component.annotations.Modified;
 import org.osgi.service.component.annotations.Reference;
 import org.osgi.service.component.annotations.ReferenceCardinality;
 import org.osgi.service.component.annotations.ReferencePolicy;
+import org.osgi.service.component.annotations.ReferencePolicyOption;
 import org.osgi.service.component.propertytypes.ServiceDescription;
 import org.osgi.service.component.propertytypes.ServiceVendor;
 import org.osgi.service.event.Event;
@@ -259,10 +260,7 @@ public class SlingAuthenticator implements Authenticator,
      */
     private static final String AUTH_INFO_PROP_FEEDBACK_HANDLER = 
"$$sling.auth.AuthenticationFeedbackHandler$$";
 
-    @Reference
-    private ResourceResolverFactory resourceResolverFactory;
-
-    private PathBasedHolderCache<AbstractAuthenticationHandlerHolder> 
authHandlerCache = new 
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>();
+    private final PathBasedHolderCache<AbstractAuthenticationHandlerHolder> 
authHandlerCache = new 
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>();
 
     // package protected for access in inner class ...
     private final PathBasedHolderCache<AuthenticationRequirementHolder> 
authRequiredCache = new PathBasedHolderCache<AuthenticationRequirementHolder>();
@@ -332,18 +330,22 @@ public class SlingAuthenticator implements Authenticator,
     /**
      * The event admin service.
      */
-    @Reference(policy=ReferencePolicy.DYNAMIC, cardinality = 
ReferenceCardinality.OPTIONAL)
+    @Reference(policy=ReferencePolicy.DYNAMIC, cardinality = 
ReferenceCardinality.OPTIONAL, policyOption = ReferencePolicyOption.GREEDY)
     private volatile EventAdmin eventAdmin;
 
-    @Reference
-    private MetricsService metricsService;
-    private SlingAuthenticationMetrics metrics;
+    private final SlingAuthenticationMetrics metrics;
+
+    private final ResourceResolverFactory resourceResolverFactory;
 
     // ---------- SCR integration
 
     @Activate
-    private void activate(final BundleContext bundleContext,
+    public SlingAuthenticator(@Reference(policyOption = 
ReferencePolicyOption.GREEDY) final MetricsService metricsService,
+            @Reference(policyOption = ReferencePolicyOption.GREEDY) final 
ResourceResolverFactory resourceResolverFactory,
+            final BundleContext bundleContext,
             final Config config) {
+        this.metrics = new SlingAuthenticationMetrics(metricsService);
+        this.resourceResolverFactory = resourceResolverFactory;
         modified(config);
 
         AuthenticatorWebConsolePlugin plugin = new 
AuthenticatorWebConsolePlugin(
@@ -369,10 +371,16 @@ public class SlingAuthenticator implements Authenticator,
             bundleContext, authHandlerCache);
         authInfoPostProcessorTracker = new ServiceTracker(bundleContext, 
AuthenticationInfoPostProcessor.class, null);
         authInfoPostProcessorTracker.open();
-
-        metrics = new SlingAuthenticationMetrics(metricsService);
     }
 
+    /**
+     * Constructor for unit tests
+     */
+    SlingAuthenticator() {
+        this.resourceResolverFactory = null;
+        this.metrics = null;
+    }
+    
     @Modified
     private void modified(Config config) {
         String newCookie = config.auth_sudo_cookie();
@@ -465,11 +473,6 @@ public class SlingAuthenticator implements Authenticator,
             webConsolePlugin.unregister();
             webConsolePlugin = null;
         }
-
-        metricsService = null;
-        if (metrics != null) {
-            metrics = null;
-        }
     }
 
     // --------- AuthenticationSupport interface
diff --git 
a/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorOsgiTest.java 
b/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorOsgiTest.java
index 588337e..5777107 100644
--- 
a/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorOsgiTest.java
+++ 
b/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorOsgiTest.java
@@ -51,7 +51,7 @@ public class SlingAuthenticatorOsgiTest {
     private Timer timer = mock(Timer.class);
     private final MetricsService metricsService = mock(MetricsService.class);
 
-    private final SlingAuthenticator authenticator = new SlingAuthenticator();
+    private SlingAuthenticator authenticator;
 
     @Before
     public void before() throws Exception {
@@ -66,7 +66,7 @@ public class SlingAuthenticatorOsgiTest {
 
         context.registerService(ResourceResolverFactory.class, 
resourceResolverFactory);
         context.registerService(MetricsService.class, metricsService);
-        context.registerInjectActivateService(authenticator);
+        authenticator = 
context.registerInjectActivateService(SlingAuthenticator.class);
     }
 
     @Test

Reply via email to