Skip to content

Commit

Permalink
created working code snippets for manual bootstrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlukas committed Dec 6, 2024
1 parent 6e18f4d commit e1f3662
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 21 deletions.
38 changes: 28 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ operate:
client-secret:
```
To adjust the (meaningful) default properties, you can also override them:
```yaml
operate:
client:
Expand Down Expand Up @@ -110,12 +112,17 @@ Build a Camunda Operate client with simple authentication:

```java
// properties you need to provide
String username = "demo";
String password = "demo";
URL operateUrl = URI.create("http://localhost:8081").toURL();
SimpleCredential credentials = new SimpleCredential("demo", "demo", operateUrl, Duration.ofMinutes(10));
// bootstrapping
SimpleCredential credentials =
new SimpleCredential(username, password, operateUrl, Duration.ofMinutes(10));
SimpleAuthentication authentication = new SimpleAuthentication(credentials);
ObjectMapper objectMapper = new ObjectMapper();
CamundaOperateClientConfiguration configuration = new CamundaOperateClientConfiguration(authentication, operateUrl, objectMapper, HttpClients.createDefault());
CamundaOperateClientConfiguration configuration =
new CamundaOperateClientConfiguration(
authentication, operateUrl, objectMapper, HttpClients.createDefault());
CamundaOperateClient client = new CamundaOperateClient(configuration);
```

Expand All @@ -128,29 +135,40 @@ String clientSecret = "";
String audience = "operate-api";
String scope = ""; // can be omitted if not required
URL operateUrl = URI.create("http://localhost:8081").toURL();
URL authUrl = URI.create("http://localhost:18080/auth/realms/camunda-platform/protocol/openid-connect/token");
URL authUrl =
URI.create(
"http://localhost:18080/auth/realms/camunda-platform/protocol/openid-connect/token")
.toURL();
// bootstrapping
JwtCredential credentials = new JwtCredential(clientId, clientSecret, audience, authUrl, scope);
ObjectMapper objectMapper = new ObjectMapper();
JwtAuthentication authentication = new JwtAuthentication(credentials, objectMapper);
CamundaOperateClientConfiguration configuration = new CamundaOperateClientConfiguration(authentication, operateUrl, objectMapper, HttpClients.createDefault());
TokenResponseMapper tokenResponseMapper = new JacksonTokenResponseMapper(objectMapper);
JwtAuthentication authentication = new JwtAuthentication(credentials, tokenResponseMapper);
CamundaOperateClientConfiguration configuration =
new CamundaOperateClientConfiguration(
authentication, operateUrl, objectMapper, HttpClients.createDefault());
CamundaOperateClient client = new CamundaOperateClient(configuration);
```

Build a Camunda Operate client for Saas:

```java
// properties you need to provide
String region = "";
String clusterId = "";
String clientId = "";
String clientSecret = "";
// bootstrapping
URL operateUrl = URI.create("https://"+ region +".operate.camunda.io/" + clusterId).toURL();
URL authUrl = URI.create("https://login.cloud.camunda.io/oauth/token");
JwtCredential credentials = new JwtCredential(clientId, clientSecret, "operate.camunda.io", authUrl, null);
URL operateUrl = URI.create("https://" + region + ".operate.camunda.io/" + clusterId).toURL();
URL authUrl = URI.create("https://login.cloud.camunda.io/oauth/token").toURL();
JwtCredential credentials =
new JwtCredential(clientId, clientSecret, "operate.camunda.io", authUrl, null);
ObjectMapper objectMapper = new ObjectMapper();
JwtAuthentication authentication = new JwtAuthentication(credentials, objectMapper);
CamundaOperateClientConfiguration configuration = new CamundaOperateClientConfiguration(authentication, operateUrl, objectMapper, HttpClients.createDefault());
TokenResponseMapper tokenResponseMapper = new JacksonTokenResponseMapper(objectMapper);
JwtAuthentication authentication = new JwtAuthentication(credentials, tokenResponseMapper);
CamundaOperateClientConfiguration configuration =
new CamundaOperateClientConfiguration(
authentication, operateUrl, objectMapper, HttpClients.createDefault());
CamundaOperateClient client = new CamundaOperateClient(configuration);
```

Expand Down
1 change: 1 addition & 0 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<packaging>pom</packaging>
<modules>
<module>operate-example-load-process-instance</module>
<module>readme-snippets</module>
</modules>

</project>
31 changes: 31 additions & 0 deletions examples/readme-snippets/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.camunda.spring</groupId>
<artifactId>operate-examples-parent</artifactId>
<version>8.7.0-SNAPSHOT</version>
</parent>

<artifactId>readme-snippets</artifactId>

<dependencies>
<dependency>
<groupId>io.camunda.spring</groupId>
<artifactId>java-client-operate</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package io.camunda.operate.example;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.camunda.operate.CamundaOperateClient;
import io.camunda.operate.CamundaOperateClientConfiguration;
import io.camunda.operate.auth.JwtAuthentication;
import io.camunda.operate.auth.JwtCredential;
import io.camunda.operate.auth.SimpleAuthentication;
import io.camunda.operate.auth.SimpleCredential;
import io.camunda.operate.auth.TokenResponseMapper;
import io.camunda.operate.auth.TokenResponseMapper.JacksonTokenResponseMapper;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.time.Duration;
import org.apache.hc.client5.http.impl.classic.HttpClients;

public interface OperateClientBootstrapper {
CamundaOperateClient createOperateClient() throws MalformedURLException;

class SimpleAuthOperateClientBootstrapper implements OperateClientBootstrapper {
public CamundaOperateClient createOperateClient() throws MalformedURLException {
// properties you need to provide
String username = "demo";
String password = "demo";
URL operateUrl = URI.create("http://localhost:8081").toURL();
// bootstrapping
SimpleCredential credentials =
new SimpleCredential(username, password, operateUrl, Duration.ofMinutes(10));
SimpleAuthentication authentication = new SimpleAuthentication(credentials);
ObjectMapper objectMapper = new ObjectMapper();
CamundaOperateClientConfiguration configuration =
new CamundaOperateClientConfiguration(
authentication, operateUrl, objectMapper, HttpClients.createDefault());
CamundaOperateClient client = new CamundaOperateClient(configuration);
return client;
}
}

class IdentityAuthOperateClientBootstrapper implements OperateClientBootstrapper {
public CamundaOperateClient createOperateClient() throws MalformedURLException {
// properties you need to provide
String clientId = "";
String clientSecret = "";
String audience = "operate-api";
String scope = ""; // can be omitted if not required
URL operateUrl = URI.create("http://localhost:8081").toURL();
URL authUrl =
URI.create(
"http://localhost:18080/auth/realms/camunda-platform/protocol/openid-connect/token")
.toURL();
// bootstrapping
JwtCredential credentials =
new JwtCredential(clientId, clientSecret, audience, authUrl, scope);
ObjectMapper objectMapper = new ObjectMapper();
TokenResponseMapper tokenResponseMapper = new JacksonTokenResponseMapper(objectMapper);
JwtAuthentication authentication = new JwtAuthentication(credentials, tokenResponseMapper);
CamundaOperateClientConfiguration configuration =
new CamundaOperateClientConfiguration(
authentication, operateUrl, objectMapper, HttpClients.createDefault());
CamundaOperateClient client = new CamundaOperateClient(configuration);
return client;
}
}

class SaasClientBootstrapper implements OperateClientBootstrapper {
public CamundaOperateClient createOperateClient() throws MalformedURLException {
// properties you need to provide
String region = "";
String clusterId = "";
String clientId = "";
String clientSecret = "";
// bootstrapping
URL operateUrl = URI.create("https://" + region + ".operate.camunda.io/" + clusterId).toURL();
URL authUrl = URI.create("https://login.cloud.camunda.io/oauth/token").toURL();
JwtCredential credentials =
new JwtCredential(clientId, clientSecret, "operate.camunda.io", authUrl, null);
ObjectMapper objectMapper = new ObjectMapper();
TokenResponseMapper tokenResponseMapper = new JacksonTokenResponseMapper(objectMapper);
JwtAuthentication authentication = new JwtAuthentication(credentials, tokenResponseMapper);
CamundaOperateClientConfiguration configuration =
new CamundaOperateClientConfiguration(
authentication, operateUrl, objectMapper, HttpClients.createDefault());
CamundaOperateClient client = new CamundaOperateClient(configuration);
return client;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.camunda.operate.example;

import static org.assertj.core.api.Assertions.*;

import io.camunda.operate.CamundaOperateClient;
import io.camunda.operate.example.OperateClientBootstrapper.IdentityAuthOperateClientBootstrapper;
import io.camunda.operate.example.OperateClientBootstrapper.SaasClientBootstrapper;
import io.camunda.operate.example.OperateClientBootstrapper.SimpleAuthOperateClientBootstrapper;
import java.net.MalformedURLException;
import org.junit.jupiter.api.Test;

public class OperateClientBootstrapperTest {
@Test
void shouldBootstrapSimpleAuthClient() throws MalformedURLException {
OperateClientBootstrapper bootstrapper = new SimpleAuthOperateClientBootstrapper();
CamundaOperateClient client = bootstrapper.createOperateClient();
assertThat(client).isNotNull();
}

@Test
void shouldBootstrapIdentityAuthClient() throws MalformedURLException {
OperateClientBootstrapper bootstrapper = new IdentityAuthOperateClientBootstrapper();
CamundaOperateClient client = bootstrapper.createOperateClient();
assertThat(client).isNotNull();
}

@Test
void shouldBootstrapSaasClient() throws MalformedURLException {
OperateClientBootstrapper bootstrapper = new SaasClientBootstrapper();
CamundaOperateClient client = bootstrapper.createOperateClient();
assertThat(client).isNotNull();
}
}
4 changes: 0 additions & 4 deletions extension/java-client-operate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.camunda</groupId>
Expand All @@ -26,7 +25,6 @@
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand All @@ -35,12 +33,10 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
7 changes: 0 additions & 7 deletions extension/spring-boot-starter-camunda-operate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,30 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.camunda.spring</groupId>
Expand Down

0 comments on commit e1f3662

Please sign in to comment.