Skip to content

Commit 6294e81

Browse files
default tenant id (#372)
Co-authored-by: Jonathan Lukas <[email protected]>
1 parent 0b3bbc7 commit 6294e81

File tree

10 files changed

+95
-24
lines changed

10 files changed

+95
-24
lines changed

README.md

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ tasklist:
9898
client-secret:
9999
```
100100
101-
Configure defaults that influence the client behaviour:
101+
Configure defaults that influence the client behavior:
102102
103103
```yaml
104104
tasklist:
@@ -107,6 +107,8 @@ tasklist:
107107
load-truncated-variables: true
108108
return-variables: true
109109
use-zeebe-user-tasks: true
110+
tenant-ids:
111+
- <default>
110112
```
111113
112114
### Plain Java
@@ -127,11 +129,11 @@ Build a Camunda Tasklist client with simple authentication:
127129
// properties you need to provide
128130
String username = "demo";
129131
String password = "demo";
130-
URL tasklistUrl = URI
131-
.create("http://localhost:8082").toURL();
132+
URL tasklistUrl = URI.create("http://localhost:8082").toURL();
132133
boolean returnVariables = false;
133134
boolean loadTruncatedVariables = false;
134135
boolean useZeebeUserTasks = true;
136+
List<String> tenantIds = List.of("<default>");
135137
// if you are using zeebe user tasks, you require a zeebe client as well
136138
ZeebeClient zeebeClient = zeebeClient();
137139
// bootstrapping
@@ -140,7 +142,11 @@ SimpleCredential credentials =
140142
SimpleAuthentication authentication = new SimpleAuthentication(credentials);
141143
CamundaTasklistClientConfiguration configuration =
142144
new CamundaTasklistClientConfiguration(
143-
authentication, tasklistUrl, zeebeClient, new DefaultProperties(returnVariables,loadTruncatedVariables,useZeebeUserTasks));
145+
authentication,
146+
tasklistUrl,
147+
zeebeClient,
148+
new DefaultProperties(
149+
returnVariables, loadTruncatedVariables, useZeebeUserTasks, tenantIds));
144150
CamundaTaskListClient client = new CamundaTaskListClient(configuration);
145151
```
146152

@@ -160,16 +166,24 @@ URL authUrl =
160166
boolean returnVariables = false;
161167
boolean loadTruncatedVariables = false;
162168
boolean useZeebeUserTasks = true;
169+
List<String> tenantIds = List.of("<default>");
163170
// if you are using zeebe user tasks, you require a zeebe client as well
164171
ZeebeClient zeebeClient = zeebeClient();
165172
// bootstrapping
166-
JwtCredential credentials = new JwtCredential(clientId, clientSecret, audience, authUrl, scope);
173+
JwtCredential credentials =
174+
new JwtCredential(clientId, clientSecret, audience, authUrl, scope);
167175
ObjectMapper objectMapper = new ObjectMapper();
168-
TokenResponseMapper tokenResponseMapper = new JacksonTokenResponseMapper(objectMapper);
169-
JwtAuthentication authentication = new JwtAuthentication(credentials, tokenResponseMapper);
176+
TokenResponseHttpClientResponseHandler clientResponseHandler =
177+
new TokenResponseHttpClientResponseHandler(objectMapper);
178+
JwtAuthentication authentication = new JwtAuthentication(credentials, clientResponseHandler);
170179
CamundaTasklistClientConfiguration configuration =
171180
new CamundaTasklistClientConfiguration(
172-
authentication, tasklistUrl, zeebeClient, new DefaultProperties(returnVariables,loadTruncatedVariables,useZeebeUserTasks));
181+
authentication,
182+
tasklistUrl,
183+
zeebeClient,
184+
new DefaultProperties(
185+
returnVariables, loadTruncatedVariables, useZeebeUserTasks, tenantIds));
186+
173187
CamundaTaskListClient client = new CamundaTaskListClient(configuration);
174188
```
175189

@@ -184,19 +198,27 @@ String clientSecret = "";
184198
boolean returnVariables = false;
185199
boolean loadTruncatedVariables = false;
186200
boolean useZeebeUserTasks = true;
201+
List<String> tenantIds = List.of("<default>");
187202
// if you are using zeebe user tasks, you require a zeebe client as well
188203
ZeebeClient zeebeClient = zeebeClient();
189204
// bootstrapping
190-
URL tasklistUrl = URI.create("https://" + region + ".tasklist.camunda.io/" + clusterId).toURL();
205+
URL tasklistUrl =
206+
URI.create("https://" + region + ".tasklist.camunda.io/" + clusterId).toURL();
191207
URL authUrl = URI.create("https://login.cloud.camunda.io/oauth/token").toURL();
192208
JwtCredential credentials =
193209
new JwtCredential(clientId, clientSecret, "tasklist.camunda.io", authUrl, null);
194210
ObjectMapper objectMapper = new ObjectMapper();
195-
TokenResponseMapper tokenResponseMapper = new JacksonTokenResponseMapper(objectMapper);
196-
JwtAuthentication authentication = new JwtAuthentication(credentials, tokenResponseMapper);
211+
TokenResponseHttpClientResponseHandler clientResponseHandler =
212+
new TokenResponseHttpClientResponseHandler(objectMapper);
213+
JwtAuthentication authentication = new JwtAuthentication(credentials, clientResponseHandler);
197214
CamundaTasklistClientConfiguration configuration =
198215
new CamundaTasklistClientConfiguration(
199-
authentication, tasklistUrl, zeebeClient, new DefaultProperties(returnVariables,loadTruncatedVariables,useZeebeUserTasks));
216+
authentication,
217+
tasklistUrl,
218+
zeebeClient,
219+
new DefaultProperties(
220+
returnVariables, loadTruncatedVariables, useZeebeUserTasks, tenantIds));
221+
200222
CamundaTaskListClient client = new CamundaTaskListClient(configuration);
201223
```
202224

example/bootstrapping-test/src/main/java/io/camunda/tasklist/bootstrapping/Bootstrapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.camunda.tasklist.bootstrapping;
22

3+
import static io.camunda.tasklist.CamundaTasklistClientConfiguration.DefaultProperties.*;
4+
35
import io.camunda.tasklist.CamundaTaskListClient;
46
import io.camunda.tasklist.CamundaTasklistClientConfiguration;
57
import io.camunda.tasklist.CamundaTasklistClientConfiguration.DefaultProperties;
@@ -22,7 +24,7 @@ public CamundaTaskListClient create() {
2224
Duration.ofMinutes(10))),
2325
URI.create("http://localhost:8082").toURL(),
2426
null,
25-
new DefaultProperties(true, true, false)));
27+
new DefaultProperties(true, true, false, DEFAULT_TENANT_IDS)));
2628
} catch (MalformedURLException e) {
2729
throw new RuntimeException("Error while bootstrapping tasklist client", e);
2830
}

example/readme-snippets/src/main/java/io/camunda/tasklist/example/TasklistClientBootstrapper.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.net.URI;
1515
import java.net.URL;
1616
import java.time.Duration;
17+
import java.util.List;
1718

1819
public interface TasklistClientBootstrapper {
1920
static ZeebeClient zeebeClient() {
@@ -33,6 +34,7 @@ public CamundaTaskListClient createTasklistClient() throws MalformedURLException
3334
boolean returnVariables = false;
3435
boolean loadTruncatedVariables = false;
3536
boolean useZeebeUserTasks = true;
37+
List<String> tenantIds = List.of("<default>");
3638
// if you are using zeebe user tasks, you require a zeebe client as well
3739
ZeebeClient zeebeClient = zeebeClient();
3840
// bootstrapping
@@ -44,7 +46,8 @@ public CamundaTaskListClient createTasklistClient() throws MalformedURLException
4446
authentication,
4547
tasklistUrl,
4648
zeebeClient,
47-
new DefaultProperties(returnVariables, loadTruncatedVariables, useZeebeUserTasks));
49+
new DefaultProperties(
50+
returnVariables, loadTruncatedVariables, useZeebeUserTasks, tenantIds));
4851
CamundaTaskListClient client = new CamundaTaskListClient(configuration);
4952
return client;
5053
}
@@ -66,6 +69,7 @@ public CamundaTaskListClient createTasklistClient() throws MalformedURLException
6669
boolean returnVariables = false;
6770
boolean loadTruncatedVariables = false;
6871
boolean useZeebeUserTasks = true;
72+
List<String> tenantIds = List.of("<default>");
6973
// if you are using zeebe user tasks, you require a zeebe client as well
7074
ZeebeClient zeebeClient = zeebeClient();
7175
// bootstrapping
@@ -80,7 +84,9 @@ public CamundaTaskListClient createTasklistClient() throws MalformedURLException
8084
authentication,
8185
tasklistUrl,
8286
zeebeClient,
83-
new DefaultProperties(returnVariables, loadTruncatedVariables, useZeebeUserTasks));
87+
new DefaultProperties(
88+
returnVariables, loadTruncatedVariables, useZeebeUserTasks, tenantIds));
89+
8490
CamundaTaskListClient client = new CamundaTaskListClient(configuration);
8591
return client;
8692
}
@@ -97,6 +103,7 @@ public CamundaTaskListClient createTasklistClient() throws MalformedURLException
97103
boolean returnVariables = false;
98104
boolean loadTruncatedVariables = false;
99105
boolean useZeebeUserTasks = true;
106+
List<String> tenantIds = List.of("<default>");
100107
// if you are using zeebe user tasks, you require a zeebe client as well
101108
ZeebeClient zeebeClient = zeebeClient();
102109
// bootstrapping
@@ -114,7 +121,9 @@ public CamundaTaskListClient createTasklistClient() throws MalformedURLException
114121
authentication,
115122
tasklistUrl,
116123
zeebeClient,
117-
new DefaultProperties(returnVariables, loadTruncatedVariables, useZeebeUserTasks));
124+
new DefaultProperties(
125+
returnVariables, loadTruncatedVariables, useZeebeUserTasks, tenantIds));
126+
118127
CamundaTaskListClient client = new CamundaTaskListClient(configuration);
119128
return client;
120129
}

extension/client-java/src/main/java/io/camunda/tasklist/CamundaTaskListClient.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public CamundaTaskListClient(
6464
new DefaultProperties(
6565
properties.isDefaultShouldReturnVariables(),
6666
properties.isDefaultShouldLoadTruncatedVariables(),
67-
properties.isUseZeebeUserTasks())));
67+
properties.isUseZeebeUserTasks(),
68+
properties.getTenantIds())));
6869
}
6970

7071
public CamundaTaskListClient(CamundaTasklistClientConfiguration configuration) {
@@ -457,6 +458,9 @@ public TaskList getTasks(TaskSearch search) throws TaskListException {
457458
if (search.getWithVariables() == null) {
458459
search.setWithVariables(defaultProperties.returnVariables());
459460
}
461+
if (search.getTenantIds() == null || search.getTenantIds().isEmpty()) {
462+
search.setTenantIds(defaultProperties.tenantIds());
463+
}
460464
Pagination pagination = search.getPagination();
461465
TaskSearchRequest request = ConverterUtils.toTaskSearchRequest(search);
462466
if (pagination != null) {

extension/client-java/src/main/java/io/camunda/tasklist/CamundaTaskListClientBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.camunda.tasklist;
22

3+
import static io.camunda.tasklist.CamundaTasklistClientConfiguration.*;
4+
35
import com.fasterxml.jackson.databind.ObjectMapper;
46
import io.camunda.tasklist.auth.Authentication;
57
import io.camunda.tasklist.auth.JwtAuthentication;
@@ -43,6 +45,7 @@ public CamundaTaskListClientBuilder shouldReturnVariables() {
4345
}
4446

4547
public CamundaTaskListClientBuilder shouldLoadTruncatedVariables() {
48+
4649
properties.setDefaultShouldLoadTruncatedVariables(true);
4750
return this;
4851
}

extension/client-java/src/main/java/io/camunda/tasklist/CamundaTaskListClientProperties.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package io.camunda.tasklist;
22

3+
import static io.camunda.tasklist.CamundaTasklistClientConfiguration.DefaultProperties.*;
4+
35
import io.camunda.tasklist.auth.Authentication;
6+
import java.util.ArrayList;
7+
import java.util.List;
48

59
@Deprecated
610
public class CamundaTaskListClientProperties {
@@ -10,6 +14,7 @@ public class CamundaTaskListClientProperties {
1014
private boolean defaultShouldReturnVariables;
1115
private boolean defaultShouldLoadTruncatedVariables;
1216
private boolean useZeebeUserTasks;
17+
private List<String> tenantIds = new ArrayList<>(DEFAULT_TENANT_IDS);
1318

1419
public CamundaTaskListClientProperties() {}
1520

@@ -26,6 +31,14 @@ public CamundaTaskListClientProperties(
2631
this.useZeebeUserTasks = useZeebeUserTasks;
2732
}
2833

34+
public List<String> getTenantIds() {
35+
return tenantIds;
36+
}
37+
38+
public void setTenantIds(List<String> tenantIds) {
39+
this.tenantIds = tenantIds;
40+
}
41+
2942
public Authentication getAuthentication() {
3043
return authentication;
3144
}

extension/client-java/src/main/java/io/camunda/tasklist/CamundaTasklistClientConfiguration.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
import io.camunda.tasklist.auth.Authentication;
44
import io.camunda.zeebe.client.ZeebeClient;
55
import java.net.URL;
6+
import java.util.List;
67

78
public record CamundaTasklistClientConfiguration(
89
Authentication authentication,
910
URL baseUrl,
1011
ZeebeClient zeebeClient,
1112
DefaultProperties defaultProperties) {
1213
public record DefaultProperties(
13-
boolean returnVariables, boolean loadTruncatedVariables, boolean useZeebeUserTasks) {}
14+
boolean returnVariables,
15+
boolean loadTruncatedVariables,
16+
boolean useZeebeUserTasks,
17+
List<String> tenantIds) {
18+
public static List<String> DEFAULT_TENANT_IDS = List.of("<default>");
19+
}
1420
}

extension/client-java/src/test/java/io/camunda/tasklist/CamundaTasklistClientTest.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.camunda.tasklist;
22

33
import static com.github.tomakehurst.wiremock.client.WireMock.*;
4+
import static io.camunda.tasklist.CamundaTasklistClientConfiguration.*;
5+
import static io.camunda.tasklist.CamundaTasklistClientConfiguration.DefaultProperties.*;
46
import static org.junit.jupiter.api.Assertions.*;
57

68
import com.auth0.jwt.JWT;
@@ -45,7 +47,10 @@ private static URL baseUrl() {
4547
public void shouldThrowIfZeebeClientNullAndUseZeebeUserTasks() {
4648
CamundaTasklistClientConfiguration configuration =
4749
new CamundaTasklistClientConfiguration(
48-
new MockAuthentication(), baseUrl(), null, new DefaultProperties(false, false, true));
50+
new MockAuthentication(),
51+
baseUrl(),
52+
null,
53+
new DefaultProperties(false, false, true, DEFAULT_TENANT_IDS));
4954
IllegalStateException assertionError =
5055
assertThrows(IllegalStateException.class, () -> new CamundaTaskListClient(configuration));
5156
assertEquals("ZeebeClient is required when using ZeebeUserTasks", assertionError.getMessage());
@@ -55,7 +60,11 @@ public void shouldThrowIfZeebeClientNullAndUseZeebeUserTasks() {
5560
public void shouldNotThrowIfZeebeClientNullAndNotUseZeebeUserTasks() {
5661
CamundaTasklistClientConfiguration configuration =
5762
new CamundaTasklistClientConfiguration(
58-
new MockAuthentication(), baseUrl(), null, new DefaultProperties(false, false, false));
63+
new MockAuthentication(),
64+
baseUrl(),
65+
null,
66+
new DefaultProperties(false, false, false, DEFAULT_TENANT_IDS));
67+
5968
CamundaTaskListClient client = new CamundaTaskListClient(configuration);
6069
assertNotNull(client);
6170
}
@@ -79,7 +88,7 @@ void shouldAuthenticateUsingSimpleAuth() throws MalformedURLException, TaskListE
7988
"demo", "demo", URI.create(BASE_URL).toURL(), Duration.ofMinutes(10))),
8089
baseUrl(),
8190
null,
82-
new DefaultProperties(false, false, false));
91+
new DefaultProperties(false, false, false, DEFAULT_TENANT_IDS));
8392
CamundaTaskListClient client = new CamundaTaskListClient(configuration);
8493
assertNotNull(client);
8594
TaskList tasks = client.getTasks(new TaskSearch());
@@ -113,7 +122,7 @@ void shouldAuthenticateUsingJwt() throws MalformedURLException, TaskListExceptio
113122
new TokenResponseHttpClientResponseHandler(new ObjectMapper())),
114123
baseUrl(),
115124
null,
116-
new DefaultProperties(false, false, false));
125+
new DefaultProperties(false, false, false, DEFAULT_TENANT_IDS));
117126
CamundaTaskListClient client = new CamundaTaskListClient(configuration);
118127
assertNotNull(client);
119128
TaskList tasks = client.getTasks(new TaskSearch());

extension/spring-boot-starter-camunda-tasklist/src/main/java/io/camunda/tasklist/spring/TasklistClientConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public CamundaTasklistClientConfiguration tasklistClientConfiguration(
5050
new DefaultProperties(
5151
properties.defaults().returnVariables(),
5252
properties.defaults().loadTruncatedVariables(),
53-
properties.defaults().useZeebeUserTasks()));
53+
properties.defaults().useZeebeUserTasks(),
54+
properties.defaults().tenantIds()));
5455
}
5556

5657
@Bean

extension/spring-boot-starter-camunda-tasklist/src/main/java/io/camunda/tasklist/spring/TasklistClientConfigurationProperties.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.net.URL;
44
import java.time.Duration;
5+
import java.util.List;
56
import org.springframework.boot.context.properties.ConfigurationProperties;
67
import org.springframework.boot.context.properties.bind.DefaultValue;
78

@@ -34,5 +35,6 @@ public enum Profile {
3435
public record ClientDefaults(
3536
@DefaultValue("true") boolean returnVariables,
3637
@DefaultValue("true") boolean loadTruncatedVariables,
37-
@DefaultValue("true") boolean useZeebeUserTasks) {}
38+
@DefaultValue("true") boolean useZeebeUserTasks,
39+
@DefaultValue("<default>") List<String> tenantIds) {}
3840
}

0 commit comments

Comments
 (0)