From e209bd7c9e8d6d0e01bfe28eedf49b93506993af Mon Sep 17 00:00:00 2001 From: ektavarma10 Date: Tue, 14 Nov 2023 12:54:25 +0530 Subject: [PATCH 1/2] Add counter for service-account api requests --- .../web/security/AtlasKeycloakAuthenticationProvider.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/webapp/src/main/java/org/apache/atlas/web/security/AtlasKeycloakAuthenticationProvider.java b/webapp/src/main/java/org/apache/atlas/web/security/AtlasKeycloakAuthenticationProvider.java index acafc5bc19..71623d3f85 100644 --- a/webapp/src/main/java/org/apache/atlas/web/security/AtlasKeycloakAuthenticationProvider.java +++ b/webapp/src/main/java/org/apache/atlas/web/security/AtlasKeycloakAuthenticationProvider.java @@ -16,8 +16,10 @@ */ package org.apache.atlas.web.security; +import io.micrometer.core.instrument.Counter; import org.apache.atlas.ApplicationProperties; import org.apache.atlas.keycloak.client.AtlasKeycloakClient; +import org.apache.atlas.service.metrics.MetricUtils; import org.apache.commons.configuration.Configuration; import org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationProvider; import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken; @@ -75,8 +77,10 @@ public Authentication authenticate(Authentication authentication) { authentication = new KeycloakAuthenticationToken(token.getAccount(), token.isInteractive(), grantedAuthorities); } } - if(authentication.getName().startsWith("service-account")) { + if(authentication.getName().startsWith("service-account-apikey")) { LOG.info("Validating request for clientId: {}", authentication.getName().substring("service-account-".length())); + + Counter.builder("service_account_api_request_counter").register(MetricUtils.getMeterRegistry()).increment(); try{ KeycloakAuthenticationToken keycloakToken = (KeycloakAuthenticationToken)authentication; String bearerToken = keycloakToken.getAccount().getKeycloakSecurityContext().getTokenString(); From 965680b01666d5febb12e800e60b496a4b051735 Mon Sep 17 00:00:00 2001 From: ektavarma10 Date: Tue, 14 Nov 2023 13:18:03 +0530 Subject: [PATCH 2/2] Rename counter to service_account_apikey_request_counter --- .../atlas/web/security/AtlasKeycloakAuthenticationProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/src/main/java/org/apache/atlas/web/security/AtlasKeycloakAuthenticationProvider.java b/webapp/src/main/java/org/apache/atlas/web/security/AtlasKeycloakAuthenticationProvider.java index 71623d3f85..6414079214 100644 --- a/webapp/src/main/java/org/apache/atlas/web/security/AtlasKeycloakAuthenticationProvider.java +++ b/webapp/src/main/java/org/apache/atlas/web/security/AtlasKeycloakAuthenticationProvider.java @@ -80,7 +80,7 @@ public Authentication authenticate(Authentication authentication) { if(authentication.getName().startsWith("service-account-apikey")) { LOG.info("Validating request for clientId: {}", authentication.getName().substring("service-account-".length())); - Counter.builder("service_account_api_request_counter").register(MetricUtils.getMeterRegistry()).increment(); + Counter.builder("service_account_apikey_request_counter").register(MetricUtils.getMeterRegistry()).increment(); try{ KeycloakAuthenticationToken keycloakToken = (KeycloakAuthenticationToken)authentication; String bearerToken = keycloakToken.getAccount().getKeycloakSecurityContext().getTokenString();