@@ -69,6 +69,7 @@ public class AuthenticationProviderMTls implements AuthenticationProvider {
6969 @ VisibleForTesting
7070 private final ConcurrentHashMap <String , ExpressionCompiler > poolMap = new ConcurrentHashMap <>();
7171 private boolean needCloseMetaData = false ;
72+ private AuthenticationMetrics metrics ;
7273
7374 private enum ErrorCode {
7475 UNKNOWN ,
@@ -82,15 +83,29 @@ private enum ErrorCode {
8283 }
8384
8485 @ Override
85- public void initialize (ServiceConfiguration config ) throws IOException {
86- this .metadataStore = createLocalMetadataStore (config );
86+ public void initialize (ServiceConfiguration conf ) throws IOException {
87+ initialize (Context .builder ().config (conf ).build ());
88+ }
89+
90+ @ Override
91+ public void initialize (Context context ) throws IOException {
92+ metrics = new AuthenticationMetrics (
93+ context .getOpenTelemetry (), getClass ().getSimpleName (), "mtls" );
94+ init (context .getConfig ());
95+ }
96+
97+ private void init (ServiceConfiguration conf ) throws MetadataStoreException {
98+ this .metadataStore = createLocalMetadataStore (conf );
8799 this .needCloseMetaData = true ;
88100 this .metadataStore .registerListener (this ::handleMetadataChanges );
89101 this .poolResources = new OIDCPoolResources (metadataStore );
90102 this .loadAsync ();
91103 }
92104
93105 public void initialize (MetadataStore metadataStore ) {
106+ Context context = Context .builder ().build ();
107+ this .metrics = new AuthenticationMetrics (
108+ context .getOpenTelemetry (), getClass ().getSimpleName (), "mtls" );
94109 this .metadataStore = metadataStore ;
95110 this .metadataStore .registerListener (this ::handleMetadataChanges );
96111 this .poolResources = new OIDCPoolResources (metadataStore );
@@ -219,10 +234,10 @@ public String authenticate(AuthenticationDataSource authData) throws Authenticat
219234 errorCode = ErrorCode .NO_MATCH_POOL ;
220235 throw new AuthenticationException ("No matched identity pool from the client certificate" );
221236 }
222- AuthenticationMetrics . authenticateSuccess ( this . getClass (). getSimpleName (), this . getAuthMethodName () );
237+ metrics . recordSuccess ( );
223238 return principal ;
224239 } catch (AuthenticationException e ) {
225- this . incrementFailureMetric (errorCode );
240+ metrics . recordFailure (errorCode );
226241 throw e ;
227242 }
228243 }
0 commit comments