Skip to content

Commit

Permalink
chore: zeebe client auth in saas
Browse files Browse the repository at this point in the history
  • Loading branch information
chillleader committed Dec 5, 2024
1 parent 6b83af4 commit a75b41c
Showing 1 changed file with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

import io.camunda.connector.api.secret.SecretProvider;
import io.camunda.zeebe.client.CredentialsProvider;
import io.camunda.zeebe.client.ZeebeClientConfiguration;
import io.camunda.zeebe.client.api.JsonMapper;
import io.camunda.zeebe.client.impl.oauth.OAuthCredentialsProviderBuilder;
import java.io.IOException;
import io.camunda.zeebe.spring.client.configuration.ZeebeClientConfigurationImpl;
import io.camunda.zeebe.spring.client.jobhandling.ZeebeClientExecutorService;
import io.camunda.zeebe.spring.client.properties.CamundaClientProperties;
import io.camunda.zeebe.spring.client.properties.ZeebeClientConfigurationProperties;
import io.grpc.ClientInterceptor;
import java.util.List;
import org.apache.hc.client5.http.async.AsyncExecChainHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@Configuration
public class ZeebeClientSaaSConfiguration {
Expand All @@ -25,15 +32,47 @@ public ZeebeClientSaaSConfiguration(@Autowired SaaSConfiguration saaSConfigurati
this.internalSecretProvider = saaSConfiguration.getInternalSecretProvider();
}

private static class SaaSZeebeClientConfiguration extends ZeebeClientConfigurationImpl {

private final CredentialsProvider customCredentialsProvider;

public SaaSZeebeClientConfiguration(
ZeebeClientConfigurationProperties properties,
CamundaClientProperties camundaClientProperties,
JsonMapper jsonMapper,
List<ClientInterceptor> interceptors,
List<AsyncExecChainHandler> chainHandlers,
ZeebeClientExecutorService zeebeClientExecutorService,
CredentialsProvider credentialsProvider) {
super(properties, camundaClientProperties, jsonMapper, interceptors, chainHandlers,
zeebeClientExecutorService);
this.customCredentialsProvider = credentialsProvider;
}

@Override
public CredentialsProvider getCredentialsProvider() {
return customCredentialsProvider;
}
}

@Bean
@Primary
public CredentialsProvider credentialsProvider() {
public ZeebeClientConfiguration zeebeClientConfiguration(
final ZeebeClientConfigurationProperties properties,
final CamundaClientProperties camundaClientProperties,
final JsonMapper jsonMapper,
final List<ClientInterceptor> interceptors,
final List<AsyncExecChainHandler> chainHandlers,
final ZeebeClientExecutorService zeebeClientExecutorService) {
return new SaaSZeebeClientConfiguration(properties, camundaClientProperties, jsonMapper,
interceptors, chainHandlers, zeebeClientExecutorService, credentialsProvider());
}

private CredentialsProvider credentialsProvider() {
final var builder = new OAuthCredentialsProviderBuilder();
builder.clientId(internalSecretProvider.getSecret(SECRET_NAME_CLIENT_ID));
builder.clientSecret(internalSecretProvider.getSecret(SECRET_NAME_SECRET));
builder.authorizationServerUrl(operateAuthUrl);
builder.audience("zeebe.dev.ultrawombat.com");
return builder.build();
}

}

0 comments on commit a75b41c

Please sign in to comment.