From 25ad0113e6b4cc02053a9fa08dec0e1170574713 Mon Sep 17 00:00:00 2001 From: 1nb0und <133918079+1nb0und@users.noreply.github.com> Date: Fri, 15 Dec 2023 17:03:54 -0500 Subject: [PATCH] feat: added auth url and base url as enabling factor (cherry picked from commit 01855728bd1956b4817f2b89dd12a739c2e243dc) --- .../CamundaOperateClientConfiguration.java | 2 ++ .../condition/CamundaOperateClientCondition.java | 12 +++++++----- .../condition/OperateClientCondition.java | 12 +++++++----- ...amundaOperateClientConfigurationProperties.java | 14 +++++++++++++- .../OperateClientConfigurationProperties.java | 2 ++ 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/configuration/CamundaOperateClientConfiguration.java b/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/configuration/CamundaOperateClientConfiguration.java index 2e9eda6da..cfd62e697 100644 --- a/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/configuration/CamundaOperateClientConfiguration.java +++ b/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/configuration/CamundaOperateClientConfiguration.java @@ -8,6 +8,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; @@ -19,6 +20,7 @@ */ @Deprecated @Conditional(CamundaOperateClientCondition.class) +@ConditionalOnProperty(prefix = "camunda.operate.client", name = "enabled", havingValue = "true", matchIfMissing = true) @EnableConfigurationProperties(CamundaOperateClientConfigurationProperties.class) public class CamundaOperateClientConfiguration { diff --git a/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/configuration/condition/CamundaOperateClientCondition.java b/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/configuration/condition/CamundaOperateClientCondition.java index 1f89d6a4c..dca8ee167 100644 --- a/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/configuration/condition/CamundaOperateClientCondition.java +++ b/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/configuration/condition/CamundaOperateClientCondition.java @@ -13,12 +13,14 @@ public CamundaOperateClientCondition() { } @ConditionalOnProperty(name = "camunda.operate.client.client-id") - static class ClientIdCondition { - - } + static class ClientIdCondition { } @ConditionalOnProperty(name = "camunda.operate.client.username") - static class UsernameCondition { + static class UsernameCondition { } - } + @ConditionalOnProperty(name = "camunda.operate.client.auth-url") + static class AuthUrlCondition { } + + @ConditionalOnProperty(name = "camunda.operate.client.base-url") + static class BaseUrlCondition { } } diff --git a/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/configuration/condition/OperateClientCondition.java b/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/configuration/condition/OperateClientCondition.java index 3256c14fd..9bf093ec4 100644 --- a/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/configuration/condition/OperateClientCondition.java +++ b/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/configuration/condition/OperateClientCondition.java @@ -9,12 +9,14 @@ public OperateClientCondition() { } @ConditionalOnProperty(name = "operate.client.client-id") - static class ClientIdCondition { - - } + static class ClientIdCondition { } @ConditionalOnProperty(name = "operate.client.username") - static class UsernameCondition { + static class UsernameCondition { } - } + @ConditionalOnProperty(name = "operate.client.auth-url") + static class AuthUrlCondition { } + + @ConditionalOnProperty(name = "operate.client.base-url") + static class BaseUrlCondition { } } diff --git a/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/properties/CamundaOperateClientConfigurationProperties.java b/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/properties/CamundaOperateClientConfigurationProperties.java index a212e408e..24b885f0c 100644 --- a/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/properties/CamundaOperateClientConfigurationProperties.java +++ b/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/properties/CamundaOperateClientConfigurationProperties.java @@ -1,5 +1,6 @@ package io.camunda.zeebe.spring.client.properties; +import jakarta.annotation.PostConstruct; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -26,7 +27,7 @@ public class CamundaOperateClientConfigurationProperties { private String clientSecret; private String username; private String password; - private Boolean enabled; + private Boolean enabled = false; private String url; private String keycloakUrl; @@ -131,4 +132,15 @@ public String getOperateUrl() { throw new IllegalArgumentException( "In order to connect to Camunda Operate you need to specify either a SaaS clusterId or an Operate URL."); } + + @PostConstruct + private void applyFinalValues() { + if (this.getClientId() != null && this.getClientSecret() != null) { + this.setEnabled(true); + } else if (this.getUsername() != null && this.getPassword() != null) { + this.setEnabled(true); + } else if (this.getAuthUrl() != null || this.getBaseUrl() != null) { + this.setEnabled(true); + } + } } diff --git a/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/properties/OperateClientConfigurationProperties.java b/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/properties/OperateClientConfigurationProperties.java index 003dc5a44..447cd55a3 100644 --- a/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/properties/OperateClientConfigurationProperties.java +++ b/spring-boot-starter-camunda/src/main/java/io/camunda/zeebe/spring/client/properties/OperateClientConfigurationProperties.java @@ -44,6 +44,8 @@ private void applyFinalValues() { this.setEnabled(true); } else if (this.getUsername() != null && this.getPassword() != null) { this.setEnabled(true); + } else if (this.getAuthUrl() != null || this.getBaseUrl() != null) { + this.setEnabled(true); } } }