Skip to content

Commit

Permalink
Code cleaning and upgrade tasklist and operate clients to manage toke…
Browse files Browse the repository at this point in the history
…n expiration
  • Loading branch information
chDame committed Aug 3, 2022
1 parent 4b8bc18 commit 7d3007e
Show file tree
Hide file tree
Showing 45 changed files with 1,062 additions and 623 deletions.
15 changes: 10 additions & 5 deletions documentation/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# Process Solution Template for Camunda Platform 8 using Keycloak, Java and Spring Boot

## Directory Server
To run it locally, you'll need a Directory Server and a Camunda 8 platform.
If you don't have a Directory Server, you can follow the documentation enclosed in LocalDirectoryServer.docx and import the sailors.LDIF file.

## Camunda 8 platform
If you don't have a Camunda 8 platform, you can use the Camunda provided docker-compose file : https://raw.githubusercontent.com/camunda/camunda-platform/d7848cc66f4dee79ee1ea73efa7eb9684c2dc748/docker-compose.yaml

Then you'll need to federate the Directory users in your Keycloak (follow the WorkshopSupport.docx documentation)
To have some "Admin" users, you'll need to configure them manually in Keycloak. To do so, connect to Keycloak as an Admin
localhost:18080 (admin:admin)
## A few configurations

* Then you'll need to federate the Directory users in your Keycloak (follow the WorkshopSupport.docx documentation)

* To have some "Admin" users allowed to access **http://localhost:8080/admin/index.html**, you'll need to configure them manually in Keycloak. To do so, connect to Keycloak as an Admin
localhost:18080 (admin:admin)
Navigate to Roles and create an "Admin" role.
Navigate to Users and assign the "Admin" role to someone (for example "Demo").
**Be careful, if you use demo as a normal user, you should provide him an email in Keycloak**

This user will then be able to access http://localhost:8080/amdin/index.html
* If you want to send mails or store documents in drive, you'll need to add a **client_secret_google_api.json** in your resources folder. This can be done from https://console.cloud.google.com/apis/credentials

If you want to send mails or store documents in drive, you'll need to add a client_secret_google_api.json in your resources folder. This can be done from https://console.cloud.google.com/apis/credentials
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<dependency>
<groupId>io.camunda</groupId>
<artifactId>camunda-tasklist-client-java</artifactId>
<version>1.3.1</version>
<version>1.4.0</version>
</dependency>

<dependency>
Expand All @@ -72,7 +72,7 @@
<dependency>
<groupId>io.camunda</groupId>
<artifactId>camunda-operate-client-java</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
</dependency>

<!-- gmail, drive, thymeleaf & feel -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.example.camunda.process.solution;

import io.camunda.zeebe.spring.client.EnableZeebeClient;
import io.camunda.zeebe.spring.client.annotation.ZeebeDeployment;
import org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import io.camunda.zeebe.spring.client.EnableZeebeClient;
import io.camunda.zeebe.spring.client.annotation.ZeebeDeployment;

@SpringBootApplication
@EnableZeebeClient
@ZeebeDeployment(resources = "classpath*:/models/*.*")
Expand All @@ -16,9 +15,9 @@ public class ProcessApplication {
public static void main(String[] args) {
SpringApplication.run(ProcessApplication.class, args);
}

@Bean
public KeycloakSpringBootConfigResolver keycloakConfigResolver() {
return new KeycloakSpringBootConfigResolver();
return new KeycloakSpringBootConfigResolver();
}
}
187 changes: 114 additions & 73 deletions src/main/java/org/example/camunda/process/solution/ProcessVariables.java
Original file line number Diff line number Diff line change
@@ -1,86 +1,127 @@
package org.example.camunda.process.solution;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

@JsonInclude(Include.NON_NULL)
public class ProcessVariables {

private String intialMessage;
private String assignee1;
private String assignee2;
private List<Map<String, String>> comments;
private Map<String, Object> file;
private String date;

public String getIntialMessage() {
return intialMessage;
}

public void setIntialMessage(String intialMessage) {
this.intialMessage = intialMessage;
}

public String getAssignee1() {
return assignee1;
}

public ProcessVariables setAssignee1(String assignee1) {
this.assignee1 = assignee1;
return this;
}

public String getAssignee2() {
return assignee2;
}

public ProcessVariables setAssignee2(String assignee2) {
this.assignee2 = assignee2;
return this;
}

public List<Map<String, String>> getComments() {
return comments;
}

public ProcessVariables setComments(List<Map<String, String>> comments) {
this.comments = comments;
return this;
}

public Map<String, Object> getFile() {
return file;
}

public ProcessVariables setFile(Map<String, Object> file) {
this.file = file;
return this;
}

public String getDate() {
return date;
}

public ProcessVariables setDate(String date) {
this.date = date;
return this;
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, new MultilineRecursiveToStringStyle() {
public ToStringStyle withShortPrefixes() {
this.setUseShortClassName(true);
this.setUseIdentityHashCode(false);
return this;
}
private String requestType;
private String subject;
private String initialMessage;
private String date;
private String lastComment;
private String lastAdhocTaskType;
private List<Map<String, String>> comments;
private Map<String, Object> attachment;
private String actionResult;
private Boolean resolved;

public String getRequestType() {
return requestType;
}

public ProcessVariables setRequestType(String requestType) {
this.requestType = requestType;
return this;
}

public String getSubject() {
return subject;
}

public ProcessVariables setSubject(String subject) {
this.subject = subject;
return this;
}

public String getInitialMessage() {
return initialMessage;
}

public ProcessVariables setInitialMessage(String intialMessage) {
this.initialMessage = intialMessage;
return this;
}

public String getDate() {
return date;
}

public ProcessVariables setDate(String date) {
this.date = date;
return this;
}

public String getLastComment() {
return lastComment;
}

public ProcessVariables setLastComment(String lastComment) {
this.lastComment = lastComment;
return this;
}

public List<Map<String, String>> getComments() {
return comments;
}

public ProcessVariables setComments(List<Map<String, String>> comments) {
this.comments = comments;
return this;
}

public Map<String, Object> getAttachment() {
return attachment;
}

public ProcessVariables setAttachment(Map<String, Object> attachment) {
this.attachment = attachment;
return this;
}

public String getActionResult() {
return actionResult;
}

public ProcessVariables setActionResult(String actionResult) {
this.actionResult = actionResult;
return this;
}

public Boolean getResolved() {
return resolved;
}

public ProcessVariables setResolved(Boolean resolved) {
this.resolved = resolved;
return this;
}

public String getLastAdhocTaskType() {
return lastAdhocTaskType;
}

public ProcessVariables setLastAdhocTaskType(String lastAdhocTaskType) {
this.lastAdhocTaskType = lastAdhocTaskType;
return this;
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(
this,
new MultilineRecursiveToStringStyle() {
public ToStringStyle withShortPrefixes() {
this.setUseShortClassName(true);
this.setUseIdentityHashCode(false);
return this;
}
}.withShortPrefixes());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.example.camunda.process.solution.exception.TechnicalException;
import org.example.camunda.process.solution.exception.UnauthorizedException;
import org.example.camunda.process.solution.facade.dto.AuthUser;
import org.keycloak.KeycloakSecurityContext;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -19,9 +18,8 @@
import org.springframework.web.context.request.ServletRequestAttributes;

public abstract class AbstractController {

@Autowired
private HttpServletRequest request;

@Autowired private HttpServletRequest request;

public abstract Logger getLogger();

Expand Down Expand Up @@ -78,13 +76,17 @@ protected HttpServletResponse getHttpServletResponse() {
return ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
.getResponse();
}

protected String getAuthenticatedUser() {
//(KeycloakPrincipal) request.getUserPrincipal();
return getKeycloakSecurityContext().getIdToken().getGivenName();

protected AuthUser getAuthenticatedUser() {
// (KeycloakPrincipal) request.getUserPrincipal();
AuthUser user = new AuthUser();
user.setUsername(getKeycloakSecurityContext().getIdToken().getGivenName());
user.setEmail(getKeycloakSecurityContext().getIdToken().getEmail());

return user;
}

private KeycloakSecurityContext getKeycloakSecurityContext() {
return (KeycloakSecurityContext) request.getAttribute(KeycloakSecurityContext.class.getName());
return (KeycloakSecurityContext) request.getAttribute(KeycloakSecurityContext.class.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public class AuthenticationController extends AbstractController {

@GetMapping("/me")
public AuthUser getConnectedUser() {
AuthUser loggedUser = new AuthUser();
loggedUser.setUsername(getAuthenticatedUser());
return loggedUser;
return getAuthenticatedUser();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.example.camunda.process.solution.facade;

import com.fasterxml.jackson.databind.JsonNode;
import io.camunda.tasklist.exception.TaskListException;
import io.camunda.tasklist.util.JsonUtils;
import java.io.IOException;

import org.example.camunda.process.solution.facade.dto.Form;
import org.example.camunda.process.solution.service.FormService;
import org.example.camunda.process.solution.service.TaskListService;
Expand All @@ -15,11 +17,6 @@
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.JsonNode;

import io.camunda.tasklist.exception.TaskListException;
import io.camunda.tasklist.util.JsonUtils;

@RestController
@RequestMapping("/forms")
@CrossOrigin(origins = "*")
Expand Down
Loading

0 comments on commit 7d3007e

Please sign in to comment.