Skip to content

Commit

Permalink
Add counter for service-account api requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ektavarma10 committed Nov 14, 2023
1 parent 8efed7c commit e209bd7
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit e209bd7

Please sign in to comment.