-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* created working code snippets for manual bootstrapping (#154) * created working code snippets for manual bootstrapping * added missing dependencies (cherry picked from commit 44ebe65) * formatted readme
- Loading branch information
1 parent
56d0419
commit 1f36a72
Showing
5 changed files
with
192 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?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.6.3-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>readme-snippets</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.camunda.spring</groupId> | ||
<artifactId>java-client-operate</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents.client5</groupId> | ||
<artifactId>httpclient5</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
88 changes: 88 additions & 0 deletions
88
...s/readme-snippets/src/main/java/io/camunda/operate/example/OperateClientBootstrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...adme-snippets/src/test/java/io/camunda/operate/example/OperateClientBootstrapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |