Skip to content

Commit

Permalink
Merge pull request #2466 from atlanhq/beta-token-metric
Browse files Browse the repository at this point in the history
Add counter for service-account api requests
  • Loading branch information
n5nk authored Nov 14, 2023
2 parents 8efed7c + 965680b commit fc7a366
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_apikey_request_counter").register(MetricUtils.getMeterRegistry()).increment();
try{
KeycloakAuthenticationToken keycloakToken = (KeycloakAuthenticationToken)authentication;
String bearerToken = keycloakToken.getAccount().getKeycloakSecurityContext().getTokenString();
Expand Down

0 comments on commit fc7a366

Please sign in to comment.