[java-identity-provider] 01/01: IDP-2272 Expose LDAP metrics

Rod Widdowson rdw at steadingsoftware.com
Tue Apr 8 14:16:08 UTC 2025


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch dev/IDP-2272
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=01b2175f1f873f87ecea6836264cfc67ced4dec8

commit 01b2175f1f873f87ecea6836264cfc67ced4dec8
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Apr 1 11:19:47 2025 +0100

    IDP-2272 Expose LDAP metrics
    
    https://shibboleth.atlassian.net/browse/IDP-2272
    
    Wire the accumulator into the credential validator.
    Add the gaugeset and make it available to the metrics bean
---
 .../idp/authn/impl/LDAPCredentialValidator.java    | 13 ++++-
 .../net/shibboleth/idp/conf/metrics-system.xml     |  6 +++
 .../shibboleth/idp/metrics/impl/LDAPGaugeSet.java  | 61 ++++++++++++++++++++++
 3 files changed, 79 insertions(+), 1 deletion(-)

diff --git a/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/LDAPCredentialValidator.java b/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/LDAPCredentialValidator.java
index 4d75219f1..af9142637 100644
--- a/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/LDAPCredentialValidator.java
+++ b/idp-authn-impl/src/main/java/net/shibboleth/idp/authn/impl/LDAPCredentialValidator.java
@@ -33,6 +33,7 @@ import org.ldaptive.auth.User;
 import org.ldaptive.jaas.LdapPrincipal;
 import org.opensaml.profile.context.ProfileRequestContext;
 import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import net.shibboleth.idp.authn.AbstractUsernamePasswordCredentialValidator;
 import net.shibboleth.idp.authn.AuthnEventIds;
@@ -43,6 +44,7 @@ import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.shared.annotation.constraint.ThreadSafeAfterInit;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.metrics.LDAPMetricAccumulator;
 import net.shibboleth.shared.primitive.LoggerFactory;
 
 /**
@@ -64,7 +66,10 @@ public class LDAPCredentialValidator extends AbstractUsernamePasswordCredentialV
     
     /** Optional strategy for obtaining/transforming the password. */
     @Nullable private Function<ProfileRequestContext,char[]> passwordLookupStrategy;
-    
+
+    /** Optional Accumulator for Ldaptive events. */
+    @Autowired @Nullable private LDAPMetricAccumulator metricAccumulator;
+
     /**
      * Returns the authenticator.
      * 
@@ -121,6 +126,9 @@ public class LDAPCredentialValidator extends AbstractUsernamePasswordCredentialV
         if (authenticator == null) {
             throw new ComponentInitializationException("Authenticator cannot be null");
         }
+        if (metricAccumulator != null) {
+            metricAccumulator.incrementEventOne();
+        }
     }
 
     /** {@inheritDoc} */
@@ -185,6 +193,9 @@ public class LDAPCredentialValidator extends AbstractUsernamePasswordCredentialV
                       AuthnEventIds.ACCOUNT_WARNING);
                 }
             }
+            if (metricAccumulator != null) {
+                metricAccumulator.incrementEventThree();
+            }
             return populateSubject(usernamePasswordContext, response);
         }
 
diff --git a/idp-conf-impl/src/main/resources/net/shibboleth/idp/conf/metrics-system.xml b/idp-conf-impl/src/main/resources/net/shibboleth/idp/conf/metrics-system.xml
index 86884e7c5..a64883de2 100644
--- a/idp-conf-impl/src/main/resources/net/shibboleth/idp/conf/metrics-system.xml
+++ b/idp-conf-impl/src/main/resources/net/shibboleth/idp/conf/metrics-system.xml
@@ -77,6 +77,12 @@
     
     <bean id="shibboleth.metrics.ModuleGaugeSet" class="net.shibboleth.idp.module.impl.ModuleGaugeSet" lazy-init="true" />
     
+    <bean id="shibboleth.metrics.LdapAccumulator" class="net.shibboleth.shared.metrics.LDAPMetricAccumulator" lazy-init="true" />
+
+    <bean id="shibboleth.metrics.LDAPGaugeSet" class="net.shibboleth.idp.metrics.impl.LDAPGaugeSet" lazy-init="true"
+        c:_0-ref="shibboleth.metrics.LdapAccumulator" />
+
+
     <bean id="shibboleth.metrics.IdPGaugeSet" class="net.shibboleth.idp.metrics.impl.IdPGaugeSet" lazy-init="true"
         p:exposedProperties="#{getObject('shibboleth.metrics.ExposedProperties')}" />
 
diff --git a/idp-core/src/main/java/net/shibboleth/idp/metrics/impl/LDAPGaugeSet.java b/idp-core/src/main/java/net/shibboleth/idp/metrics/impl/LDAPGaugeSet.java
new file mode 100644
index 000000000..ff37ccc40
--- /dev/null
+++ b/idp-core/src/main/java/net/shibboleth/idp/metrics/impl/LDAPGaugeSet.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.shibboleth.idp.metrics.impl;
+
+import java.util.Map;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import com.codahale.metrics.Gauge;
+import com.codahale.metrics.Metric;
+import com.codahale.metrics.MetricFilter;
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.MetricSet;
+
+import net.shibboleth.shared.annotation.constraint.NotEmpty;
+import net.shibboleth.shared.collection.CollectionSupport;
+import net.shibboleth.shared.metrics.LDAPMetricAccumulator;
+
+/** Prototype GuageSet for interrogating LDAPTive Event counts. */
+public class LDAPGaugeSet  implements MetricSet, MetricFilter {
+
+    /** Default prefix for metrics. */
+    @Nonnull @NotEmpty private static final String DEFAULT_METRIC_NAME = "net.shibboleth.idp.ldap";
+
+    /** The map of gauges. */
+    @Nonnull private final Map<String,Metric> gauges;
+
+    /** Constructor. */
+    public LDAPGaugeSet(@Nullable LDAPMetricAccumulator metricAccumulator) {
+		gauges = CollectionSupport.singletonMap(MetricRegistry.name(DEFAULT_METRIC_NAME),
+                new Gauge<LDAPMetricAccumulator>() {
+                    public LDAPMetricAccumulator getValue() {
+                        return metricAccumulator;
+                    }
+                });
+	}
+
+    /** {@inheritDoc} */
+    @Override
+    public Map<String, Metric> getMetrics() {
+        return gauges;
+    }
+
+    /** {@inheritDoc} */
+    public boolean matches(final String name, final Metric metric) {
+        return gauges.containsKey(name);
+    }
+
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list