Vinyeh commited on
Commit
bcbb570
·
verified ·
1 Parent(s): 182b466

Add pinned source: camunda-dmn-examples (part 22)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +4 -0
  2. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly-jakarta/assembly.xml +31 -0
  3. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly-jakarta/pom.xml +692 -0
  4. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly-jakarta/renames.properties +14 -0
  5. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/main/webapp/develop/invoice-forms/start-form.html +117 -0
  6. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/main/webapp/error-404-page.html +131 -0
  7. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/main/webapp/error-500-page.html +132 -0
  8. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/main/webapp/index.html +11 -0
  9. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/admin/plugin/base/AbstractAdminPluginTest.java +79 -0
  10. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/admin/plugin/base/MetricsRestServiceTest.java +488 -0
  11. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/IncidentRestServiceTest.java +533 -0
  12. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/PluginQueryTest.java +41 -0
  13. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/ProcessDefinitionResourceTest.java +683 -0
  14. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/ProcessDefinitionRestServiceTest.java +465 -0
  15. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/ProcessInstanceResourceTest.java +279 -0
  16. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/ProcessInstanceRestServiceTest.java +0 -0
  17. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/authorization/AuthorizationTest.java +216 -0
  18. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/authorization/IncidentRestServiceAuthorizationTest.java +147 -0
  19. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/authorization/ProcessDefinitionResourceAuthorizationTest.java +203 -0
  20. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/authorization/ProcessDefinitionRestServiceAuthorizationTest.java +177 -0
  21. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/authorization/ProcessInstanceResourceAuthorizationTest.java +276 -0
  22. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/authorization/ProcessInstanceRestServiceAuthorizationTest.java +150 -0
  23. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/pa/CreateIncidentsDelegate.java +50 -0
  24. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/pa/FailingDelegate.java +29 -0
  25. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/pa/VariableSavingDelegate.java +33 -0
  26. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/tenantcheck/IncidentRestServiceTenantCheckTest.java +187 -0
  27. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/tenantcheck/ProcessDefinitionResourceTenantCheckTest.java +166 -0
  28. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/tenantcheck/ProcessDefinitionRestServiceTenantCheckTest.java +251 -0
  29. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/tenantcheck/ProcessInstanceResourceTenantCheckTest.java +161 -0
  30. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/tenantcheck/ProcessInstanceRestServiceTenantCheckTest.java +232 -0
  31. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/db/QuerySessionFactoryTest.java +59 -0
  32. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/engine/EnginesFilterTest.java +142 -0
  33. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/engine/WebappsDatabaseNamingConsistencyTest.java +76 -0
  34. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/auth/AuthCacheTest.java +540 -0
  35. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/auth/ContainerAuthenticationFilterTest.java +279 -0
  36. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/auth/UserAuthenticationResourceLoggingTest.java +303 -0
  37. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/auth/UserAuthenticationResourceTest.java +238 -0
  38. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/filter/RequestFilterTest.java +126 -0
  39. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/filter/SecurityFilterRulesTest.java +536 -0
  40. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/filter/SessionCookieTest.java +183 -0
  41. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/filter/csrf/CsrfPreventionCookieTest.java +199 -0
  42. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/filter/csrf/CsrfPreventionFilterAppPathTest.java +98 -0
  43. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/filter/csrf/CsrfPreventionFilterTest.java +267 -0
  44. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/filter/headersec/ContentSecurityPolicyTest.java +83 -0
  45. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/filter/headersec/ContentTypeOptionsTest.java +82 -0
  46. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/filter/headersec/StrictTransportSecurityTest.java +133 -0
  47. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/filter/headersec/XssProtectionTest.java +150 -0
  48. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/util/HeaderRule.java +184 -0
  49. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/plugin/resource/AbstractAppPluginRootResourceTest.java +144 -0
  50. source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/resources/META-INF/services/org.camunda.bpm.engine.rest.spi.ProcessEngineProvider +1 -0
.gitattributes CHANGED
@@ -77,3 +77,7 @@ source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/examples/invoice/src
77
  source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/examples/invoice/src/main/webapp/assets/fonts/IBMPlexSans-BoldItalic.otf filter=lfs diff=lfs merge=lfs -text
78
  source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/examples/invoice/src/main/webapp/assets/fonts/IBMPlexSans-Italic.otf filter=lfs diff=lfs merge=lfs -text
79
  source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/examples/invoice/src/main/webapp/assets/fonts/IBMPlexSans-Regular.otf filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
77
  source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/examples/invoice/src/main/webapp/assets/fonts/IBMPlexSans-BoldItalic.otf filter=lfs diff=lfs merge=lfs -text
78
  source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/examples/invoice/src/main/webapp/assets/fonts/IBMPlexSans-Italic.otf filter=lfs diff=lfs merge=lfs -text
79
  source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/examples/invoice/src/main/webapp/assets/fonts/IBMPlexSans-Regular.otf filter=lfs diff=lfs merge=lfs -text
80
+ source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/frontend/camunda-commons-ui/vendor/fonts/IBMPlexSans-Bold.otf filter=lfs diff=lfs merge=lfs -text
81
+ source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/frontend/camunda-commons-ui/vendor/fonts/IBMPlexSans-BoldItalic.otf filter=lfs diff=lfs merge=lfs -text
82
+ source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/frontend/camunda-commons-ui/vendor/fonts/IBMPlexSans-Italic.otf filter=lfs diff=lfs merge=lfs -text
83
+ source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/frontend/camunda-commons-ui/vendor/fonts/IBMPlexSans-Regular.otf filter=lfs diff=lfs merge=lfs -text
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly-jakarta/assembly.xml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <assembly
3
+ xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
4
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
+ xsi:schemaLocation="
6
+ http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2
7
+ http://maven.apache.org/xsd/assembly-1.1.2.xsd">
8
+ <id>frontend-sources</id>
9
+ <formats>
10
+ <format>zip</format>
11
+ </formats>
12
+ <baseDirectory>camunda-webapp-jakarta-frontend-sources</baseDirectory>
13
+ <fileSets>
14
+ <!-- Only respect frontend code -->
15
+ <fileSet>
16
+ <outputDirectory>/</outputDirectory>
17
+ <directory>../frontend</directory>
18
+
19
+ <excludes>
20
+ <!-- These excludes are only needed to speed up the build locally (when the folders are already dirty);
21
+ with a clean copy of the repo (e.g., on Jenkins) these folders should not exist -->
22
+ <exclude>**/node_modules/**</exclude>
23
+ <exclude>**/.idea/**</exclude>
24
+ <exclude>**/.settings/**</exclude>
25
+ <exclude>**/dist/**</exclude>
26
+ <exclude>camunda-commons-ui/cache/**</exclude>
27
+ <exclude>ui/cockpit/build/**</exclude>
28
+ </excludes>
29
+ </fileSet>
30
+ </fileSets>
31
+ </assembly>
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly-jakarta/pom.xml ADDED
@@ -0,0 +1,692 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <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">
3
+
4
+ <modelVersion>4.0.0</modelVersion>
5
+
6
+ <parent>
7
+ <groupId>org.camunda.bpm.webapp</groupId>
8
+ <artifactId>camunda-webapp-root</artifactId>
9
+ <version>7.24.0-SNAPSHOT</version>
10
+ <relativePath>../</relativePath>
11
+ </parent>
12
+
13
+ <artifactId>camunda-webapp-jakarta</artifactId>
14
+ <packaging>war</packaging>
15
+
16
+ <description>
17
+ Note: 7.24.0 is the last community edition release published on Maven Central. This library will not receive any new versions or releases. However, if you are interested in extended maintenance you could look into our enterprise edition. Get in touch with us: https://camunda.com/contact/
18
+ </description>
19
+ <name>Camunda Platform - Webapp - Assembly Jakarta</name>
20
+
21
+ <properties>
22
+ <jakarta.webapp>${project.build.directory}/generated-resources/jakarta-webapp</jakarta.webapp>
23
+ <jakarta.runtime>${project.build.directory}/generated-resources/jakarta-runtime</jakarta.runtime>
24
+
25
+ <version.resteasy>6.2.8.Final</version.resteasy>
26
+ <version.jetty>11.0.14</version.jetty>
27
+ <version.jersey2>3.1.1</version.jersey2>
28
+
29
+ <web.resources.override>${jakarta.runtime}/default/webapp</web.resources.override>
30
+ <java.resources.override>${jakarta.runtime}/default/resources</java.resources.override>
31
+ <properties.override>${jakarta.runtime}/default/config.properties</properties.override>
32
+
33
+ <!-- generate a bom of compile time dependencies for the license book.
34
+ Note: Every compile time dependency will end up in the license book. Please
35
+ declare only dependencies that are actually needed -->
36
+ <skip-third-party-bom>false</skip-third-party-bom>
37
+ </properties>
38
+
39
+ <dependencyManagement>
40
+ <dependencies>
41
+ <dependency>
42
+ <groupId>org.camunda.bpm</groupId>
43
+ <artifactId>camunda-engine-rest-core-jakarta</artifactId>
44
+ <version>${project.version}</version>
45
+ </dependency>
46
+ <dependency>
47
+ <groupId>org.camunda.bpm</groupId>
48
+ <artifactId>camunda-engine-rest-jakarta</artifactId>
49
+ <version>${project.version}</version>
50
+ </dependency>
51
+ <dependency>
52
+ <groupId>jakarta.platform</groupId>
53
+ <artifactId>jakarta.jakartaee-bom</artifactId>
54
+ <version>${version.jakarta-ee-spec}</version>
55
+ <type>pom</type>
56
+ <scope>import</scope>
57
+ </dependency>
58
+ <dependency>
59
+ <groupId>com.fasterxml.jackson</groupId>
60
+ <artifactId>jackson-bom</artifactId>
61
+ <version>${version.jackson}</version>
62
+ <scope>import</scope>
63
+ <type>pom</type>
64
+ </dependency>
65
+ </dependencies>
66
+ </dependencyManagement>
67
+
68
+ <dependencies>
69
+
70
+ <dependency>
71
+ <groupId>com.fasterxml.jackson.jakarta.rs</groupId>
72
+ <artifactId>jackson-jakarta-rs-json-provider</artifactId>
73
+ <exclusions>
74
+ <exclusion>
75
+ <groupId>jakarta.activation</groupId>
76
+ <artifactId>jakarta.activation-api</artifactId>
77
+ </exclusion>
78
+ <exclusion>
79
+ <groupId>jakarta.xml.bind</groupId>
80
+ <artifactId>jakarta.xml.bind-api</artifactId>
81
+ </exclusion>
82
+ </exclusions>
83
+ </dependency>
84
+
85
+ <dependency>
86
+ <groupId>com.fasterxml.jackson.core</groupId>
87
+ <artifactId>jackson-databind</artifactId>
88
+ </dependency>
89
+
90
+ <dependency>
91
+ <groupId>com.fasterxml.jackson.datatype</groupId>
92
+ <artifactId>jackson-datatype-jsr310</artifactId>
93
+ </dependency>
94
+
95
+ <dependency>
96
+ <groupId>jakarta.servlet</groupId>
97
+ <artifactId>jakarta.servlet-api</artifactId>
98
+ <scope>provided</scope>
99
+ </dependency>
100
+ <dependency>
101
+ <groupId>jakarta.activation</groupId>
102
+ <artifactId>jakarta.activation-api</artifactId>
103
+ <scope>provided</scope>
104
+ </dependency>
105
+ <dependency>
106
+ <groupId>jakarta.ws.rs</groupId>
107
+ <artifactId>jakarta.ws.rs-api</artifactId>
108
+ <scope>provided</scope>
109
+ </dependency>
110
+ <dependency>
111
+ <groupId>jakarta.xml.bind</groupId>
112
+ <artifactId>jakarta.xml.bind-api</artifactId>
113
+ <scope>provided</scope>
114
+ </dependency>
115
+
116
+ <dependency>
117
+ <groupId>org.camunda.bpm</groupId>
118
+ <artifactId>camunda-engine-rest-core-jakarta</artifactId>
119
+ </dependency>
120
+
121
+ <dependency>
122
+ <groupId>org.camunda.bpm</groupId>
123
+ <artifactId>camunda-engine-rest-core-jakarta</artifactId>
124
+ <version>${project.version}</version>
125
+ <scope>test</scope>
126
+ <classifier>tests</classifier>
127
+ </dependency>
128
+ </dependencies>
129
+
130
+ <build>
131
+ <finalName>camunda-webapp-jakarta</finalName>
132
+
133
+ <plugins>
134
+ <plugin>
135
+ <groupId>org.apache.maven.plugins</groupId>
136
+ <artifactId>maven-resources-plugin</artifactId>
137
+ <executions>
138
+ <execution>
139
+ <id>copy-resources-assembly</id>
140
+ <phase>prepare-package</phase>
141
+ <goals>
142
+ <goal>copy-resources</goal>
143
+ </goals>
144
+ <configuration>
145
+ <outputDirectory>${basedir}/target/webapp</outputDirectory>
146
+ <resources>
147
+ <resource>
148
+ <directory>${basedir}/../frontend/target/webapp</directory>
149
+ <filtering>false</filtering>
150
+ </resource>
151
+ </resources>
152
+ </configuration>
153
+ </execution>
154
+ <execution>
155
+ <id>copy-sources</id>
156
+ <phase>generate-sources</phase>
157
+ <goals>
158
+ <goal>copy-resources</goal>
159
+ </goals>
160
+ <configuration>
161
+ <outputDirectory>${project.build.directory}/generated-sources/jakarta</outputDirectory>
162
+ <resources>
163
+ <resource>
164
+ <directory>${basedir}/../assembly/src/main/java</directory>
165
+ <filtering>false</filtering>
166
+ </resource>
167
+ </resources>
168
+ </configuration>
169
+ </execution>
170
+ <execution>
171
+ <id>copy-runtime</id>
172
+ <phase>generate-resources</phase>
173
+ <goals>
174
+ <goal>copy-resources</goal>
175
+ </goals>
176
+ <configuration>
177
+ <outputDirectory>${jakarta.runtime}</outputDirectory>
178
+ <resources>
179
+ <resource>
180
+ <directory>${basedir}/../assembly/src/main/runtime</directory>
181
+ <filtering>true</filtering>
182
+ </resource>
183
+ </resources>
184
+ </configuration>
185
+ </execution>
186
+ <execution>
187
+ <id>copy-webapp</id>
188
+ <phase>generate-resources</phase>
189
+ <goals>
190
+ <goal>copy-resources</goal>
191
+ </goals>
192
+ <configuration>
193
+ <outputDirectory>${jakarta.webapp}</outputDirectory>
194
+ <resources>
195
+ <resource>
196
+ <directory>${basedir}/../assembly/src/main/webapp</directory>
197
+ <filtering>false</filtering>
198
+ </resource>
199
+ </resources>
200
+ </configuration>
201
+ </execution>
202
+ <execution>
203
+ <id>copy-resources</id>
204
+ <phase>generate-resources</phase>
205
+ <goals>
206
+ <goal>copy-resources</goal>
207
+ </goals>
208
+ <configuration>
209
+ <outputDirectory>${project.build.directory}/generated-resources/jakarta</outputDirectory>
210
+ <resources>
211
+ <resource>
212
+ <directory>${basedir}/../assembly/src/main/resources</directory>
213
+ <filtering>false</filtering>
214
+ </resource>
215
+ </resources>
216
+ </configuration>
217
+ </execution>
218
+ <execution>
219
+ <id>copy-test-sources</id>
220
+ <phase>generate-test-sources</phase>
221
+ <goals>
222
+ <goal>copy-resources</goal>
223
+ </goals>
224
+ <configuration>
225
+ <outputDirectory>${project.build.directory}/generated-test-sources/jakarta</outputDirectory>
226
+ <resources>
227
+ <resource>
228
+ <directory>${basedir}/../assembly/src/test/java</directory>
229
+ <filtering>false</filtering>
230
+ </resource>
231
+ </resources>
232
+ </configuration>
233
+ </execution>
234
+ <execution>
235
+ <id>copy-test-resources</id>
236
+ <phase>generate-test-resources</phase>
237
+ <goals>
238
+ <goal>copy-resources</goal>
239
+ </goals>
240
+ <configuration>
241
+ <outputDirectory>${project.build.directory}/generated-test-resources/jakarta</outputDirectory>
242
+ <resources>
243
+ <resource>
244
+ <directory>${basedir}/../assembly/src/test/resources</directory>
245
+ <filtering>true</filtering>
246
+ </resource>
247
+ </resources>
248
+ </configuration>
249
+ </execution>
250
+ </executions>
251
+ </plugin>
252
+ <plugin>
253
+ <groupId>org.apache.maven.plugins</groupId>
254
+ <artifactId>maven-dependency-plugin</artifactId>
255
+ <executions>
256
+ <execution>
257
+ <phase>initialize</phase>
258
+ <goals>
259
+ <goal>properties</goal>
260
+ </goals>
261
+ </execution>
262
+ </executions>
263
+ </plugin>
264
+ <plugin>
265
+ <groupId>org.eclipse.transformer</groupId>
266
+ <artifactId>transformer-maven-plugin</artifactId>
267
+ <configuration>
268
+ <rules>
269
+ <jakartaDefaults>true</jakartaDefaults>
270
+ <renames combine.children="append">
271
+ <rename>${project.basedir}/renames.properties</rename>
272
+ </renames>
273
+ </rules>
274
+ <classifier>jakarta</classifier>
275
+ </configuration>
276
+ <executions>
277
+ <execution>
278
+ <id>transform-sources</id>
279
+ <phase>generate-sources</phase>
280
+ <goals>
281
+ <goal>transform</goal>
282
+ </goals>
283
+ <configuration>
284
+ <transformDirectory>${project.build.directory}/generated-sources/jakarta</transformDirectory>
285
+ </configuration>
286
+ </execution>
287
+ <execution>
288
+ <id>transform-runtime</id>
289
+ <phase>generate-resources</phase>
290
+ <goals>
291
+ <goal>transform</goal>
292
+ </goals>
293
+ <configuration>
294
+ <transformDirectory>${jakarta.runtime}</transformDirectory>
295
+ </configuration>
296
+ </execution>
297
+ <execution>
298
+ <id>transform-webapp</id>
299
+ <phase>generate-resources</phase>
300
+ <goals>
301
+ <goal>transform</goal>
302
+ </goals>
303
+ <configuration>
304
+ <transformDirectory>${jakarta.webapp}</transformDirectory>
305
+ </configuration>
306
+ </execution>
307
+ <execution>
308
+ <id>transform-jakarta-resources</id>
309
+ <phase>generate-resources</phase>
310
+ <goals>
311
+ <goal>transform</goal>
312
+ </goals>
313
+ <configuration>
314
+ <transformDirectory>${project.build.directory}/generated-resources/jakarta</transformDirectory>
315
+ </configuration>
316
+ </execution>
317
+ <execution>
318
+ <id>transform-test-sources</id>
319
+ <phase>generate-test-sources</phase>
320
+ <goals>
321
+ <goal>transform</goal>
322
+ </goals>
323
+ <configuration>
324
+ <transformDirectory>${project.build.directory}/generated-test-sources/jakarta</transformDirectory>
325
+ </configuration>
326
+ </execution>
327
+ <execution>
328
+ <id>transform-test-resources</id>
329
+ <phase>generate-test-resources</phase>
330
+ <goals>
331
+ <goal>transform</goal>
332
+ </goals>
333
+ <configuration>
334
+ <transformDirectory>${project.build.directory}/generated-test-resources/jakarta</transformDirectory>
335
+ </configuration>
336
+ </execution>
337
+ </executions>
338
+ </plugin>
339
+ <plugin>
340
+ <groupId>org.codehaus.mojo</groupId>
341
+ <artifactId>build-helper-maven-plugin</artifactId>
342
+ <version>3.2.0</version>
343
+ <executions>
344
+ <execution>
345
+ <id>add-jakarta-source</id>
346
+ <phase>generate-sources</phase>
347
+ <goals>
348
+ <goal>add-source</goal>
349
+ </goals>
350
+ <configuration>
351
+ <sources>
352
+ <source>${basedir}/target/generated-sources/jakarta</source>
353
+ </sources>
354
+ </configuration>
355
+ </execution>
356
+ <execution>
357
+ <id>add-jakarta-resource</id>
358
+ <phase>generate-resources</phase>
359
+ <goals>
360
+ <goal>add-resource</goal>
361
+ </goals>
362
+ <configuration>
363
+ <resources>
364
+ <resource>
365
+ <directory>${basedir}/target/generated-resources/jakarta</directory>
366
+ </resource>
367
+ </resources>
368
+ </configuration>
369
+ </execution>
370
+ <execution>
371
+ <id>add-jakarta-test-source</id>
372
+ <phase>generate-test-sources</phase>
373
+ <goals>
374
+ <goal>add-test-source</goal>
375
+ </goals>
376
+ <configuration>
377
+ <sources>
378
+ <source>${basedir}/target/generated-test-sources/jakarta</source>
379
+ </sources>
380
+ </configuration>
381
+ </execution>
382
+ <execution>
383
+ <id>add-jakarta-test-resource</id>
384
+ <phase>generate-test-resources</phase>
385
+ <goals>
386
+ <goal>add-test-resource</goal>
387
+ </goals>
388
+ <configuration>
389
+ <resources>
390
+ <resource>
391
+ <directory>${basedir}/target/generated-test-resources/jakarta</directory>
392
+ </resource>
393
+ </resources>
394
+ </configuration>
395
+ </execution>
396
+ </executions>
397
+ </plugin>
398
+
399
+ <plugin>
400
+ <groupId>org.apache.maven.plugins</groupId>
401
+ <artifactId>maven-war-plugin</artifactId>
402
+ <configuration combine.children="append">
403
+ <warSourceDirectory>${jakarta.webapp}</warSourceDirectory>
404
+ </configuration>
405
+ </plugin>
406
+ <plugin>
407
+ <artifactId>maven-surefire-plugin</artifactId>
408
+ <configuration>
409
+ <failIfNoTests>false</failIfNoTests>
410
+ <trimStackTrace>false</trimStackTrace>
411
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
412
+ </configuration>
413
+ </plugin>
414
+ <plugin>
415
+ <groupId>org.apache.maven.plugins</groupId>
416
+ <artifactId>maven-jar-plugin</artifactId>
417
+ </plugin>
418
+ <plugin>
419
+ <groupId>org.codehaus.mojo</groupId>
420
+ <artifactId>license-maven-plugin</artifactId>
421
+ <version>1.14</version>
422
+ <configuration>
423
+ <excludedScopes>test</excludedScopes>
424
+ </configuration>
425
+ </plugin>
426
+ <plugin>
427
+ <groupId>org.apache.maven.plugins</groupId>
428
+ <artifactId>maven-assembly-plugin</artifactId>
429
+ </plugin>
430
+ <plugin>
431
+ <groupId>org.apache.maven.plugins</groupId>
432
+ <artifactId>maven-antrun-plugin</artifactId>
433
+ <executions>
434
+ <execution>
435
+ <phase>generate-resources</phase>
436
+ <configuration>
437
+ <target>
438
+ <mkdir dir="${project.basedir}/target/webapp" />
439
+ </target>
440
+ </configuration>
441
+ <goals>
442
+ <goal>run</goal>
443
+ </goals>
444
+ </execution>
445
+ </executions>
446
+ </plugin>
447
+ </plugins>
448
+ </build>
449
+
450
+ <profiles>
451
+ <profile>
452
+ <id>central-sonatype-publish</id>
453
+ <properties>
454
+ <!-- skip building the frontend-sources zip artifact
455
+ when releasing the community edition (alpha/minor releases) -->
456
+ <skip-zip-frontend-sources>true</skip-zip-frontend-sources>
457
+ </properties>
458
+ </profile>
459
+
460
+ <profile>
461
+ <id>os</id>
462
+ <activation>
463
+ <os>
464
+ <family>Windows</family>
465
+ </os>
466
+ </activation>
467
+ <properties>
468
+ <exec.shell>cmd</exec.shell>
469
+ <exec.arg>/c</exec.arg>
470
+ </properties>
471
+ </profile>
472
+
473
+ <profile>
474
+ <id>develop</id>
475
+ <dependencies>
476
+ <dependency>
477
+ <groupId>org.jboss.resteasy</groupId>
478
+ <artifactId>resteasy-core</artifactId>
479
+ <version>${version.resteasy}</version>
480
+ <scope>runtime</scope>
481
+ </dependency>
482
+ <dependency>
483
+ <groupId>jakarta.ws.rs</groupId>
484
+ <artifactId>jakarta.ws.rs-api</artifactId>
485
+ </dependency>
486
+ <dependency>
487
+ <groupId>org.camunda.bpm</groupId>
488
+ <artifactId>camunda-engine</artifactId>
489
+ </dependency>
490
+ <dependency>
491
+ <groupId>org.camunda.bpm</groupId>
492
+ <artifactId>camunda-engine-plugin-spin</artifactId>
493
+ </dependency>
494
+ <dependency>
495
+ <groupId>org.camunda.spin</groupId>
496
+ <artifactId>camunda-spin-dataformat-json-jackson</artifactId>
497
+ </dependency>
498
+ <dependency>
499
+ <groupId>org.camunda.spin</groupId>
500
+ <artifactId>camunda-spin-dataformat-xml-dom-jakarta</artifactId>
501
+ </dependency>
502
+ <dependency>
503
+ <groupId>org.camunda.bpm</groupId>
504
+ <artifactId>camunda-engine-plugin-connect</artifactId>
505
+ </dependency>
506
+ <dependency>
507
+ <groupId>org.camunda.bpm.identity</groupId>
508
+ <artifactId>camunda-identity-ldap</artifactId>
509
+ </dependency>
510
+ <dependency>
511
+ <groupId>com.h2database</groupId>
512
+ <artifactId>h2</artifactId>
513
+ </dependency>
514
+ <dependency>
515
+ <groupId>com.fasterxml.uuid</groupId>
516
+ <artifactId>java-uuid-generator</artifactId>
517
+ </dependency>
518
+ <dependency>
519
+ <groupId>ch.qos.logback</groupId>
520
+ <artifactId>logback-classic</artifactId>
521
+ </dependency>
522
+ <dependency>
523
+ <groupId>com.sun.xml.bind</groupId>
524
+ <artifactId>jaxb-impl</artifactId>
525
+ <version>${version.xml.jaxb-impl4}</version>
526
+ </dependency>
527
+ <dependency>
528
+ <groupId>org.graalvm.js</groupId>
529
+ <artifactId>js</artifactId>
530
+ </dependency>
531
+ <dependency>
532
+ <groupId>org.graalvm.js</groupId>
533
+ <artifactId>js-scriptengine</artifactId>
534
+ </dependency>
535
+ </dependencies>
536
+ <build>
537
+ <plugins>
538
+ <plugin>
539
+ <groupId>org.eclipse.jetty</groupId>
540
+ <artifactId>jetty-maven-plugin</artifactId>
541
+ <configuration>
542
+ <webApp>
543
+ <contextPath>/camunda</contextPath>
544
+ <defaultsDescriptor>${jakarta.runtime}/develop/jetty/webdefault.xml</defaultsDescriptor>
545
+ <resourceBases>
546
+ <resourceBase>${project.basedir}/target/webapp</resourceBase>
547
+ <resourceBase>${jakarta.webapp}</resourceBase>
548
+ </resourceBases>
549
+ </webApp>
550
+ </configuration>
551
+ </plugin>
552
+ <plugin>
553
+ <groupId>org.codehaus.mojo</groupId>
554
+ <artifactId>build-helper-maven-plugin</artifactId>
555
+ <executions>
556
+ <execution>
557
+ <id>add-sources</id>
558
+ <goals>
559
+ <goal>add-source</goal>
560
+ </goals>
561
+ <configuration>
562
+ <sources>
563
+ <source>${jakarta.runtime}/develop/java</source>
564
+ </sources>
565
+ </configuration>
566
+ </execution>
567
+ <execution>
568
+ <id>add-resources</id>
569
+ <goals>
570
+ <goal>add-resource</goal>
571
+ </goals>
572
+ <configuration>
573
+ <resources>
574
+ <resource>
575
+ <directory>${jakarta.runtime}/develop/resources</directory>
576
+ </resource>
577
+ </resources>
578
+ </configuration>
579
+ </execution>
580
+ </executions>
581
+ </plugin>
582
+ </plugins>
583
+ </build>
584
+ <properties>
585
+ <java.resources.override>${jakarta.runtime}/develop/resources</java.resources.override>
586
+ </properties>
587
+ </profile>
588
+
589
+ <profile>
590
+ <id>h2</id>
591
+ <properties>
592
+ <project.parent.basedir>./</project.parent.basedir>
593
+ </properties>
594
+ </profile>
595
+
596
+ <!-- check history audit -->
597
+ <profile>
598
+ <id>cfghistoryaudit</id>
599
+ <properties>
600
+ <history.level>audit</history.level>
601
+ </properties>
602
+ </profile>
603
+
604
+ <!-- check history activity -->
605
+ <profile>
606
+ <id>cfghistoryactivity</id>
607
+ <properties>
608
+ <history.level>activity</history.level>
609
+ </properties>
610
+ </profile>
611
+
612
+ <!-- check history none -->
613
+ <profile>
614
+ <id>cfghistorynone</id>
615
+ <properties>
616
+ <history.level>none</history.level>
617
+ </properties>
618
+ </profile>
619
+
620
+ <profile>
621
+ <id>cfgJdbcBatchProcessingOff</id>
622
+ <properties>
623
+ <jdbcBatchProcessing>false</jdbcBatchProcessing>
624
+ </properties>
625
+ </profile>
626
+
627
+ <profile>
628
+ <id>license-header-check</id>
629
+ <build>
630
+ <plugins>
631
+ <plugin>
632
+ <groupId>com.mycila</groupId>
633
+ <artifactId>license-maven-plugin</artifactId>
634
+ </plugin>
635
+ </plugins>
636
+ </build>
637
+ </profile>
638
+
639
+ <profile>
640
+ <id>below-jdk17</id>
641
+ <activation>
642
+ <jdk>(,17)</jdk>
643
+ </activation>
644
+
645
+ <build>
646
+ <plugins>
647
+ <plugin>
648
+ <artifactId>maven-compiler-plugin</artifactId>
649
+ <configuration>
650
+ <testExcludes>
651
+ <exclude>**/AuthCacheTest.java</exclude>
652
+ <exclude>**/ContainerAuthenticationFilterTest.java</exclude>
653
+ <exclude>**/CsrfPreventionFilterAppPathTest.java</exclude>
654
+ <exclude>**/CsrfPreventionFilterTest.java</exclude>
655
+ <exclude>**/UserAuthenticationResourceTest.java</exclude>
656
+ <exclude>**/UserAuthenticationResourceLoggingTest.java</exclude>
657
+ </testExcludes>
658
+ </configuration>
659
+ </plugin>
660
+ </plugins>
661
+ </build>
662
+ </profile>
663
+
664
+ <profile>
665
+ <id>jdk17-and-onwards</id>
666
+ <activation>
667
+ <jdk>[17,)</jdk>
668
+ </activation>
669
+
670
+ <properties>
671
+ <version.spring.framework>${version.spring.framework6}</version.spring.framework>
672
+ </properties>
673
+
674
+ <dependencies>
675
+ <dependency>
676
+ <groupId>org.springframework</groupId>
677
+ <artifactId>spring-test</artifactId>
678
+ <version>${version.spring.framework}</version>
679
+ <scope>test</scope>
680
+ </dependency>
681
+
682
+ <dependency>
683
+ <groupId>org.springframework</groupId>
684
+ <artifactId>spring-web</artifactId>
685
+ <version>${version.spring.framework}</version>
686
+ <scope>test</scope>
687
+ </dependency>
688
+ </dependencies>
689
+ </profile>
690
+ </profiles>
691
+
692
+ </project>
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly-jakarta/renames.properties ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # DevProcessApplication
3
+ org.camunda.bpm.application.impl.ServletProcessApplication=org.camunda.bpm.application.impl.JakartaServletProcessApplication
4
+ ServletProcessApplication=JakartaServletProcessApplication
5
+
6
+ # H2
7
+ org.h2.server.web.WebServlet=org.h2.server.web.JakartaWebServlet
8
+
9
+ # References to resources from tests
10
+ src/main/webapp/WEB-INF/securityFilterRules.json=target/generated-resources/jakarta-webapp/WEB-INF/securityFilterRules.json
11
+ src/test/resources/WEB-INF/=target/generated-test-resources/jakarta/WEB-INF/
12
+
13
+ # Logging
14
+ javax.activation.level=jakarta.activation.level
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/main/webapp/develop/invoice-forms/start-form.html ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <form role="form" name="invoiceForm"
2
+ class="form-horizontal">
3
+
4
+ <div class="well">Please fill in the details for the invoice you received</div>
5
+
6
+
7
+ <div class="form-group">
8
+ <label class="control-label col-md-4"
9
+ for="invoiceDocumentUpload">Upload your Invoice Document (Required)</label>
10
+ <div class="col-md-8">
11
+ <input type="file"
12
+ id="invoiceDocumentUpload"
13
+ cam-variable-name="invoiceDocument"
14
+ cam-variable-type="File"
15
+ cam-max-filesize="10000000"
16
+ class="form-control"/>
17
+ <div class="help-block">This field is required</div>
18
+ </div>
19
+ </div>
20
+
21
+ <script cam-script type="text/form-script">
22
+ var fileUpload = $('#invoiceDocumentUpload');
23
+ var fileUploadHelpBlock = $('.help-block', fileUpload.parent());
24
+
25
+ function flagFileUpload() {
26
+ var hasFile = fileUpload.get(0).files.length > 0;
27
+ fileUpload[hasFile ? 'removeClass' : 'addClass']('ng-invalid');
28
+ fileUploadHelpBlock[hasFile ? 'removeClass' : 'addClass']('error');
29
+ return hasFile;
30
+ }
31
+
32
+ fileUpload.on('change', function () {
33
+ flagFileUpload();
34
+ });
35
+
36
+ camForm.on('submit', function(evt) {
37
+ var hasFile = flagFileUpload();
38
+
39
+ // prevent submit if user has not provided a file
40
+ evt.submitPrevented = !hasFile;
41
+ });
42
+ </script>
43
+
44
+
45
+ <div class="form-group">
46
+ <label class="control-label col-md-4"
47
+ for="creditor">Creditor</label>
48
+ <div class="col-md-8">
49
+ <input cam-variable-name="creditor"
50
+ cam-variable-type="String"
51
+ id="creditor"
52
+ class="form-control"
53
+ type="text"
54
+ required />
55
+ <div class="help-block">
56
+ (e.g. &quot;Great Pizza for Everyone Inc.&quot;)
57
+ </div>
58
+ </div>
59
+ </div>
60
+
61
+
62
+ <div class="form-group">
63
+ <label class="control-label col-md-4"
64
+ for="amount">Amount</label>
65
+ <div class="col-md-8">
66
+ <input cam-variable-name="amount"
67
+ cam-variable-type="Double"
68
+ id="amount"
69
+ name="amount"
70
+ class="form-control"
71
+ type="text"
72
+ required />
73
+ <div class="help-block">
74
+ (e.g. &quot;30.00&quot;)
75
+ </div>
76
+
77
+ <p ng-show="invoiceForm.amount.$error.camVariableType">
78
+ Note: Input must be a 'Double'.
79
+ </p>
80
+
81
+ </div>
82
+ </div>
83
+
84
+
85
+ <div class="form-group">
86
+ <label class="control-label col-md-4"
87
+ for="amount">Invoice Category</label>
88
+ <div class="col-md-8">
89
+ <select cam-variable-name="invoiceCategory"
90
+ cam-variable-type="String"
91
+ class="form-control">
92
+ <option>Travel Expenses</option>
93
+ <option>Misc</option>
94
+ </select>
95
+
96
+ </div>
97
+ </div>
98
+
99
+
100
+ <div class="form-group">
101
+ <label class="control-label col-md-4"
102
+ for="invoiceNumber">Invoice Number</label>
103
+ <div class="col-md-8">
104
+ <input cam-variable-name="invoiceNumber"
105
+ cam-variable-type="String"
106
+ id="invoiceNumber"
107
+ class="form-control"
108
+ type="text"
109
+ required />
110
+ <div class="help-block">
111
+ (e.g. &quot;I-12345&quot;)
112
+ </div>
113
+ </div>
114
+ </div>
115
+
116
+ </form>
117
+
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/main/webapp/error-404-page.html ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE HTML>
2
+ <html>
3
+ <head>
4
+ <style>
5
+
6
+ .navbar-header {
7
+ width: 100%;
8
+ position: fixed;
9
+ top: 0;
10
+ left: 0;
11
+ right: 0;
12
+ min-height: 42px;
13
+ z-index: 1030;
14
+ margin-bottom: 0;
15
+ border-top: 3px solid #b5152b;
16
+ box-shadow: 0 2px 10px -4px #555;
17
+ color: #777;
18
+ background-color: #fff;
19
+ font-size: 14px;
20
+ }
21
+
22
+ .navbar-header .logo {
23
+ margin-right: 5px;
24
+ fill: #666;
25
+ }
26
+ .navbar-header a {
27
+ text-decoration: none;
28
+ }
29
+
30
+ .navbar-header .navbar-brand {
31
+ display: flex;
32
+ align-items: center;
33
+ font-size: 21px;
34
+ line-height: 42px;
35
+ height: 42px;
36
+ padding-top: 0;
37
+ padding-bottom: 0;
38
+ padding-left: 10.5px;
39
+ padding-right: 15px;
40
+ color: #000;
41
+ }
42
+
43
+ body {
44
+ font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
45
+ font-size: 14px;
46
+ line-height: 1.42857143;
47
+ color: #555;
48
+ background-color: #fff;
49
+ }
50
+
51
+ .main {
52
+ position: absolute;
53
+ top: 45px;
54
+ bottom: 24px;
55
+ left: 0;
56
+ right: 0;
57
+ overflow: hidden;
58
+ background-color: #e5e5e5;
59
+ }
60
+
61
+ .inner {
62
+ margin: 15px 15px 30px 15px;
63
+ background-color: #fff;
64
+ padding: 15px;
65
+ box-shadow: 0 2px 8px -4px #555;
66
+ }
67
+
68
+ footer {
69
+ position: fixed;
70
+ padding-right: 15px;
71
+ z-index: 99;
72
+ height: 24px;
73
+ line-height: 24px;
74
+ font-size: smaller;
75
+ bottom: 0;
76
+ left: 0;
77
+ right: 0;
78
+ background-color: #fff;
79
+ border-top: 1px solid #eee;
80
+ color: #777;
81
+ text-align: right;
82
+ }
83
+
84
+ footer a {
85
+ color: #155cb5;
86
+ text-decoration: none;
87
+ }
88
+
89
+ header {
90
+ overflow: hidden;
91
+ border-bottom: 1px solid #e5e5e5;
92
+ margin-bottom: 15px;
93
+ }
94
+
95
+ h1 {
96
+ font-size: 28px;
97
+ margin-top: 5px;
98
+ margin-bottom: 10px;
99
+ font-weight: 100;
100
+ }
101
+
102
+ h2 {
103
+ font-weight: normal;
104
+ }
105
+ </style>
106
+
107
+ <title>Camunda - Not Found</title>
108
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
109
+ </head>
110
+ <body>
111
+ <div class="navbar-header">
112
+ <a class="navbar-brand" href="#/" title="Camunda - Not Found (404)">
113
+ <svg width="26" height="26" viewBox="0 0 26 26" class="logo"><path d="M13,0 C20.1797017,0 26,5.82029825 26,13 C26,20.1797017 20.1797017,26 13,26 C5.82029825,26 0,20.1797017 0,13 C0,5.82029825 5.82029825,0 13,0 Z M15.9924973,18.7781515 L9.99320872,18.7781515 L9.99320872,22.1683591 L15.9924973,22.1683591 L15.9924973,18.7781515 Z M13,3.83248173 C11.0249014,3.83248173 10.0058211,4.99702477 9.99320872,7.04527521 L9.99320872,7.04527521 L9.99320872,13.69284 L9.99685,13.8998115 C10.0647928,15.8025897 11.0827733,16.8913395 12.985706,16.8913395 C14.9608046,16.8913395 15.9773624,15.7267965 15.9924973,13.678546 L15.9924973,13.678546 L15.9924973,11.9834422 L14.0913912,11.9834422 L14.0913912,13.8105556 L14.0867571,13.9750837 C14.0405969,14.7638347 13.6523228,15.0490913 13.0445637,15.0490913 C12.4105815,15.0490913 11.9977362,14.7245327 11.9977362,13.8105556 L11.9977362,13.8105556 L11.9977362,6.89476748 L12.0023704,6.72991255 C12.0485306,5.93798383 12.4368047,5.62774885 13.0445637,5.64193778 C13.678546,5.64193778 14.0913912,5.99592523 14.0913912,6.90990233 L14.0913912,6.90990233 L14.0913912,8.28044758 L15.9924973,8.28044758 L15.9924973,7.04527521 L15.9888705,6.83655109 C15.9211931,4.91809617 14.9069918,3.83248173 13,3.83248173 Z"></path></svg>
114
+ <span class="brand-name ng-binding">Camunda</span>
115
+ </a>
116
+ </div>
117
+ <div class="main">
118
+ <div class="inner">
119
+ <header>
120
+ <h1>Not Found (404)</h1>
121
+ </header>
122
+ <h2>The Page you are requesting was not found on this server.</h2>
123
+ <p>Try going back to the Front Page and attempting the Action again.</p>
124
+ </div>
125
+ </div>
126
+
127
+ <footer>
128
+ Powered by <a href="http://camunda.org">Camunda Platform</a>
129
+ </footer>
130
+ </body>
131
+ </html>
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/main/webapp/error-500-page.html ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE HTML>
2
+ <html>
3
+ <head>
4
+ <style>
5
+ .navbar-header {
6
+ width: 100%;
7
+ position: fixed;
8
+ top: 0;
9
+ left: 0;
10
+ right: 0;
11
+ min-height: 42px;
12
+ z-index: 1030;
13
+ margin-bottom: 0;
14
+ border-top: 3px solid #b5152b;
15
+ box-shadow: 0 2px 10px -4px #555;
16
+ color: #777;
17
+ background-color: #fff;
18
+ font-size: 14px;
19
+ }
20
+
21
+ .navbar-header .logo {
22
+ margin-right: 5px;
23
+ fill: #666;
24
+ }
25
+
26
+ .navbar-header a {
27
+ text-decoration: none;
28
+ }
29
+
30
+ .navbar-header .navbar-brand {
31
+ display: flex;
32
+ align-items: center;
33
+ font-size: 21px;
34
+ line-height: 42px;
35
+ height: 42px;
36
+ padding-top: 0;
37
+ padding-bottom: 0;
38
+ padding-left: 10.5px;
39
+ padding-right: 15px;
40
+ color: #000;
41
+ }
42
+
43
+ body {
44
+ font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
45
+ font-size: 14px;
46
+ line-height: 1.42857143;
47
+ color: #555;
48
+ background-color: #fff;
49
+ }
50
+
51
+ .main {
52
+ position: absolute;
53
+ top: 45px;
54
+ bottom: 24px;
55
+ left: 0;
56
+ right: 0;
57
+ overflow: hidden;
58
+ background-color: #e5e5e5;
59
+ }
60
+
61
+ .inner {
62
+ /* position: relative;
63
+ top: 10px; */
64
+ margin: 15px 15px 30px 15px;
65
+ background-color: #fff;
66
+ padding: 15px;
67
+ box-shadow: 0 2px 8px -4px #555;
68
+ }
69
+
70
+ footer {
71
+ position: fixed;
72
+ padding-right: 15px;
73
+ z-index: 99;
74
+ height: 24px;
75
+ line-height: 24px;
76
+ font-size: smaller;
77
+ bottom: 0;
78
+ left: 0;
79
+ right: 0;
80
+ background-color: #fff;
81
+ border-top: 1px solid #eee;
82
+ color: #777;
83
+ text-align: right;
84
+ }
85
+
86
+ footer a {
87
+ color: #155cb5;
88
+ text-decoration: none;
89
+ }
90
+
91
+ header {
92
+ overflow: hidden;
93
+ border-bottom: 1px solid #e5e5e5;
94
+ margin-bottom: 15px;
95
+ }
96
+
97
+ h1 {
98
+ font-size: 28px;
99
+ margin-top: 5px;
100
+ margin-bottom: 10px;
101
+ font-weight: 100;
102
+ }
103
+
104
+ h2 {
105
+ font-weight: normal;
106
+ }
107
+ </style>
108
+
109
+ <title>Camunda - Internal Server Error</title>
110
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
111
+ </head>
112
+ <body>
113
+ <div class="navbar-header">
114
+ <a class="navbar-brand" href="#/" title="Camunda - Internal Server Error (500)">
115
+ <svg width="26" height="26" viewBox="0 0 26 26" class="logo"><path d="M13,0 C20.1797017,0 26,5.82029825 26,13 C26,20.1797017 20.1797017,26 13,26 C5.82029825,26 0,20.1797017 0,13 C0,5.82029825 5.82029825,0 13,0 Z M15.9924973,18.7781515 L9.99320872,18.7781515 L9.99320872,22.1683591 L15.9924973,22.1683591 L15.9924973,18.7781515 Z M13,3.83248173 C11.0249014,3.83248173 10.0058211,4.99702477 9.99320872,7.04527521 L9.99320872,7.04527521 L9.99320872,13.69284 L9.99685,13.8998115 C10.0647928,15.8025897 11.0827733,16.8913395 12.985706,16.8913395 C14.9608046,16.8913395 15.9773624,15.7267965 15.9924973,13.678546 L15.9924973,13.678546 L15.9924973,11.9834422 L14.0913912,11.9834422 L14.0913912,13.8105556 L14.0867571,13.9750837 C14.0405969,14.7638347 13.6523228,15.0490913 13.0445637,15.0490913 C12.4105815,15.0490913 11.9977362,14.7245327 11.9977362,13.8105556 L11.9977362,13.8105556 L11.9977362,6.89476748 L12.0023704,6.72991255 C12.0485306,5.93798383 12.4368047,5.62774885 13.0445637,5.64193778 C13.678546,5.64193778 14.0913912,5.99592523 14.0913912,6.90990233 L14.0913912,6.90990233 L14.0913912,8.28044758 L15.9924973,8.28044758 L15.9924973,7.04527521 L15.9888705,6.83655109 C15.9211931,4.91809617 14.9069918,3.83248173 13,3.83248173 Z"></path></svg>
116
+ <span class="brand-name ng-binding">Camunda</span>
117
+ </a>
118
+ </div>
119
+ <div class="main">
120
+ <div class="inner">
121
+ <header>
122
+ <h1>Internal Server Error (500)</h1>
123
+ </header>
124
+ <h2>An error occurred while processing your request.</h2>
125
+ <p>Try reloading the Page, or going back and attempting the action again.</div>
126
+ </div>
127
+ </div>
128
+ <footer>
129
+ Powered by <a href="http://camunda.org">Camunda Platform</a>
130
+ </footer>
131
+ </body>
132
+ </html>
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/main/webapp/index.html ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE HTML>
2
+ <html>
3
+ <head>
4
+ <title>Camunda Welcome</title>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6
+ <meta http-equiv="refresh" content="0;URL='app/welcome/'">
7
+ </head>
8
+ <body>
9
+
10
+ </body>
11
+ </html>
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/admin/plugin/base/AbstractAdminPluginTest.java ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.admin.plugin.base;
18
+
19
+ import org.apache.ibatis.logging.LogFactory;
20
+ import org.camunda.bpm.admin.Admin;
21
+ import org.camunda.bpm.admin.impl.DefaultAdminRuntimeDelegate;
22
+ import org.camunda.bpm.engine.ProcessEngine;
23
+ import org.camunda.bpm.engine.impl.util.LogUtil;
24
+ import org.camunda.bpm.engine.test.ProcessEngineRule;
25
+ import org.junit.After;
26
+ import org.junit.AfterClass;
27
+ import org.junit.Before;
28
+ import org.junit.BeforeClass;
29
+ import org.junit.Rule;
30
+
31
+ public abstract class AbstractAdminPluginTest {
32
+
33
+ protected static final TestAdminRuntimeDelegate RUNTIME_DELEGATE = new TestAdminRuntimeDelegate();
34
+
35
+ static {
36
+ LogUtil.readJavaUtilLoggingConfigFromClasspath();
37
+ LogFactory.useJdkLogging();
38
+ }
39
+
40
+ @Rule
41
+ public ProcessEngineRule processEngineRule = new ProcessEngineRule(true);
42
+
43
+ @BeforeClass
44
+ public static void beforeClass() {
45
+ Admin.setAdminRuntimeDelegate(RUNTIME_DELEGATE);
46
+ }
47
+
48
+ @AfterClass
49
+ public static void afterClass() {
50
+ Admin.setAdminRuntimeDelegate(null);
51
+ }
52
+
53
+ @Before
54
+ public void before() {
55
+ RUNTIME_DELEGATE.ENGINE = getProcessEngine();
56
+ }
57
+
58
+ @After
59
+ public void after() {
60
+ RUNTIME_DELEGATE.ENGINE = null;
61
+ getProcessEngine().getIdentityService().clearAuthentication();
62
+ }
63
+
64
+ public ProcessEngine getProcessEngine() {
65
+ return processEngineRule.getProcessEngine();
66
+ }
67
+
68
+ private static class TestAdminRuntimeDelegate extends DefaultAdminRuntimeDelegate {
69
+
70
+ public ProcessEngine ENGINE;
71
+
72
+ @Override
73
+ public ProcessEngine getProcessEngine(String processEngineName) {
74
+
75
+ // always return default engine for plugin tests
76
+ return ENGINE;
77
+ }
78
+ }
79
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/admin/plugin/base/MetricsRestServiceTest.java ADDED
@@ -0,0 +1,488 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.admin.plugin.base;
18
+
19
+ import org.assertj.core.groups.Tuple;
20
+ import org.camunda.bpm.admin.impl.plugin.resources.MetricsRestService;
21
+ import org.camunda.bpm.engine.ManagementService;
22
+ import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
23
+ import org.camunda.bpm.engine.impl.metrics.MetricsRegistry;
24
+ import org.camunda.bpm.engine.impl.metrics.reporter.DbMetricsReporter;
25
+ import org.camunda.bpm.engine.impl.persistence.entity.TaskMeterLogEntity;
26
+ import org.camunda.bpm.engine.impl.util.ClockUtil;
27
+ import org.camunda.bpm.engine.management.Metrics;
28
+ import org.camunda.bpm.engine.rest.exception.InvalidRequestException;
29
+ import org.joda.time.DateTime;
30
+ import org.junit.After;
31
+ import org.junit.Before;
32
+ import org.junit.Test;
33
+ import org.mockito.Mockito;
34
+
35
+ import javax.ws.rs.core.MultivaluedHashMap;
36
+ import javax.ws.rs.core.MultivaluedMap;
37
+ import javax.ws.rs.core.UriInfo;
38
+ import java.util.ArrayList;
39
+ import java.util.UUID;
40
+ import java.util.function.Consumer;
41
+
42
+ import static org.assertj.core.api.Assertions.assertThat;
43
+ import static org.assertj.core.api.Assertions.assertThatThrownBy;
44
+ import static org.assertj.core.api.Assertions.tuple;
45
+
46
+ public class MetricsRestServiceTest extends AbstractAdminPluginTest {
47
+
48
+ private final MultivaluedMap<String, String> queryParameters = new MultivaluedHashMap<>();
49
+ private MetricsRestService resource;
50
+ private UriInfo uriInfo;
51
+ private ManagementService managementService;
52
+ private DbMetricsReporter dbMetricsReporter;
53
+ private MetricsRegistry metricsRegistry;
54
+
55
+ @Before
56
+ public void setUp() throws Exception {
57
+ super.before();
58
+
59
+ var processEngine = getProcessEngine();
60
+ var processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
61
+ dbMetricsReporter = processEngineConfiguration.getDbMetricsReporter();
62
+ metricsRegistry = processEngineConfiguration.getMetricsRegistry();
63
+ managementService = processEngine.getManagementService();
64
+
65
+ resource = new MetricsRestService(processEngine.getName());
66
+
67
+ uriInfo = Mockito.mock(UriInfo.class);
68
+ Mockito.doReturn(queryParameters).when(uriInfo).getQueryParameters();
69
+ }
70
+
71
+ @After
72
+ public void tearDown() {
73
+ queryParameters.clear();
74
+ managementService.deleteMetrics(null);
75
+ managementService.deleteTaskMetrics(null);
76
+ ClockUtil.reset();
77
+ }
78
+
79
+ @Test
80
+ public void shouldThrowExceptionWhenSubscriptionStartDateNotProvided() {
81
+ // given
82
+ queryParameters.add("subscriptionStartDate", "");
83
+
84
+ // when
85
+ assertThatThrownBy(() -> resource.getAggregatedMetrics(uriInfo))
86
+ // then
87
+ .isInstanceOf(InvalidRequestException.class)
88
+ .hasMessage("subscriptionStartDate parameter has invalid value: null");
89
+ }
90
+
91
+ @Test
92
+ public void shouldThrowExceptionWhenSubscriptionStartDateInvalid() {
93
+ // given
94
+ queryParameters.add("subscriptionStartDate", "notDate");
95
+ queryParameters.add("groupBy", "month");
96
+
97
+ // when
98
+ assertThatThrownBy(() -> resource.getAggregatedMetrics(uriInfo))
99
+ // then
100
+ .isInstanceOf(InvalidRequestException.class)
101
+ .hasMessage(
102
+ "Cannot set query parameter 'subscriptionStartDate' to value 'notDate': Cannot convert value \"notDate\" to java type java.util.Date");
103
+ }
104
+
105
+ @Test
106
+ public void shouldThrowExceptionWhenSubscriptionStartDateNotInPast() {
107
+ // given
108
+ queryParameters.add("subscriptionStartDate", new DateTime().withYear(2100).withMonthOfYear(1).withDayOfMonth(31).toString());
109
+ queryParameters.add("groupBy", "month");
110
+
111
+ // when
112
+ assertThatThrownBy(() -> resource.getAggregatedMetrics(uriInfo))
113
+ // then
114
+ .isInstanceOf(InvalidRequestException.class)
115
+ .hasMessageStartingWith("subscriptionStartDate parameter has invalid value: Sun Jan 31");
116
+ }
117
+
118
+ @Test
119
+ public void shouldThrowExceptionWhenGroupByNotProvided() {
120
+ // given
121
+ queryParameters.add("subscriptionStartDate", "2024-01-01");
122
+
123
+ // when
124
+ assertThatThrownBy(() -> resource.getAggregatedMetrics(uriInfo))
125
+ // then
126
+ .isInstanceOf(InvalidRequestException.class).hasMessage("groupBy parameter has invalid value: null");
127
+ }
128
+
129
+ @Test
130
+ public void shouldThrowExceptionWhenGroupByInvalid() {
131
+ // given
132
+ queryParameters.add("subscriptionStartDate", "2024-01-01");
133
+ queryParameters.add("groupBy", "day");
134
+
135
+ // when
136
+ assertThatThrownBy(() -> resource.getAggregatedMetrics(uriInfo))
137
+ // then
138
+ .isInstanceOf(InvalidRequestException.class).hasMessage("groupBy parameter has invalid value: day");
139
+ }
140
+
141
+ @Test
142
+ public void shouldThrowExceptionWhenStartDateInvalid() {
143
+ // given
144
+ queryParameters.add("subscriptionStartDate", "2024-01-01");
145
+ queryParameters.add("startDate", "notDate");
146
+
147
+ // when
148
+ assertThatThrownBy(() -> resource.getAggregatedMetrics(uriInfo))
149
+ // then
150
+ .isInstanceOf(InvalidRequestException.class)
151
+ .hasMessage(
152
+ "Cannot set query parameter 'startDate' to value 'notDate': Cannot convert value \"notDate\" to java type java.util.Date");
153
+ }
154
+
155
+ @Test
156
+ public void shouldThrowExceptionWhenEndDateInvalid() {
157
+ // given
158
+ queryParameters.add("subscriptionStartDate", "2024-01-01");
159
+ queryParameters.add("endDate", "notDate");
160
+
161
+ // when
162
+ assertThatThrownBy(() -> resource.getAggregatedMetrics(uriInfo))
163
+ // then
164
+ .isInstanceOf(InvalidRequestException.class)
165
+ .hasMessage(
166
+ "Cannot set query parameter 'endDate' to value 'notDate': Cannot convert value \"notDate\" to java type java.util.Date");
167
+ }
168
+
169
+ @Test
170
+ public void shouldThrowExceptionWhenStartDateNotBeforeEndDate() {
171
+ // given
172
+ queryParameters.add("subscriptionStartDate", "2024-01-01");
173
+ queryParameters.add("startDate", "2023-01-31T16:54:00.000+0100");
174
+ queryParameters.add("endDate", "2023-01-31T16:54:00.000+0100");
175
+
176
+ // when
177
+ assertThatThrownBy(() -> resource.getAggregatedMetrics(uriInfo))
178
+ // then
179
+ .isInstanceOf(InvalidRequestException.class).hasMessage("endDate parameter must be after startDate");
180
+ }
181
+
182
+ @Test
183
+ public void shouldThrowExceptionWhenMetricsInvalid() {
184
+ // given
185
+ queryParameters.add("subscriptionStartDate", "2024-01-01");
186
+ queryParameters.add("groupBy", "month");
187
+ queryParameters.add("metrics", "a,process-instances");
188
+
189
+ // when
190
+ assertThatThrownBy(() -> resource.getAggregatedMetrics(uriInfo))
191
+ // then
192
+ .isInstanceOf(InvalidRequestException.class)
193
+ .hasMessage("Cannot set query parameter 'metrics' to value 'a,process-instances'");
194
+ }
195
+
196
+ @Test
197
+ public void shouldReturnAggregatedMetricsFilteredByMetricsParameter() {
198
+ // given
199
+ queryParameters.add("subscriptionStartDate", new DateTime().withYear(2020).withMonthOfYear(1).withDayOfMonth(1).toString());
200
+ queryParameters.add("groupBy", "year");
201
+ queryParameters.add("metrics", String.format("%s,%s", Metrics.PROCESS_INSTANCES, Metrics.FLOW_NODE_INSTANCES));
202
+
203
+ // generate metrics for all available meters
204
+ var metricNames = metricsRegistry.getDbMeters().keySet();
205
+ metricNames.forEach(metric -> metricsRegistry.markOccurrence(metric, 1));
206
+ dbMetricsReporter.reportNow();
207
+
208
+ // when
209
+ var actual = resource.getAggregatedMetrics(uriInfo);
210
+
211
+ // then - only the two selected metrics are returned
212
+ assertThat(actual).hasSize(2);
213
+ assertThat(actual).extracting("metric", "sum", "subscriptionYear", "subscriptionMonth")
214
+ .containsExactlyInAnyOrder(
215
+ tuple(Metrics.PROCESS_INSTANCES, 1L, new DateTime().getYear(), null),
216
+ tuple(Metrics.FLOW_NODE_INSTANCES, 1L, new DateTime().getYear(), null));
217
+ }
218
+
219
+ @Test
220
+ public void shouldReturnAggregatedMetricsFilteredByStartDateParameter() {
221
+ // given
222
+ queryParameters.add("subscriptionStartDate", new DateTime().withYear(2020).withMonthOfYear(1).withDayOfMonth(1).toString());
223
+ queryParameters.add("groupBy", "year");
224
+ queryParameters.add("startDate", "2022-01-01");
225
+ queryParameters.add("metrics", Metrics.PROCESS_INSTANCES);
226
+
227
+ // generate metrics for 2021 and current year
228
+ var dateTime = new DateTime().withYear(2021);
229
+ ClockUtil.setCurrentTime(dateTime.toDate());
230
+ metricsRegistry.markOccurrence(Metrics.ROOT_PROCESS_INSTANCE_START, 1);
231
+ dbMetricsReporter.reportNow();
232
+ ClockUtil.reset();
233
+ metricsRegistry.markOccurrence(Metrics.ROOT_PROCESS_INSTANCE_START, 1);
234
+ dbMetricsReporter.reportNow();
235
+
236
+ // when
237
+ var actual = resource.getAggregatedMetrics(uriInfo);
238
+
239
+ // then - the metric from 2021 is not returned
240
+ assertThat(actual).hasSize(1);
241
+ assertThat(actual).extracting("metric", "sum", "subscriptionYear", "subscriptionMonth")
242
+ .containsExactly(
243
+ tuple(Metrics.PROCESS_INSTANCES, 1L, new DateTime().getYear(), null));
244
+ }
245
+
246
+ @Test
247
+ public void shouldReturnAggregatedMetricsFilteredByEndDateParameter() {
248
+ // given
249
+ queryParameters.add("subscriptionStartDate", new DateTime().withYear(2020).withMonthOfYear(1).withDayOfMonth(1).toString());
250
+ queryParameters.add("groupBy", "year");
251
+ queryParameters.add("endDate", "2022-01-01");
252
+ queryParameters.add("metrics", Metrics.PROCESS_INSTANCES);
253
+
254
+ // generate metrics for 2021 and current year
255
+ var dateTime = new DateTime().withYear(2021);
256
+ ClockUtil.setCurrentTime(dateTime.toDate());
257
+ metricsRegistry.markOccurrence(Metrics.ROOT_PROCESS_INSTANCE_START, 1);
258
+ dbMetricsReporter.reportNow();
259
+ ClockUtil.reset();
260
+ metricsRegistry.markOccurrence(Metrics.ROOT_PROCESS_INSTANCE_START, 1);
261
+ dbMetricsReporter.reportNow();
262
+
263
+ // when
264
+ var actual = resource.getAggregatedMetrics(uriInfo);
265
+
266
+ // then - the metric from current year is not returned
267
+ assertThat(actual).hasSize(1);
268
+ assertThat(actual).extracting("metric", "sum", "subscriptionYear", "subscriptionMonth")
269
+ .containsExactly(
270
+ tuple(Metrics.PROCESS_INSTANCES, 1L, dateTime.getYear(), null));
271
+ }
272
+
273
+ @Test
274
+ public void shouldReturnAggregatedMetricsGroupedByMonth() {
275
+ // given
276
+ queryParameters.add("subscriptionStartDate", new DateTime().withYear(2020).withMonthOfYear(4).withDayOfMonth(15).toString());
277
+ queryParameters.add("groupBy", "month");
278
+ queryParameters.add("metrics", Metrics.PROCESS_INSTANCES);
279
+
280
+ // generate metrics for 2021-02-15T00:00:00.000+01:00 & 2021-02-14T23:59:59.999+01:00
281
+ var dateTime = new DateTime().withYear(2021)
282
+ .withMonthOfYear(2)
283
+ .withDayOfMonth(15)
284
+ .withTimeAtStartOfDay()
285
+ .minusMillis(1);
286
+ ClockUtil.setCurrentTime(dateTime.toDate());
287
+ metricsRegistry.markOccurrence(Metrics.ROOT_PROCESS_INSTANCE_START, 1);
288
+ dbMetricsReporter.reportNow();
289
+ dateTime = dateTime.withDayOfMonth(15).withTimeAtStartOfDay();
290
+ ClockUtil.setCurrentTime(dateTime.toDate());
291
+ metricsRegistry.markOccurrence(Metrics.ROOT_PROCESS_INSTANCE_START, 1);
292
+ dbMetricsReporter.reportNow();
293
+ ClockUtil.reset();
294
+
295
+ // when
296
+ var actual = resource.getAggregatedMetrics(uriInfo);
297
+
298
+ // then - metrics are grouped by months (Jan, Feb) with respect to the subscriptionStartDate
299
+ assertThat(actual).hasSize(2);
300
+ assertThat(actual).extracting("metric", "sum", "subscriptionYear", "subscriptionMonth")
301
+ .containsExactlyInAnyOrder(
302
+ tuple(Metrics.PROCESS_INSTANCES, 1L, dateTime.getYear(), 2),
303
+ tuple(Metrics.PROCESS_INSTANCES, 1L, dateTime.getYear(), 1));
304
+ }
305
+
306
+ @Test
307
+ public void shouldReturnAggregatedMetricsGroupedByYear() {
308
+ // given
309
+ queryParameters.add("subscriptionStartDate", new DateTime().withYear(2020).withMonthOfYear(4).withDayOfMonth(15).toString());
310
+ queryParameters.add("groupBy", "year");
311
+ queryParameters.add("metrics", Metrics.PROCESS_INSTANCES);
312
+
313
+ // generate metrics for 2021-04-15T00:00:00.000+01:00 & 2021-04-14T23:59:59.999+01:00
314
+ var dateTime = new DateTime().withYear(2021)
315
+ .withMonthOfYear(4)
316
+ .withDayOfMonth(15)
317
+ .withTimeAtStartOfDay()
318
+ .minusMillis(1);
319
+ ClockUtil.setCurrentTime(dateTime.toDate());
320
+ metricsRegistry.markOccurrence(Metrics.ROOT_PROCESS_INSTANCE_START, 1);
321
+ dbMetricsReporter.reportNow();
322
+ dateTime = dateTime.withDayOfMonth(15).withTimeAtStartOfDay();
323
+ ClockUtil.setCurrentTime(dateTime.toDate());
324
+ metricsRegistry.markOccurrence(Metrics.ROOT_PROCESS_INSTANCE_START, 1);
325
+ dbMetricsReporter.reportNow();
326
+ ClockUtil.reset();
327
+
328
+ // when
329
+ var actual = resource.getAggregatedMetrics(uriInfo);
330
+
331
+ // then - metrics are grouped by years (2020, 2021) with respect to the subscriptionStartDate
332
+ assertThat(actual).hasSize(2);
333
+ assertThat(actual).extracting("metric", "sum", "subscriptionYear", "subscriptionMonth")
334
+ .containsExactlyInAnyOrder(
335
+ tuple(Metrics.PROCESS_INSTANCES, 1L, dateTime.getYear(), null),
336
+ tuple(Metrics.PROCESS_INSTANCES, 1L, dateTime.minusYears(1).getYear(), null));
337
+ }
338
+
339
+ @Test
340
+ public void shouldReturnAnnualAggregatedMetricsForTU() {
341
+ // given
342
+ queryParameters.add("subscriptionStartDate", new DateTime().withYear(2020).withMonthOfYear(1).withDayOfMonth(1).toString());
343
+ queryParameters.add("groupBy", "year");
344
+ queryParameters.add("metrics", Metrics.TASK_USERS);
345
+
346
+ // generate TU metric - counts _unique_ task workers (unique ASSIGNEE_HASH_)
347
+ processEngineRule.getProcessEngineConfiguration().getCommandExecutorTxRequired().execute(commandContext -> {
348
+ commandContext.getMeterLogManager().insert(new TaskMeterLogEntity("assignee", ClockUtil.getCurrentTime()));
349
+ commandContext.getMeterLogManager().insert(new TaskMeterLogEntity("assignee", ClockUtil.getCurrentTime()));
350
+ ClockUtil.reset();
351
+ return null;
352
+ });
353
+
354
+ // when
355
+ var actual = resource.getAggregatedMetrics(uriInfo);
356
+
357
+ // then
358
+ assertThat(actual).hasSize(1);
359
+ assertThat(actual).extracting("metric", "sum", "subscriptionYear", "subscriptionMonth")
360
+ .containsExactly(
361
+ tuple(Metrics.TASK_USERS, 1L, new DateTime().getYear(), null));
362
+ }
363
+
364
+ @Test
365
+ public void shouldReturnMonthlyAggregatedMetricsForTU() {
366
+ // given
367
+ queryParameters.add("subscriptionStartDate", new DateTime().withYear(2020).withMonthOfYear(1).withDayOfMonth(1).toString());
368
+ queryParameters.add("startDate", "2023-01-01");
369
+ queryParameters.add("groupBy", "month");
370
+ queryParameters.add("metrics", Metrics.TASK_USERS);
371
+
372
+ // generate TU metric - counts _unique_ task workers (unique ASSIGNEE_HASH_) for the selected period (startDate, endDate)
373
+ DateTime now = new DateTime();
374
+ DateTime prevMonth = now.minusMonths(1);
375
+ processEngineRule.getProcessEngineConfiguration().getCommandExecutorTxRequired().execute(commandContext -> {
376
+ commandContext.getMeterLogManager().insert(new TaskMeterLogEntity("assignee1", ClockUtil.getCurrentTime()));
377
+ commandContext.getMeterLogManager().insert(new TaskMeterLogEntity("assignee3", ClockUtil.getCurrentTime()));
378
+
379
+ ClockUtil.setCurrentTime(prevMonth.toDate());
380
+ commandContext.getMeterLogManager().insert(new TaskMeterLogEntity("assignee1", ClockUtil.getCurrentTime()));
381
+ commandContext.getMeterLogManager().insert(new TaskMeterLogEntity("assignee2", ClockUtil.getCurrentTime()));
382
+
383
+ ClockUtil.setCurrentTime(now.withYear(2022).toDate());
384
+ commandContext.getMeterLogManager().insert(new TaskMeterLogEntity("assignee1", ClockUtil.getCurrentTime()));
385
+ ClockUtil.reset();
386
+ return null;
387
+ });
388
+
389
+ // when
390
+ var actual = resource.getAggregatedMetrics(uriInfo);
391
+
392
+ // then
393
+ assertThat(actual).hasSize(2);
394
+ assertThat(actual).extracting("metric", "sum", "subscriptionYear", "subscriptionMonth")
395
+ .containsExactlyInAnyOrder(
396
+ tuple(Metrics.TASK_USERS, 1L, now.getYear(), now.getMonthOfYear()),
397
+ tuple(Metrics.TASK_USERS, 2L, prevMonth.getYear(), prevMonth.getMonthOfYear()));
398
+ }
399
+
400
+ protected void generateMetrics(int year, int month, int times) {
401
+ var dateTime = new DateTime().withYear(year).withMonthOfYear(month).withDayOfMonth(10);
402
+
403
+ for (int i = 1; i <= times; i++) {
404
+ ClockUtil.setCurrentTime(dateTime.toDate());
405
+
406
+ metricsRegistry.markOccurrence(Metrics.ROOT_PROCESS_INSTANCE_START, i);
407
+ metricsRegistry.markOccurrence(Metrics.ACTIVTY_INSTANCE_START, i);
408
+ metricsRegistry.markOccurrence(Metrics.EXECUTED_DECISION_INSTANCES, i);
409
+ metricsRegistry.markOccurrence(Metrics.EXECUTED_DECISION_ELEMENTS, i);
410
+ dbMetricsReporter.reportNow();
411
+
412
+ int i1 = i;
413
+ processEngineRule.getProcessEngineConfiguration().getCommandExecutorTxRequired().execute(commandContext -> {
414
+ for (int j = 1; j <= i1; j++) {
415
+ commandContext.getMeterLogManager().insert(
416
+ new TaskMeterLogEntity(UUID.randomUUID().toString(), ClockUtil.getCurrentTime()));
417
+ }
418
+ return null;
419
+ });
420
+
421
+ dateTime = dateTime.minusDays(1);
422
+ }
423
+ ClockUtil.reset();
424
+ }
425
+
426
+ @Test
427
+ public void shouldReturnAggregatedMetricsByYear() {
428
+ // given
429
+ queryParameters.add("subscriptionStartDate", new DateTime().withYear(2020).withMonthOfYear(1).withDayOfMonth(1).toString());
430
+ queryParameters.add("groupBy", "year");
431
+
432
+ // generate metrics for last 5 days & last 3 years
433
+ generateMetrics(2024, 2, 2);
434
+ generateMetrics(2023, 2, 3);
435
+
436
+ // when
437
+ var actual = resource.getAggregatedMetrics(uriInfo);
438
+
439
+ // then
440
+ assertThat(actual).hasSize(10);
441
+ // generate tuples
442
+ var tuples = new ArrayList<Tuple>();
443
+ Consumer<String> generateAssertTuple = (String metric) -> {
444
+ tuples.add(tuple(metric, 3L, 2024, null));
445
+ tuples.add(tuple(metric, 6L, 2023, null));
446
+ };
447
+ generateAssertTuple.accept(Metrics.PROCESS_INSTANCES);
448
+ generateAssertTuple.accept(Metrics.FLOW_NODE_INSTANCES);
449
+ generateAssertTuple.accept(Metrics.DECISION_INSTANCES);
450
+ generateAssertTuple.accept(Metrics.EXECUTED_DECISION_ELEMENTS);
451
+ generateAssertTuple.accept(Metrics.TASK_USERS);
452
+
453
+ assertThat(actual).extracting("metric", "sum", "subscriptionYear", "subscriptionMonth")
454
+ .containsExactlyInAnyOrder(tuples.toArray(new Tuple[]{}));
455
+ }
456
+
457
+ @Test
458
+ public void shouldReturnAggregatedMetricsByMonth() {
459
+ // given
460
+ queryParameters.add("subscriptionStartDate", new DateTime().withYear(2020).withMonthOfYear(1).withDayOfMonth(1).toString());
461
+ queryParameters.add("groupBy", "month");
462
+
463
+ // generate metrics for last 5 days & last 3 years
464
+ generateMetrics(2024, 2, 2);
465
+ generateMetrics(2024, 1, 3);
466
+
467
+ // when
468
+ var actual = resource.getAggregatedMetrics(uriInfo);
469
+
470
+ // then
471
+ assertThat(actual).hasSize(10);
472
+ // generate tuples
473
+ var tuples = new ArrayList<Tuple>();
474
+ Consumer<String> generateAssertTuple = (String metric) -> {
475
+ tuples.add(tuple(metric, 3L, 2024, 2));
476
+ tuples.add(tuple(metric, 6L, 2024, 1));
477
+ };
478
+ generateAssertTuple.accept(Metrics.PROCESS_INSTANCES);
479
+ generateAssertTuple.accept(Metrics.FLOW_NODE_INSTANCES);
480
+ generateAssertTuple.accept(Metrics.DECISION_INSTANCES);
481
+ generateAssertTuple.accept(Metrics.EXECUTED_DECISION_ELEMENTS);
482
+ generateAssertTuple.accept(Metrics.TASK_USERS);
483
+
484
+ assertThat(actual).extracting("metric", "sum", "subscriptionYear", "subscriptionMonth")
485
+ .containsExactlyInAnyOrder(tuples.toArray(new Tuple[]{}));
486
+ }
487
+
488
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/IncidentRestServiceTest.java ADDED
@@ -0,0 +1,533 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.cockpit.plugin.base;
18
+
19
+ import static junit.framework.TestCase.fail;
20
+ import static org.assertj.core.api.Assertions.assertThat;
21
+
22
+ import java.util.List;
23
+
24
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.IncidentDto;
25
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.query.IncidentQueryDto;
26
+ import org.camunda.bpm.cockpit.impl.plugin.resources.IncidentRestService;
27
+ import org.camunda.bpm.cockpit.plugin.test.AbstractCockpitPluginTest;
28
+ import org.camunda.bpm.engine.BadUserRequestException;
29
+ import org.camunda.bpm.engine.IdentityService;
30
+ import org.camunda.bpm.engine.ProcessEngine;
31
+ import org.camunda.bpm.engine.RepositoryService;
32
+ import org.camunda.bpm.engine.RuntimeService;
33
+ import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
34
+ import org.camunda.bpm.engine.runtime.Incident;
35
+ import org.camunda.bpm.engine.runtime.ProcessInstance;
36
+ import org.camunda.bpm.engine.test.Deployment;
37
+ import org.junit.After;
38
+ import org.junit.Before;
39
+ import org.junit.Test;
40
+
41
+ /**
42
+ * @author roman.smirnov
43
+ */
44
+ public class IncidentRestServiceTest extends AbstractCockpitPluginTest {
45
+
46
+ private ProcessEngine processEngine;
47
+ protected ProcessEngineConfigurationImpl processEngineConfiguration;
48
+ private RepositoryService repositoryService;
49
+ private RuntimeService runtimeService;
50
+ private IncidentRestService resource;
51
+ protected IdentityService identityService;
52
+
53
+ @Before
54
+ public void setUp() throws Exception {
55
+ super.before();
56
+
57
+ processEngine = getProcessEngine();
58
+ processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine
59
+ .getProcessEngineConfiguration();
60
+ repositoryService = processEngine.getRepositoryService();
61
+ runtimeService = processEngine.getRuntimeService();
62
+ identityService = processEngine.getIdentityService();
63
+
64
+ resource = new IncidentRestService(processEngine.getName());
65
+ }
66
+
67
+ @After
68
+ public void clearAuthentication() {
69
+ identityService.clearAuthentication();
70
+ }
71
+
72
+ @After
73
+ public void resetQueryMaxResultsLimit() {
74
+ processEngineConfiguration.setQueryMaxResultsLimit(Integer.MAX_VALUE);
75
+ }
76
+
77
+ @Test
78
+ @Deployment(resources = {
79
+ "processes/failing-process.bpmn"
80
+ })
81
+ public void testQueryByProcessInstanceId() {
82
+ ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("FailingProcess");
83
+ runtimeService.startProcessInstanceByKey("FailingProcess");
84
+
85
+ executeAvailableJobs();
86
+
87
+ String incidentId = runtimeService.createIncidentQuery().processInstanceId(processInstance1.getId()).singleResult().getId();
88
+
89
+ runtimeService.setAnnotationForIncidentById(incidentId, "an Annotation");
90
+
91
+ String[] processInstanceIds= {processInstance1.getId()};
92
+
93
+ IncidentQueryDto queryParameter = new IncidentQueryDto();
94
+ queryParameter.setProcessInstanceIdIn(processInstanceIds);
95
+
96
+ List<IncidentDto> result = resource.queryIncidents(queryParameter, null, null);
97
+ assertThat(result).isNotEmpty();
98
+ assertThat(result).hasSize(1);
99
+
100
+ IncidentDto incident = result.get(0);
101
+
102
+ assertThat(incident.getId()).isNotNull();
103
+ assertThat(incident.getIncidentType()).isEqualTo(Incident.FAILED_JOB_HANDLER_TYPE);
104
+ assertThat(incident.getIncidentMessage()).isEqualTo("I am failing!");
105
+ assertThat(incident.getIncidentTimestamp()).isNotNull();
106
+ assertThat(incident.getActivityId()).isEqualTo("ServiceTask_1");
107
+ assertThat(incident.getFailedActivityId()).isEqualTo("ServiceTask_1");
108
+ assertThat(incident.getProcessInstanceId()).isEqualTo(processInstance1.getId());
109
+ assertThat(incident.getProcessDefinitionId()).isEqualTo(processInstance1.getProcessDefinitionId());
110
+ assertThat(incident.getExecutionId()).isEqualTo(processInstance1.getId());
111
+ assertThat(incident.getConfiguration()).isNotNull();
112
+ assertThat(incident.getAnnotation()).isEqualTo("an Annotation");
113
+ assertThat(incident.getCauseIncidentId()).isEqualTo(incident.getId());
114
+ assertThat(incident.getCauseIncidentProcessInstanceId()).isEqualTo(processInstance1.getId());
115
+ assertThat(incident.getCauseIncidentProcessDefinitionId()).isEqualTo(processInstance1.getProcessDefinitionId());
116
+ assertThat(incident.getCauseIncidentActivityId()).isEqualTo("ServiceTask_1");
117
+ assertThat(incident.getCauseIncidentFailedActivityId()).isEqualTo("ServiceTask_1");
118
+ assertThat(incident.getRootCauseIncidentId()).isEqualTo(incident.getId());
119
+ assertThat(incident.getRootCauseIncidentProcessInstanceId()).isEqualTo(processInstance1.getId());
120
+ assertThat(incident.getRootCauseIncidentProcessDefinitionId()).isEqualTo(processInstance1.getProcessDefinitionId());
121
+ assertThat(incident.getRootCauseIncidentActivityId()).isEqualTo("ServiceTask_1");
122
+ assertThat(incident.getRootCauseIncidentFailedActivityId()).isEqualTo("ServiceTask_1");
123
+ assertThat(incident.getRootCauseIncidentConfiguration()).isNotNull();
124
+ assertThat(incident.getRootCauseIncidentMessage()).isEqualTo("I am failing!");
125
+ }
126
+
127
+ @Test
128
+ @Deployment(resources = {
129
+ "processes/failing-process.bpmn"
130
+ })
131
+ public void testQueryByProcessInstanceIds() {
132
+ ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("FailingProcess");
133
+ ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("FailingProcess");
134
+
135
+ executeAvailableJobs();
136
+
137
+ String[] processInstanceIds= {processInstance1.getId(), processInstance2.getId()};
138
+
139
+ IncidentQueryDto queryParameter = new IncidentQueryDto();
140
+ queryParameter.setProcessInstanceIdIn(processInstanceIds);
141
+
142
+ List<IncidentDto> result = resource.queryIncidents(queryParameter, null, null);
143
+ assertThat(result).isNotEmpty();
144
+ assertThat(result).hasSize(2);
145
+ }
146
+
147
+ @Test
148
+ @Deployment(resources = {
149
+ "processes/process-with-two-parallel-failing-services.bpmn"
150
+ })
151
+ public void testQueryByActivityId() {
152
+ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processWithTwoParallelFailingServices");
153
+
154
+ executeAvailableJobs();
155
+
156
+ String[] activityIds= {"theServiceTask1"};
157
+
158
+ IncidentQueryDto queryParameter = new IncidentQueryDto();
159
+ queryParameter.setActivityIdIn(activityIds);
160
+
161
+ List<IncidentDto> result = resource.queryIncidents(queryParameter, null, null);
162
+ assertThat(result).isNotEmpty();
163
+ assertThat(result).hasSize(1);
164
+
165
+ IncidentDto incident = result.get(0);
166
+
167
+ assertThat(incident.getId()).isNotNull();
168
+ assertThat(incident.getIncidentType()).isEqualTo(Incident.FAILED_JOB_HANDLER_TYPE);
169
+ assertThat(incident.getIncidentMessage()).isEqualTo("I am failing!");
170
+ assertThat(incident.getIncidentTimestamp()).isNotNull();
171
+ assertThat(incident.getActivityId()).isEqualTo("theServiceTask1");
172
+ assertThat(incident.getFailedActivityId()).isEqualTo("theServiceTask1");
173
+ assertThat(incident.getProcessInstanceId()).isEqualTo(processInstance.getId());
174
+ assertThat(incident.getProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId());
175
+ assertThat(incident.getExecutionId()).isNotNull();
176
+ assertThat(incident.getConfiguration()).isNotNull();
177
+ assertThat(incident.getCauseIncidentId()).isEqualTo(incident.getId());
178
+ assertThat(incident.getCauseIncidentProcessInstanceId()).isEqualTo(processInstance.getId());
179
+ assertThat(incident.getCauseIncidentProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId());
180
+ assertThat(incident.getCauseIncidentActivityId()).isEqualTo("theServiceTask1");
181
+ assertThat(incident.getCauseIncidentFailedActivityId()).isEqualTo("theServiceTask1");
182
+ assertThat(incident.getRootCauseIncidentId()).isEqualTo(incident.getId());
183
+ assertThat(incident.getRootCauseIncidentProcessInstanceId()).isEqualTo(processInstance.getId());
184
+ assertThat(incident.getRootCauseIncidentProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId());
185
+ assertThat(incident.getRootCauseIncidentActivityId()).isEqualTo("theServiceTask1");
186
+ assertThat(incident.getRootCauseIncidentFailedActivityId()).isEqualTo("theServiceTask1");
187
+ assertThat(incident.getRootCauseIncidentConfiguration()).isNotNull();
188
+ assertThat(incident.getRootCauseIncidentMessage()).isEqualTo("I am failing!");
189
+ }
190
+
191
+ @Test
192
+ @Deployment(resources = {
193
+ "processes/process-with-two-parallel-failing-services.bpmn"
194
+ })
195
+ public void testQueryByActivityIds() {
196
+ runtimeService.startProcessInstanceByKey("processWithTwoParallelFailingServices");
197
+
198
+ executeAvailableJobs();
199
+
200
+ String[] activityIds= {"theServiceTask1", "theServiceTask2"};
201
+
202
+ IncidentQueryDto queryParameter = new IncidentQueryDto();
203
+ queryParameter.setActivityIdIn(activityIds);
204
+
205
+ List<IncidentDto> result = resource.queryIncidents(queryParameter, null, null);
206
+ assertThat(result).isNotEmpty();
207
+ assertThat(result).hasSize(2);
208
+ }
209
+
210
+ @Test
211
+ @Deployment(resources = {
212
+ "processes/failing-process.bpmn"
213
+ })
214
+ public void testQueryByProcessInstanceIdAndActivityId() {
215
+ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("FailingProcess");
216
+
217
+ executeAvailableJobs();
218
+
219
+ String[] processInstanceIds= {processInstance.getId()};
220
+ String[] activityIds= {"ServiceTask_1"};
221
+
222
+ IncidentQueryDto queryParameter = new IncidentQueryDto();
223
+ queryParameter.setProcessInstanceIdIn(processInstanceIds);
224
+ queryParameter.setActivityIdIn(activityIds);
225
+
226
+ List<IncidentDto> result = resource.queryIncidents(queryParameter, null, null);
227
+ assertThat(result).isNotEmpty();
228
+ assertThat(result).hasSize(1);
229
+ }
230
+
231
+ @Test
232
+ @Deployment(resources = {
233
+ "processes/failing-process.bpmn",
234
+ "processes/process-with-two-parallel-failing-services.bpmn"
235
+ })
236
+ public void testQueryByProcessInstanceIdAndActivityId_ShouldReturnEmptyList() {
237
+ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("FailingProcess");
238
+ runtimeService.startProcessInstanceByKey("processWithTwoParallelFailingServices");
239
+
240
+ executeAvailableJobs();
241
+
242
+ String[] processInstanceIds= {processInstance.getId()};
243
+ String[] activityIds= {"theServiceTask1"}; // is an activity id in "processWithTwoParallelFailingServices"
244
+
245
+ IncidentQueryDto queryParameter = new IncidentQueryDto();
246
+ queryParameter.setProcessInstanceIdIn(processInstanceIds);
247
+ queryParameter.setActivityIdIn(activityIds);
248
+
249
+ List<IncidentDto> result = resource.queryIncidents(queryParameter, null, null);
250
+
251
+ assertThat(result).isEmpty();
252
+ }
253
+
254
+ @Test
255
+ @Deployment(resources = {
256
+ "processes/failing-process.bpmn",
257
+ "processes/call-activity.bpmn",
258
+ "processes/nested-call-activity.bpmn"
259
+ })
260
+ public void testQueryWithNestedIncidents() {
261
+ ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("NestedCallActivity");
262
+
263
+ executeAvailableJobs();
264
+
265
+ ProcessInstance processInstance2 = runtimeService.createProcessInstanceQuery().processDefinitionKey("CallActivity").singleResult();
266
+ ProcessInstance processInstance3 = runtimeService.createProcessInstanceQuery().processDefinitionKey("FailingProcess").singleResult();
267
+
268
+ String[] processInstanceIds= {processInstance1.getId()};
269
+
270
+ IncidentQueryDto queryParameter = new IncidentQueryDto();
271
+ queryParameter.setProcessInstanceIdIn(processInstanceIds);
272
+
273
+ List<IncidentDto> result = resource.queryIncidents(queryParameter, null, null);
274
+ assertThat(result).isNotEmpty();
275
+ assertThat(result).hasSize(1);
276
+
277
+ IncidentDto incident = result.get(0);
278
+
279
+ assertThat(incident.getId()).isNotNull();
280
+ assertThat(incident.getIncidentType()).isEqualTo(Incident.FAILED_JOB_HANDLER_TYPE);
281
+ assertThat(incident.getIncidentMessage()).isNull();
282
+ assertThat(incident.getIncidentTimestamp()).isNotNull();
283
+ assertThat(incident.getActivityId()).isEqualTo("CallActivity_1");
284
+ assertThat(incident.getFailedActivityId()).isEqualTo("CallActivity_1");
285
+ assertThat(incident.getProcessInstanceId()).isEqualTo(processInstance1.getId());
286
+ assertThat(incident.getProcessDefinitionId()).isEqualTo(processInstance1.getProcessDefinitionId());
287
+ assertThat(incident.getExecutionId()).isNotNull();
288
+ assertThat(incident.getConfiguration()).isNull();
289
+
290
+ assertThat(incident.getCauseIncidentId()).isNotEqualTo(incident.getId());
291
+ assertThat(incident.getCauseIncidentProcessInstanceId()).isEqualTo(processInstance2.getId());
292
+ assertThat(incident.getCauseIncidentProcessDefinitionId()).isEqualTo(processInstance2.getProcessDefinitionId());
293
+ assertThat(incident.getCauseIncidentActivityId()).isEqualTo("CallActivity_1");
294
+ assertThat(incident.getCauseIncidentFailedActivityId()).isEqualTo("CallActivity_1");
295
+
296
+ assertThat(incident.getRootCauseIncidentId()).isNotEqualTo(incident.getId());
297
+ assertThat(incident.getRootCauseIncidentProcessInstanceId()).isEqualTo(processInstance3.getId());
298
+ assertThat(incident.getRootCauseIncidentProcessDefinitionId()).isEqualTo(processInstance3.getProcessDefinitionId());
299
+ assertThat(incident.getRootCauseIncidentActivityId()).isEqualTo("ServiceTask_1");
300
+ assertThat(incident.getRootCauseIncidentFailedActivityId()).isEqualTo("ServiceTask_1");
301
+ assertThat(incident.getRootCauseIncidentConfiguration()).isNotNull();
302
+ assertThat(incident.getRootCauseIncidentMessage()).isEqualTo("I am failing!");
303
+ }
304
+
305
+ @Test
306
+ @Deployment(resources = {
307
+ "processes/process-with-two-parallel-failing-services.bpmn"
308
+ })
309
+ public void testQueryPaginiation() {
310
+ runtimeService.startProcessInstanceByKey("processWithTwoParallelFailingServices");
311
+
312
+ executeAvailableJobs();
313
+
314
+ IncidentQueryDto queryParameter = new IncidentQueryDto();
315
+
316
+ List<IncidentDto> result = resource.queryIncidents(queryParameter, 0, 2);
317
+ assertThat(result).isNotEmpty();
318
+ assertThat(result).hasSize(2);
319
+
320
+ result = resource.queryIncidents(queryParameter, 2, 1);
321
+ assertThat(result).isNotEmpty();
322
+ assertThat(result).hasSize(1);
323
+
324
+ result = resource.queryIncidents(queryParameter, 4, null);
325
+ assertThat(result).isNotEmpty();
326
+ assertThat(result).hasSize(6);
327
+
328
+ result = resource.queryIncidents(queryParameter, null, 4);
329
+ assertThat(result).isNotEmpty();
330
+ assertThat(result).hasSize(4);
331
+ }
332
+
333
+ @Test
334
+ @Deployment(resources = {
335
+ "processes/failing-process.bpmn",
336
+ "processes/call-activity.bpmn",
337
+ "processes/nested-call-activity.bpmn"
338
+ })
339
+ public void testQueryByProcessDefinitionId() {
340
+ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("NestedCallActivity");
341
+
342
+ executeAvailableJobs();
343
+
344
+ String[] processDefinitionIds = { processInstance.getProcessDefinitionId() };
345
+
346
+ IncidentQueryDto queryParameter = new IncidentQueryDto();
347
+ queryParameter.setProcessDefinitionIdIn(processDefinitionIds);
348
+
349
+ List<IncidentDto> result = resource.queryIncidents(queryParameter, null, null);
350
+ assertThat(result).isNotEmpty();
351
+ assertThat(result).hasSize(1);
352
+
353
+ IncidentDto incident = result.get(0);
354
+
355
+ assertThat(incident.getId()).isNotNull();
356
+ assertThat(incident.getIncidentType()).isEqualTo(Incident.FAILED_JOB_HANDLER_TYPE);
357
+ assertThat(incident.getIncidentMessage()).isNull();
358
+ assertThat(incident.getIncidentTimestamp()).isNotNull();
359
+ assertThat(incident.getActivityId()).isEqualTo("CallActivity_1");
360
+ assertThat(incident.getFailedActivityId()).isEqualTo("CallActivity_1");
361
+ assertThat(incident.getProcessInstanceId()).isEqualTo(processInstance.getId());
362
+ assertThat(incident.getProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId());
363
+ assertThat(incident.getExecutionId()).isNotNull();
364
+ assertThat(incident.getConfiguration()).isNull();
365
+ }
366
+
367
+ @Test
368
+ @Deployment(resources = {
369
+ "processes/failing-process.bpmn",
370
+ "processes/call-activity.bpmn",
371
+ "processes/nested-call-activity.bpmn"
372
+ })
373
+ public void testQueryByProcessDefinitionIds() {
374
+ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("NestedCallActivity");
375
+
376
+ executeAvailableJobs();
377
+
378
+ String processDefinition2 = repositoryService.createProcessDefinitionQuery().processDefinitionKey("CallActivity").singleResult().getId();
379
+
380
+ String[] processDefinitionIds = { processInstance.getProcessDefinitionId(), processDefinition2 };
381
+
382
+ IncidentQueryDto queryParameter = new IncidentQueryDto();
383
+ queryParameter.setProcessDefinitionIdIn(processDefinitionIds);
384
+
385
+ List<IncidentDto> result = resource.queryIncidents(queryParameter, null, null);
386
+ assertThat(result).isNotEmpty();
387
+ assertThat(result).hasSize(2);
388
+ }
389
+
390
+ @Test
391
+ @Deployment(resources = {
392
+ "processes/failing-process.bpmn",
393
+ "processes/call-activity.bpmn",
394
+ "processes/nested-call-activity.bpmn"
395
+ })
396
+ public void testQuerySorting() {
397
+ runtimeService.startProcessInstanceByKey("NestedCallActivity");
398
+
399
+ executeAvailableJobs();
400
+
401
+ // asc
402
+ verifySorting("incidentMessage", "asc", 3);
403
+ verifySorting("incidentTimestamp", "asc", 3);
404
+ verifySorting("incidentType", "asc", 3);
405
+ verifySorting("activityId", "asc", 3);
406
+ verifySorting("causeIncidentProcessInstanceId", "asc", 3);
407
+ verifySorting("rootCauseIncidentProcessInstanceId", "asc", 3);
408
+
409
+ // desc
410
+ verifySorting("incidentMessage", "desc", 3);
411
+ verifySorting("incidentTimestamp", "desc", 3);
412
+ verifySorting("incidentType", "desc", 3);
413
+ verifySorting("activityId", "desc", 3);
414
+ verifySorting("causeIncidentProcessInstanceId", "desc", 3);
415
+ verifySorting("rootCauseIncidentProcessInstanceId", "desc", 3);
416
+ }
417
+
418
+ @Test
419
+ @Deployment(resources = "processes/simple-user-task-process.bpmn")
420
+ public void testQuerySortingByIncidentMessage()
421
+ {
422
+ // given
423
+ ProcessInstance instance = runtimeService.startProcessInstanceByKey("simpleUserTaskProcess");
424
+ Incident incident1 = runtimeService.createIncident("foo", instance.getId(), null, "message1");
425
+ Incident incident2 = runtimeService.createIncident("foo", instance.getId(), null, "message3");
426
+ Incident incident3 = runtimeService.createIncident("foo", instance.getId(), null, "message2");
427
+
428
+ // when
429
+ List<IncidentDto> ascending = queryIncidents("incidentMessage", "asc");
430
+ List<IncidentDto> descending = queryIncidents("incidentMessage", "desc");
431
+
432
+ // then
433
+ assertThat(ascending).extracting("id").containsExactly(incident1.getId(), incident3.getId(), incident2.getId());
434
+ assertThat(descending).extracting("id").containsExactly(incident2.getId(), incident3.getId(), incident1.getId());
435
+ }
436
+
437
+ @Test
438
+ public void shouldReturnPaginatedResult() {
439
+ // given
440
+ processEngineConfiguration.setQueryMaxResultsLimit(10);
441
+
442
+ identityService.setAuthenticatedUserId("foo");
443
+
444
+ try {
445
+ // when
446
+ resource.queryIncidents(new IncidentQueryDto(), 0, 10);
447
+ // then: no exception expected
448
+ } catch (BadUserRequestException e) {
449
+ // then
450
+ fail("No exception expected");
451
+ }
452
+ }
453
+
454
+ @Test
455
+ public void shouldReturnUnboundedResult_NotAuthenticated() {
456
+ // given
457
+ processEngineConfiguration.setQueryMaxResultsLimit(10);
458
+
459
+ try {
460
+ // when
461
+ resource.queryIncidents(new IncidentQueryDto(), null, null);
462
+ // then: no exception expected
463
+ } catch (BadUserRequestException e) {
464
+ // then
465
+ fail("No exception expected");
466
+ }
467
+ }
468
+
469
+ @Test
470
+ public void shouldReturnUnboundedResult_NoLimitConfigured() {
471
+ // given
472
+ identityService.setAuthenticatedUserId("foo");
473
+
474
+ try {
475
+ // when
476
+ resource.queryIncidents(new IncidentQueryDto(), null, null);
477
+ // then: no exception expected
478
+ } catch (BadUserRequestException e) {
479
+ // then
480
+ fail("No exception expected");
481
+ }
482
+ }
483
+
484
+ @Test
485
+ public void shouldThrowExceptionWhenMaxResultsLimitExceeded() {
486
+ // given
487
+ processEngineConfiguration.setQueryMaxResultsLimit(10);
488
+
489
+ identityService.setAuthenticatedUserId("foo");
490
+
491
+ try {
492
+ // when
493
+ resource.queryIncidents(new IncidentQueryDto(), 0, 11);
494
+ fail("Exception expected!");
495
+ } catch (BadUserRequestException e) {
496
+ // then
497
+ assertThat(e).hasMessage("Max results limit of 10 exceeded!");
498
+ }
499
+ }
500
+
501
+ @Test
502
+ public void shouldThrowExceptionWhenQueryUnbounded() {
503
+ // given
504
+ processEngineConfiguration.setQueryMaxResultsLimit(10);
505
+
506
+ identityService.setAuthenticatedUserId("foo");
507
+
508
+ try {
509
+ // when
510
+ resource.queryIncidents(new IncidentQueryDto(), null, null);
511
+ fail("Exception expected!");
512
+ } catch (BadUserRequestException e) {
513
+ // then
514
+ assertThat(e).hasMessage("An unbound number of results is forbidden!");
515
+ }
516
+ }
517
+
518
+ protected List<IncidentDto> queryIncidents(String sorting, String order)
519
+ {
520
+ IncidentQueryDto queryParameter = new IncidentQueryDto();
521
+ queryParameter.setSortBy(sorting);
522
+ queryParameter.setSortOrder(order);
523
+
524
+ return resource.queryIncidents(queryParameter, null, null);
525
+ }
526
+
527
+ protected void verifySorting(String sortBy, String sortOrder, int expectedResult) {
528
+ List<IncidentDto> result = queryIncidents(sortBy, sortOrder);
529
+ assertThat(result).isNotEmpty();
530
+ assertThat(result).hasSize(expectedResult);
531
+ }
532
+
533
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/PluginQueryTest.java ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.cockpit.plugin.base;
18
+
19
+ import static org.assertj.core.api.Assertions.assertThat;
20
+
21
+ import java.util.List;
22
+
23
+ import org.camunda.bpm.cockpit.db.QueryParameters;
24
+ import org.camunda.bpm.cockpit.plugin.test.AbstractCockpitPluginTest;
25
+ import org.camunda.bpm.engine.runtime.Execution;
26
+ import org.junit.Test;
27
+
28
+ /**
29
+ *
30
+ * @author nico.rehwaldt
31
+ */
32
+ public class PluginQueryTest extends AbstractCockpitPluginTest {
33
+
34
+ @Test
35
+ public void testCustomQuery() {
36
+
37
+ List<Execution> result = getQueryService().executeQuery("cockpit.base.selectProcessDefinitionWithFailedJobs", new QueryParameters());
38
+
39
+ assertThat(result).hasSize(0);
40
+ }
41
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/ProcessDefinitionResourceTest.java ADDED
@@ -0,0 +1,683 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.cockpit.plugin.base;
18
+
19
+ import static junit.framework.TestCase.fail;
20
+ import static org.camunda.bpm.engine.rest.dto.ConditionQueryParameterDto.EQUALS_OPERATOR_NAME;
21
+ import static org.camunda.bpm.engine.rest.dto.ConditionQueryParameterDto.LIKE_OPERATOR_NAME;
22
+ import static org.camunda.bpm.engine.rest.dto.ConditionQueryParameterDto.NOT_EQUALS_OPERATOR_NAME;
23
+ import static org.assertj.core.api.Assertions.assertThat;
24
+
25
+ import java.util.Arrays;
26
+ import java.util.HashMap;
27
+ import java.util.List;
28
+ import java.util.Map;
29
+
30
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.ProcessDefinitionDto;
31
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.query.ProcessDefinitionQueryDto;
32
+ import org.camunda.bpm.cockpit.impl.plugin.base.sub.resources.ProcessDefinitionResource;
33
+ import org.camunda.bpm.cockpit.plugin.test.AbstractCockpitPluginTest;
34
+ import org.camunda.bpm.engine.BadUserRequestException;
35
+ import org.camunda.bpm.engine.IdentityService;
36
+ import org.camunda.bpm.engine.ProcessEngine;
37
+ import org.camunda.bpm.engine.RepositoryService;
38
+ import org.camunda.bpm.engine.RuntimeService;
39
+ import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
40
+ import org.camunda.bpm.engine.impl.db.sql.DbSqlSessionFactory;
41
+ import org.camunda.bpm.engine.impl.test.RequiredDatabase;
42
+ import org.camunda.bpm.engine.repository.ProcessDefinition;
43
+ import org.camunda.bpm.engine.rest.dto.VariableQueryParameterDto;
44
+ import org.camunda.bpm.engine.runtime.ProcessInstance;
45
+ import org.camunda.bpm.engine.test.Deployment;
46
+ import org.junit.After;
47
+ import org.junit.Assert;
48
+ import org.junit.Before;
49
+ import org.junit.Test;
50
+
51
+ public class ProcessDefinitionResourceTest extends AbstractCockpitPluginTest {
52
+
53
+ private ProcessEngine processEngine;
54
+ protected ProcessEngineConfigurationImpl processEngineConfiguration;
55
+ private RuntimeService runtimeService;
56
+ private RepositoryService repositoryService;
57
+ private ProcessDefinitionResource resource;
58
+ protected IdentityService identityService;
59
+
60
+ @Before
61
+ public void setUp() throws Exception {
62
+ super.before();
63
+
64
+ processEngine = getProcessEngine();
65
+ processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine
66
+ .getProcessEngineConfiguration();
67
+
68
+ runtimeService = processEngine.getRuntimeService();
69
+ repositoryService = processEngine.getRepositoryService();
70
+ identityService = processEngine.getIdentityService();
71
+ }
72
+
73
+ @After
74
+ public void clearAuthentication() {
75
+ identityService.clearAuthentication();
76
+ }
77
+
78
+ @After
79
+ public void resetQueryMaxResultsLimit() {
80
+ processEngineConfiguration.setQueryMaxResultsLimit(Integer.MAX_VALUE);
81
+ }
82
+
83
+ @Test
84
+ @Deployment(resources = {
85
+ "processes/user-task-process.bpmn",
86
+ "processes/calling-user-task-process.bpmn"
87
+ })
88
+ public void testCalledProcessDefinitionByParentProcessDefinitionId() {
89
+ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("CallingUserTaskProcess");
90
+
91
+ resource = new ProcessDefinitionResource(getProcessEngine().getName(), processInstance.getProcessDefinitionId());
92
+
93
+ ProcessDefinition userTaskProcess = repositoryService.createProcessDefinitionQuery()
94
+ .processDefinitionKey("userTaskProcess")
95
+ .singleResult();
96
+
97
+ ProcessDefinitionQueryDto queryParameter = new ProcessDefinitionQueryDto();
98
+
99
+ List<ProcessDefinitionDto> result = resource.queryCalledProcessDefinitions(queryParameter);
100
+ assertThat(result).isNotEmpty();
101
+ assertThat(result).hasSize(1);
102
+
103
+ ProcessDefinitionDto dto = result.get(0);
104
+
105
+ assertThat(dto.getId()).isEqualTo(userTaskProcess.getId());
106
+ assertThat(dto.getKey()).isEqualTo(userTaskProcess.getKey());
107
+ assertThat(dto.getName()).isEqualTo(userTaskProcess.getName());
108
+ assertThat(dto.getVersion()).isEqualTo(userTaskProcess.getVersion());
109
+ assertThat(dto.getCalledFromActivityIds()).hasSize(1);
110
+
111
+ String calledFrom = dto.getCalledFromActivityIds().get(0);
112
+
113
+ assertThat(calledFrom).isEqualTo("CallActivity_1");
114
+
115
+ }
116
+
117
+ @Test
118
+ @Deployment(resources = {
119
+ "processes/user-task-process.bpmn",
120
+ "processes/two-parallel-call-activities-calling-same-process.bpmn"
121
+ })
122
+ public void testCalledProcessDefinitionByParentProcessDefinitionIdWithTwoActivityCallingSameProcess() {
123
+ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("TwoParallelCallActivitiesCallingSameProcess");
124
+
125
+ resource = new ProcessDefinitionResource(getProcessEngine().getName(), processInstance.getProcessDefinitionId());
126
+
127
+ ProcessDefinition userTaskProcess = repositoryService.createProcessDefinitionQuery()
128
+ .processDefinitionKey("userTaskProcess")
129
+ .singleResult();
130
+
131
+ ProcessDefinitionQueryDto queryParameter = new ProcessDefinitionQueryDto();
132
+
133
+ List<ProcessDefinitionDto> result = resource.queryCalledProcessDefinitions(queryParameter);
134
+ assertThat(result).isNotEmpty();
135
+ assertThat(result).hasSize(1);
136
+
137
+ ProcessDefinitionDto dto = result.get(0);
138
+
139
+ assertThat(dto.getId()).isEqualTo(userTaskProcess.getId());
140
+ assertThat(dto.getKey()).isEqualTo(userTaskProcess.getKey());
141
+ assertThat(dto.getName()).isEqualTo(userTaskProcess.getName());
142
+ assertThat(dto.getVersion()).isEqualTo(userTaskProcess.getVersion());
143
+ assertThat(dto.getCalledFromActivityIds()).hasSize(2);
144
+
145
+ for (String activityId : dto.getCalledFromActivityIds()) {
146
+ if (activityId.equals("firstCallActivity")) {
147
+ assertThat(activityId).isEqualTo("firstCallActivity");
148
+ } else if (activityId.equals("secondCallActivity")) {
149
+ assertThat(activityId).isEqualTo("secondCallActivity");
150
+ } else {
151
+ Assert.fail("Unexpected activity id:" + activityId);
152
+ }
153
+ }
154
+ }
155
+
156
+ @Test
157
+ @Deployment(resources = {
158
+ "processes/user-task-process.bpmn",
159
+ "processes/two-parallel-call-activities-calling-same-process.bpmn",
160
+ "processes/calling-user-task-process.bpmn"
161
+ })
162
+ public void testCalledProcessDefinitionByCallingSameProcessFromDifferentProcessDefinitions() {
163
+ ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("TwoParallelCallActivitiesCallingSameProcess");
164
+ ProcessDefinitionResource resource1 = new ProcessDefinitionResource(getProcessEngine().getName(), processInstance1.getProcessDefinitionId());
165
+
166
+ ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("CallingUserTaskProcess");
167
+ ProcessDefinitionResource resource2 = new ProcessDefinitionResource(getProcessEngine().getName(), processInstance2.getProcessDefinitionId());
168
+
169
+ ProcessDefinition userTaskProcess = repositoryService.createProcessDefinitionQuery()
170
+ .processDefinitionKey("userTaskProcess")
171
+ .singleResult();
172
+
173
+ ProcessDefinitionQueryDto queryParameter1 = new ProcessDefinitionQueryDto();
174
+
175
+ List<ProcessDefinitionDto> result1 = resource1.queryCalledProcessDefinitions(queryParameter1);
176
+ assertThat(result1).isNotEmpty();
177
+ assertThat(result1).hasSize(1);
178
+
179
+ ProcessDefinitionDto dto1 = result1.get(0);
180
+
181
+ assertThat(dto1.getId()).isEqualTo(userTaskProcess.getId());
182
+ assertThat(dto1.getKey()).isEqualTo(userTaskProcess.getKey());
183
+ assertThat(dto1.getName()).isEqualTo(userTaskProcess.getName());
184
+ assertThat(dto1.getVersion()).isEqualTo(userTaskProcess.getVersion());
185
+ assertThat(dto1.getCalledFromActivityIds()).hasSize(2);
186
+
187
+ for (String activityId : dto1.getCalledFromActivityIds()) {
188
+ if (activityId.equals("firstCallActivity")) {
189
+ assertThat(activityId).isEqualTo("firstCallActivity");
190
+ } else if (activityId.equals("secondCallActivity")) {
191
+ assertThat(activityId).isEqualTo("secondCallActivity");
192
+ } else {
193
+ Assert.fail("Unexpected activity id:" + activityId);
194
+ }
195
+ }
196
+
197
+ ProcessDefinitionQueryDto queryParameter2 = new ProcessDefinitionQueryDto();
198
+
199
+ List<ProcessDefinitionDto> result2 = resource2.queryCalledProcessDefinitions(queryParameter2);
200
+ assertThat(result2).isNotEmpty();
201
+ assertThat(result2).hasSize(1);
202
+
203
+ ProcessDefinitionDto dto2 = result2.get(0);
204
+
205
+ assertThat(dto2.getId()).isEqualTo(userTaskProcess.getId());
206
+ assertThat(dto2.getKey()).isEqualTo(userTaskProcess.getKey());
207
+ assertThat(dto2.getName()).isEqualTo(userTaskProcess.getName());
208
+ assertThat(dto2.getVersion()).isEqualTo(userTaskProcess.getVersion());
209
+ assertThat(dto2.getCalledFromActivityIds()).hasSize(1);
210
+
211
+ String calledFrom = dto2.getCalledFromActivityIds().get(0);
212
+
213
+ assertThat(calledFrom).isEqualTo("CallActivity_1");
214
+ }
215
+
216
+ @Test
217
+ @Deployment(resources = {
218
+ "processes/user-task-process.bpmn",
219
+ "processes/another-user-task-process.bpmn",
220
+ "processes/two-parallel-call-activities-calling-different-process.bpmn"
221
+ })
222
+ public void testCalledProcessDefinitionByCallingDifferentProcessFromSameProcessDefinitions() {
223
+ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("TwoParallelCallActivitiesCallingDifferentProcess");
224
+
225
+ resource = new ProcessDefinitionResource(getProcessEngine().getName(), processInstance.getProcessDefinitionId());
226
+
227
+ ProcessDefinition userTaskProcess = repositoryService.createProcessDefinitionQuery()
228
+ .processDefinitionKey("userTaskProcess")
229
+ .singleResult();
230
+
231
+ ProcessDefinition anotherUserTaskProcess = repositoryService.createProcessDefinitionQuery()
232
+ .processDefinitionKey("anotherUserTaskProcess")
233
+ .singleResult();
234
+
235
+ ProcessDefinitionQueryDto queryParameter = new ProcessDefinitionQueryDto();
236
+
237
+ List<ProcessDefinitionDto> result = resource.queryCalledProcessDefinitions(queryParameter);
238
+ assertThat(result).isNotEmpty();
239
+ assertThat(result).hasSize(2);
240
+
241
+ ProcessDefinition compareWith = null;
242
+ for (ProcessDefinitionDto dto : result) {
243
+ String id = dto.getId();
244
+ if (id.equals(userTaskProcess.getId())) {
245
+ compareWith = userTaskProcess;
246
+ assertThat(dto.getCalledFromActivityIds()).hasSize(1);
247
+
248
+ String calledFrom = dto.getCalledFromActivityIds().get(0);
249
+
250
+ assertThat(calledFrom).isEqualTo("firstCallActivity");
251
+
252
+ } else if (id.equals(anotherUserTaskProcess.getId())) {
253
+ compareWith = anotherUserTaskProcess;
254
+ assertThat(dto.getCalledFromActivityIds()).hasSize(1);
255
+
256
+ String calledFrom = dto.getCalledFromActivityIds().get(0);
257
+
258
+ assertThat(calledFrom).isEqualTo("secondCallActivity");
259
+
260
+ } else {
261
+ Assert.fail("Unexpected process definition: " + id);
262
+ }
263
+
264
+ assertThat(dto.getId()).isEqualTo(compareWith.getId());
265
+ assertThat(dto.getKey()).isEqualTo(compareWith.getKey());
266
+ assertThat(dto.getName()).isEqualTo(compareWith.getName());
267
+ assertThat(dto.getVersion()).isEqualTo(compareWith.getVersion());
268
+ }
269
+
270
+ }
271
+
272
+ @Test
273
+ @Deployment(resources = {
274
+ "processes/user-task-process.bpmn",
275
+ "processes/another-user-task-process.bpmn",
276
+ "processes/dynamic-call-activity.bpmn"
277
+ })
278
+ public void testCalledProcessDefinitionByCallingDifferentProcessFromSameCallActivity() {
279
+ Map<String, Object> vars1 = new HashMap<String, Object>();
280
+ vars1.put("callProcess", "userTaskProcess");
281
+ runtimeService.startProcessInstanceByKey("DynamicCallActivity", vars1);
282
+
283
+ Map<String, Object> vars2 = new HashMap<String, Object>();
284
+ vars2.put("callProcess", "anotherUserTaskProcess");
285
+ runtimeService.startProcessInstanceByKey("DynamicCallActivity", vars2);
286
+
287
+ ProcessDefinition dynamicCallActivity = repositoryService.createProcessDefinitionQuery()
288
+ .processDefinitionKey("DynamicCallActivity")
289
+ .singleResult();
290
+
291
+ resource = new ProcessDefinitionResource(getProcessEngine().getName(), dynamicCallActivity.getId());
292
+
293
+ ProcessDefinition userTaskProcess = repositoryService.createProcessDefinitionQuery()
294
+ .processDefinitionKey("userTaskProcess")
295
+ .singleResult();
296
+
297
+ ProcessDefinition anotherUserTaskProcess = repositoryService.createProcessDefinitionQuery()
298
+ .processDefinitionKey("anotherUserTaskProcess")
299
+ .singleResult();
300
+
301
+ ProcessDefinitionQueryDto queryParameter = new ProcessDefinitionQueryDto();
302
+
303
+ List<ProcessDefinitionDto> result = resource.queryCalledProcessDefinitions(queryParameter);
304
+ assertThat(result).isNotEmpty();
305
+ assertThat(result).hasSize(2);
306
+
307
+ ProcessDefinition compareWith = null;
308
+ for (ProcessDefinitionDto dto : result) {
309
+ String id = dto.getId();
310
+ if (id.equals(userTaskProcess.getId())) {
311
+ compareWith = userTaskProcess;
312
+ } else if (id.equals(anotherUserTaskProcess.getId())) {
313
+ compareWith = anotherUserTaskProcess;
314
+ } else {
315
+ Assert.fail("Unexpected process definition: " + id);
316
+ }
317
+
318
+ assertThat(dto.getId()).isEqualTo(compareWith.getId());
319
+ assertThat(dto.getKey()).isEqualTo(compareWith.getKey());
320
+ assertThat(dto.getName()).isEqualTo(compareWith.getName());
321
+ assertThat(dto.getVersion()).isEqualTo(compareWith.getVersion());
322
+ assertThat(dto.getCalledFromActivityIds()).hasSize(1);
323
+
324
+ String calledFrom = dto.getCalledFromActivityIds().get(0);
325
+
326
+ assertThat(calledFrom).isEqualTo("dynamicCallActivity");
327
+ }
328
+ }
329
+
330
+ @Test
331
+ @Deployment(resources = {
332
+ "processes/user-task-process.bpmn",
333
+ "processes/calling-user-task-process.bpmn",
334
+ "processes/nested-calling-user-task-process.bpmn"
335
+ })
336
+ public void testCalledProcessDefinitionQueryBySuperProcessDefinitionId() {
337
+ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("NestedCallingUserTaskProcess");
338
+
339
+ ProcessDefinition callingUserTaskProcess = repositoryService
340
+ .createProcessDefinitionQuery()
341
+ .processDefinitionKey("CallingUserTaskProcess")
342
+ .singleResult();
343
+
344
+ ProcessDefinition userTaskProcess = repositoryService
345
+ .createProcessDefinitionQuery()
346
+ .processDefinitionKey("userTaskProcess")
347
+ .singleResult();
348
+
349
+ resource = new ProcessDefinitionResource(getProcessEngine().getName(), callingUserTaskProcess.getId());
350
+ ProcessDefinitionQueryDto queryParameter = new ProcessDefinitionQueryDto();
351
+ queryParameter.setSuperProcessDefinitionId(processInstance.getProcessDefinitionId());
352
+
353
+ List<ProcessDefinitionDto> result = resource.queryCalledProcessDefinitions(queryParameter);
354
+ assertThat(result).isNotEmpty();
355
+ assertThat(result).hasSize(1);
356
+
357
+ ProcessDefinitionDto dto = result.get(0);
358
+
359
+ assertThat(dto.getId()).isEqualTo(userTaskProcess.getId());
360
+ assertThat(dto.getKey()).isEqualTo(userTaskProcess.getKey());
361
+ assertThat(dto.getName()).isEqualTo(userTaskProcess.getName());
362
+ assertThat(dto.getVersion()).isEqualTo(userTaskProcess.getVersion());
363
+ assertThat(dto.getCalledFromActivityIds()).hasSize(1);
364
+
365
+ String calledFrom = dto.getCalledFromActivityIds().get(0);
366
+
367
+ assertThat(calledFrom).isEqualTo("CallActivity_1");
368
+ }
369
+
370
+ @Test
371
+ @Deployment(resources = {
372
+ "processes/user-task-process.bpmn",
373
+ "processes/another-user-task-process.bpmn",
374
+ "processes/two-parallel-call-activities-calling-different-process.bpmn"
375
+ })
376
+ public void testCalledProcessDefinitionQueryByActivityId() {
377
+ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("TwoParallelCallActivitiesCallingDifferentProcess");
378
+ resource = new ProcessDefinitionResource(getProcessEngine().getName(), processInstance.getProcessDefinitionId());
379
+
380
+ ProcessDefinition userTaskProcess = repositoryService.createProcessDefinitionQuery()
381
+ .processDefinitionKey("userTaskProcess")
382
+ .singleResult();
383
+
384
+ ProcessDefinition anotherUserTaskProcess = repositoryService.createProcessDefinitionQuery()
385
+ .processDefinitionKey("anotherUserTaskProcess")
386
+ .singleResult();
387
+
388
+ ProcessDefinitionQueryDto queryParameter1 = new ProcessDefinitionQueryDto();
389
+ String[] activityIds1 = {"firstCallActivity"};
390
+ queryParameter1.setActivityIdIn(activityIds1);
391
+
392
+ List<ProcessDefinitionDto> result1 = resource.queryCalledProcessDefinitions(queryParameter1);
393
+ assertThat(result1).isNotEmpty();
394
+ assertThat(result1).hasSize(1);
395
+
396
+ ProcessDefinitionDto dto1 = result1.get(0);
397
+
398
+ assertThat(dto1.getId()).isEqualTo(userTaskProcess.getId());
399
+ assertThat(dto1.getKey()).isEqualTo(userTaskProcess.getKey());
400
+ assertThat(dto1.getName()).isEqualTo(userTaskProcess.getName());
401
+ assertThat(dto1.getVersion()).isEqualTo(userTaskProcess.getVersion());
402
+ assertThat(dto1.getCalledFromActivityIds()).hasSize(1);
403
+
404
+ String calledFrom1 = dto1.getCalledFromActivityIds().get(0);
405
+
406
+ assertThat(calledFrom1).isEqualTo("firstCallActivity");
407
+
408
+ ProcessDefinitionQueryDto queryParameter2 = new ProcessDefinitionQueryDto();
409
+ String[] activityIds2 = {"secondCallActivity"};
410
+ queryParameter2.setActivityIdIn(activityIds2);
411
+
412
+ List<ProcessDefinitionDto> result2 = resource.queryCalledProcessDefinitions(queryParameter2);
413
+ assertThat(result2).isNotEmpty();
414
+ assertThat(result2).hasSize(1);
415
+
416
+ ProcessDefinitionDto dto2 = result2.get(0);
417
+
418
+ assertThat(dto2.getId()).isEqualTo(anotherUserTaskProcess.getId());
419
+ assertThat(dto2.getKey()).isEqualTo(anotherUserTaskProcess.getKey());
420
+ assertThat(dto2.getName()).isEqualTo(anotherUserTaskProcess.getName());
421
+ assertThat(dto2.getVersion()).isEqualTo(anotherUserTaskProcess.getVersion());
422
+ assertThat(dto2.getCalledFromActivityIds()).hasSize(1);
423
+
424
+ String calledFrom2 = dto2.getCalledFromActivityIds().get(0);
425
+
426
+ assertThat(calledFrom2).isEqualTo("secondCallActivity");
427
+
428
+ ProcessDefinitionQueryDto queryParameter3 = new ProcessDefinitionQueryDto();
429
+ String[] activityIds3 = {"firstCallActivity", "secondCallActivity"};
430
+ queryParameter3.setActivityIdIn(activityIds3);
431
+
432
+ List<ProcessDefinitionDto> result3 = resource.queryCalledProcessDefinitions(queryParameter3);
433
+ assertThat(result3).isNotEmpty();
434
+ assertThat(result3).hasSize(2);
435
+
436
+ }
437
+
438
+ @Test
439
+ @Deployment(resources = {
440
+ "processes/user-task-process.bpmn",
441
+ "processes/another-user-task-process.bpmn",
442
+ "processes/two-parallel-call-activities-calling-different-process.bpmn"
443
+ })
444
+ public void testCalledProcessDefinitionQueryByBusinessKey() {
445
+ runtimeService.startProcessInstanceByKey("TwoParallelCallActivitiesCallingDifferentProcess", "aBusinessKey");
446
+ runtimeService.startProcessInstanceByKey("TwoParallelCallActivitiesCallingDifferentProcess", "anotherBusinessKey");
447
+
448
+ ProcessDefinition parallelProcess = repositoryService.createProcessDefinitionQuery()
449
+ .processDefinitionKey("TwoParallelCallActivitiesCallingDifferentProcess")
450
+ .singleResult();
451
+
452
+ resource = new ProcessDefinitionResource(getProcessEngine().getName(), parallelProcess.getId());
453
+
454
+ ProcessDefinitionQueryDto queryParameter1 = new ProcessDefinitionQueryDto();
455
+ queryParameter1.setBusinessKey("aBusinessKey");
456
+
457
+ List<ProcessDefinitionDto> result1 = resource.queryCalledProcessDefinitions(queryParameter1);
458
+ assertThat(result1).isNotEmpty();
459
+ assertThat(result1).hasSize(2);
460
+
461
+ ProcessDefinitionQueryDto queryParameter2 = new ProcessDefinitionQueryDto();
462
+ queryParameter2.setBusinessKey("anotherBusinessKey");
463
+
464
+ List<ProcessDefinitionDto> result2 = resource.queryCalledProcessDefinitions(queryParameter2);
465
+ assertThat(result2).isNotEmpty();
466
+ assertThat(result2).hasSize(2);
467
+ }
468
+
469
+ @Test
470
+ @Deployment(resources = {
471
+ "processes/user-task-process.bpmn",
472
+ "processes/another-user-task-process.bpmn",
473
+ "processes/two-parallel-call-activities-calling-different-process.bpmn"
474
+ })
475
+ public void testCalledProcessDefinitionQueryByInvalidBusinessKey() {
476
+ runtimeService.startProcessInstanceByKey("TwoParallelCallActivitiesCallingDifferentProcess", "aBusinessKey");
477
+
478
+ ProcessDefinition parallelProcess = repositoryService.createProcessDefinitionQuery()
479
+ .processDefinitionKey("TwoParallelCallActivitiesCallingDifferentProcess")
480
+ .singleResult();
481
+
482
+ resource = new ProcessDefinitionResource(getProcessEngine().getName(), parallelProcess.getId());
483
+
484
+ ProcessDefinitionQueryDto queryParameter1 = new ProcessDefinitionQueryDto();
485
+ queryParameter1.setBusinessKey("anInvalidBusinessKey");
486
+
487
+ List<ProcessDefinitionDto> result1 = resource.queryCalledProcessDefinitions(queryParameter1);
488
+ assertThat(result1).isEmpty();
489
+ assertThat(result1).hasSize(0);
490
+
491
+ }
492
+
493
+ @Test
494
+ @Deployment(resources = {
495
+ "processes/variables-process-with-call-activity.bpmn",
496
+ "processes/user-task-process.bpmn"
497
+ })
498
+ public void testQueryWithBooleanVariable() {
499
+ // given
500
+ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("variableProcessWithCallActivity");
501
+ resource = new ProcessDefinitionResource(getProcessEngine().getName(), processInstance.getProcessDefinitionId());
502
+
503
+ // when
504
+ VariableQueryParameterDto variable = createVariableParameter("varboolean", EQUALS_OPERATOR_NAME, false);
505
+
506
+ ProcessDefinitionQueryDto queryParameter = new ProcessDefinitionQueryDto();
507
+ queryParameter.setVariables(Arrays.asList(variable));
508
+
509
+ List<ProcessDefinitionDto> results = resource.queryCalledProcessDefinitions(queryParameter);
510
+
511
+ // then
512
+ assertThat(results).hasSize(0);
513
+ }
514
+
515
+ @Test
516
+ @Deployment(resources = {
517
+ "processes/user-task-process.bpmn",
518
+ "processes/another-user-task-process.bpmn",
519
+ "processes/dynamic-call-activity.bpmn"
520
+ })
521
+ public void testQueryWithVariable() {
522
+ // given
523
+ Map<String, Object> vars1 = new HashMap<String, Object>();
524
+ vars1.put("callProcess", "userTaskProcess");
525
+ vars1.put("aVariableName", "test_123");
526
+ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("DynamicCallActivity", vars1);
527
+
528
+ Map<String, Object> vars2 = new HashMap<String, Object>();
529
+ vars2.put("callProcess", "anotherUserTaskProcess");
530
+ vars1.put("aVariableName", "test_456");
531
+ runtimeService.startProcessInstanceByKey("DynamicCallActivity", vars2);
532
+
533
+ resource = new ProcessDefinitionResource(getProcessEngine().getName(), processInstance.getProcessDefinitionId());
534
+
535
+ ProcessDefinition userTaskProcess = repositoryService
536
+ .createProcessDefinitionQuery()
537
+ .processDefinitionKey("userTaskProcess")
538
+ .singleResult();
539
+
540
+ // when
541
+ VariableQueryParameterDto variable = createVariableParameter("aVariableName", LIKE_OPERATOR_NAME, "test\\_1%");
542
+
543
+ ProcessDefinitionQueryDto queryParameter = new ProcessDefinitionQueryDto();
544
+ queryParameter.setVariables(Arrays.asList(variable));
545
+
546
+ // then
547
+ List<ProcessDefinitionDto> results = resource.queryCalledProcessDefinitions(queryParameter);
548
+ assertThat(results).isNotEmpty();
549
+ assertThat(results).hasSize(1);
550
+
551
+ ProcessDefinitionDto dto = results.get(0);
552
+
553
+ assertThat(dto.getId()).isEqualTo(userTaskProcess.getId());
554
+ assertThat(dto.getKey()).isEqualTo(userTaskProcess.getKey());
555
+ assertThat(dto.getName()).isEqualTo(userTaskProcess.getName());
556
+ }
557
+
558
+ @Test
559
+ @Deployment(resources = {
560
+ "processes/variables-process-with-call-activity.bpmn",
561
+ "processes/user-task-process.bpmn"
562
+ })
563
+ public void testQueryWithStringVariable() {
564
+ // given
565
+ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("variableProcessWithCallActivity");
566
+ resource = new ProcessDefinitionResource(getProcessEngine().getName(), processInstance.getProcessDefinitionId());
567
+
568
+ // when
569
+ VariableQueryParameterDto variable = createVariableParameter("varstring", LIKE_OPERATOR_NAME, "B%");
570
+
571
+ ProcessDefinitionQueryDto queryParameter = new ProcessDefinitionQueryDto();
572
+ queryParameter.setVariables(Arrays.asList(variable));
573
+
574
+ List<ProcessDefinitionDto> results = resource.queryCalledProcessDefinitions(queryParameter);
575
+
576
+ // then
577
+ assertThat(results).hasSize(0);
578
+ }
579
+
580
+ @Test
581
+ @Deployment(resources = {
582
+ "processes/variables-process-with-call-activity.bpmn",
583
+ "processes/user-task-process.bpmn"
584
+ })
585
+ public void testQueryWithFloatVariable() {
586
+ // given
587
+ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("variableProcessWithCallActivity");
588
+ resource = new ProcessDefinitionResource(getProcessEngine().getName(), processInstance.getProcessDefinitionId());
589
+
590
+ // when
591
+ VariableQueryParameterDto variable = createVariableParameter("varfloat", EQUALS_OPERATOR_NAME, 0.0);
592
+
593
+ ProcessDefinitionQueryDto queryParameter = new ProcessDefinitionQueryDto();
594
+ queryParameter.setVariables(Arrays.asList(variable));
595
+
596
+ List<ProcessDefinitionDto> results = resource.queryCalledProcessDefinitions(queryParameter);
597
+
598
+ // then
599
+ assertThat(results).hasSize(0);
600
+ }
601
+
602
+ @Test
603
+ @Deployment(resources = {
604
+ "processes/variables-process-with-call-activity.bpmn",
605
+ "processes/user-task-process.bpmn"
606
+ })
607
+ public void testQueryWithIntegerVariable() {
608
+ // given
609
+ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("variableProcessWithCallActivity");
610
+ resource = new ProcessDefinitionResource(getProcessEngine().getName(), processInstance.getProcessDefinitionId());
611
+
612
+ // when
613
+ VariableQueryParameterDto variable = createVariableParameter("varinteger", NOT_EQUALS_OPERATOR_NAME, 12);
614
+
615
+ ProcessDefinitionQueryDto queryParameter = new ProcessDefinitionQueryDto();
616
+ queryParameter.setVariables(Arrays.asList(variable));
617
+
618
+ List<ProcessDefinitionDto> results = resource.queryCalledProcessDefinitions(queryParameter);
619
+
620
+ // then
621
+ assertThat(results).hasSize(0);
622
+ }
623
+
624
+ @Test
625
+ @Deployment(resources = {
626
+ "processes/variables-process-with-call-activity.bpmn",
627
+ "processes/user-task-process.bpmn"
628
+ })
629
+ @RequiredDatabase(excludes = {DbSqlSessionFactory.MYSQL})
630
+ public void testQueryWithComplexVariableFilter() {
631
+ // given
632
+ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("variableProcessWithCallActivity");
633
+ resource = new ProcessDefinitionResource(getProcessEngine().getName(), processInstance.getProcessDefinitionId());
634
+
635
+ // when
636
+ ProcessDefinitionQueryDto queryParameter = new ProcessDefinitionQueryDto();
637
+ queryParameter.setVariables(Arrays.asList(
638
+ createVariableParameter("varinteger", VariableQueryParameterDto.GREATER_THAN_OPERATOR_NAME, 11),
639
+ createVariableParameter("varinteger", VariableQueryParameterDto.LESS_THAN_OR_EQUALS_OPERATOR_NAME, 12),
640
+ createVariableParameter("varinteger", VariableQueryParameterDto.EQUALS_OPERATOR_NAME, 12),
641
+ createVariableParameter("varboolean", VariableQueryParameterDto.EQUALS_OPERATOR_NAME, true),
642
+ createVariableParameter("varboolean", VariableQueryParameterDto.NOT_EQUALS_OPERATOR_NAME, false),
643
+ createVariableParameter("varstring", VariableQueryParameterDto.LIKE_OPERATOR_NAME, "F%"),
644
+ createVariableParameter("varstring", VariableQueryParameterDto.EQUALS_OPERATOR_NAME, "FOO"),
645
+ createVariableParameter("varstring", VariableQueryParameterDto.NOT_EQUALS_OPERATOR_NAME, "BAR"),
646
+ createVariableParameter("varfloat", VariableQueryParameterDto.EQUALS_OPERATOR_NAME, 12.12),
647
+ createVariableParameter("varfloat", VariableQueryParameterDto.NOT_EQUALS_OPERATOR_NAME, 13.0),
648
+ createVariableParameter("varfloat", VariableQueryParameterDto.LESS_THAN_OR_EQUALS_OPERATOR_NAME, 12.13)));
649
+
650
+ // then
651
+ List<ProcessDefinitionDto> results = resource.queryCalledProcessDefinitions(queryParameter);
652
+ assertThat(results).hasSize(1);
653
+
654
+ }
655
+
656
+ @Test
657
+ public void shouldNotThrowExceptionWhenQueryUnbounded() {
658
+ // given
659
+ resource = new ProcessDefinitionResource(getProcessEngine().getName(), "anId");
660
+
661
+ processEngineConfiguration.setQueryMaxResultsLimit(10);
662
+
663
+ identityService.setAuthenticatedUserId("foo");
664
+
665
+ try {
666
+ // when
667
+ resource.queryCalledProcessDefinitions(new ProcessDefinitionQueryDto());
668
+ // then: no exception thrown
669
+ } catch (BadUserRequestException e) {
670
+ fail("No exception expected");
671
+ }
672
+ }
673
+
674
+ private VariableQueryParameterDto createVariableParameter(String name, String operator, Object value) {
675
+ VariableQueryParameterDto variable = new VariableQueryParameterDto();
676
+ variable.setName(name);
677
+ variable.setOperator(operator);
678
+ variable.setValue(value);
679
+
680
+ return variable;
681
+ }
682
+
683
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/ProcessDefinitionRestServiceTest.java ADDED
@@ -0,0 +1,465 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.cockpit.plugin.base;
18
+
19
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.ProcessDefinitionStatisticsDto;
20
+ import org.camunda.bpm.cockpit.impl.plugin.resources.ProcessDefinitionRestService;
21
+ import org.camunda.bpm.cockpit.plugin.test.AbstractCockpitPluginTest;
22
+ import org.camunda.bpm.engine.BadUserRequestException;
23
+ import org.camunda.bpm.engine.IdentityService;
24
+ import org.camunda.bpm.engine.ProcessEngine;
25
+ import org.camunda.bpm.engine.RepositoryService;
26
+ import org.camunda.bpm.engine.RuntimeService;
27
+ import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
28
+ import org.camunda.bpm.engine.impl.persistence.entity.SuspensionState;
29
+ import org.camunda.bpm.engine.repository.ProcessDefinition;
30
+ import org.camunda.bpm.engine.rest.dto.CountResultDto;
31
+ import org.camunda.bpm.engine.runtime.Execution;
32
+ import org.camunda.bpm.engine.runtime.Incident;
33
+ import org.camunda.bpm.model.bpmn.Bpmn;
34
+ import org.camunda.bpm.model.bpmn.BpmnModelInstance;
35
+ import org.junit.After;
36
+ import org.junit.Before;
37
+ import org.junit.Test;
38
+ import org.mockito.Mockito;
39
+
40
+ import javax.ws.rs.core.MultivaluedHashMap;
41
+ import javax.ws.rs.core.MultivaluedMap;
42
+ import javax.ws.rs.core.UriInfo;
43
+ import java.util.Arrays;
44
+ import java.util.List;
45
+
46
+ import static junit.framework.TestCase.fail;
47
+ import static org.assertj.core.api.Assertions.assertThat;
48
+
49
+ public class ProcessDefinitionRestServiceTest extends AbstractCockpitPluginTest {
50
+
51
+ private ProcessEngineConfigurationImpl processEngineConfiguration;
52
+ private RepositoryService repositoryService;
53
+ private RuntimeService runtimeService;
54
+ private ProcessDefinitionRestService resource;
55
+ private IdentityService identityService;
56
+ private UriInfo uriInfo;
57
+ private final MultivaluedMap<String, String> queryParameters = new MultivaluedHashMap<>();
58
+
59
+ @Before
60
+ public void setUp() throws Exception {
61
+ super.before();
62
+
63
+ ProcessEngine processEngine = getProcessEngine();
64
+ processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
65
+ repositoryService = processEngine.getRepositoryService();
66
+ runtimeService = processEngine.getRuntimeService();
67
+ identityService = processEngine.getIdentityService();
68
+
69
+ resource = new ProcessDefinitionRestService(processEngine.getName());
70
+
71
+ uriInfo = Mockito.mock(UriInfo.class);
72
+ Mockito.doReturn(queryParameters).when(uriInfo).getQueryParameters();
73
+ }
74
+
75
+ @After
76
+ public void tearDown() {
77
+ identityService.clearAuthentication();
78
+ processEngineConfiguration.setQueryMaxResultsLimit(Integer.MAX_VALUE);
79
+ queryParameters.clear();
80
+ repositoryService.createDeploymentQuery()
81
+ .list()
82
+ .forEach(deployment -> repositoryService.deleteDeployment(deployment.getId(), true));
83
+ }
84
+
85
+ private void deployProcesses(int count) {
86
+ deployProcesses(count, "ProcessDefinition", "Process Definition");
87
+ }
88
+
89
+ private void deployProcesses(int count, String key, String name) {
90
+ deployProcesses(count, key, name, 0, 0, "default");
91
+ }
92
+
93
+ private void deployProcesses(int count, String key, String name, int instances, int incidents, String tenantId) {
94
+ for (int i = 0; i < count; i++) {
95
+ String pdKey = key + (count > 1 ? "-" + i : "");
96
+ BpmnModelInstance aProcessDefinition = Bpmn.createExecutableProcess(pdKey)
97
+ .name(name + (count > 1 ? " " + i : ""))
98
+ .startEvent()
99
+ .userTask("testQuerySuspensionStateTask")
100
+ .endEvent()
101
+ .done();
102
+ ProcessDefinition processDefinition = repositoryService.createDeployment()
103
+ .addModelInstance(pdKey + ".bpmn", aProcessDefinition)
104
+ .name(pdKey)
105
+ .tenantId(tenantId)
106
+ .deployWithResult()
107
+ .getDeployedProcessDefinitions()
108
+ .get(0);
109
+
110
+ if (instances > 0) {
111
+ for (int j = 0; j < instances; j++) {
112
+ runtimeService.startProcessInstanceById(processDefinition.getId());
113
+ }
114
+ }
115
+
116
+ if (incidents > 0) {
117
+ for (int k = 0; k < incidents; k++) {
118
+ Execution execution = runtimeService.createExecutionQuery()
119
+ .processDefinitionId(processDefinition.getId())
120
+ .list()
121
+ .get(0);
122
+ runtimeService.createIncident("custom", execution.getId(), null);
123
+ }
124
+ }
125
+ }
126
+ }
127
+
128
+ @Test
129
+ public void shouldThrowExceptionWhenMaxResultsLimitExceeded() {
130
+ // given
131
+ processEngineConfiguration.setQueryMaxResultsLimit(10);
132
+ identityService.setAuthenticatedUserId("foo");
133
+
134
+ try {
135
+ // when
136
+ resource.queryStatistics(uriInfo, 0, 11);
137
+ fail("Exception expected!");
138
+ } catch (BadUserRequestException e) {
139
+ // then
140
+ assertThat(e).hasMessage("Max results limit of 10 exceeded!");
141
+ }
142
+ }
143
+
144
+ @Test
145
+ public void shouldThrowExceptionWhenQueryUnbounded() {
146
+ // given
147
+ processEngineConfiguration.setQueryMaxResultsLimit(10);
148
+ identityService.setAuthenticatedUserId("foo");
149
+
150
+ try {
151
+ // when
152
+ resource.queryStatistics(uriInfo, null, null);
153
+ fail("Exception expected!");
154
+ } catch (BadUserRequestException e) {
155
+ // then
156
+ assertThat(e).hasMessage("An unbound number of results is forbidden!");
157
+ }
158
+ }
159
+
160
+ @Test
161
+ public void shouldReturnUnboundedResultWhenNotAuthenticated() {
162
+ // given
163
+ processEngineConfiguration.setQueryMaxResultsLimit(10);
164
+
165
+ try {
166
+ // when
167
+ resource.queryStatistics(uriInfo, null, null);
168
+ // then: no exception expected
169
+ } catch (BadUserRequestException e) {
170
+ // then
171
+ fail("No exception expected");
172
+ }
173
+ }
174
+
175
+ protected void assertProcessDefinitionStatisticsDto(ProcessDefinitionStatisticsDto actual,
176
+ ProcessDefinition expected,
177
+ int expectedInstances,
178
+ int expectedIncidents) {
179
+ assertThat(actual.getId()).isEqualTo(expected.getId());
180
+ assertThat(actual.getKey()).isEqualTo(expected.getKey());
181
+ assertThat(actual.getName()).isEqualTo(expected.getName());
182
+ assertThat(actual.getVersion()).isEqualTo(expected.getVersion());
183
+ assertThat(actual.getTenantId()).isEqualTo(expected.getTenantId());
184
+ assertThat(actual.getSuspensionState()).isEqualTo(
185
+ expected.isSuspended() ? SuspensionState.SUSPENDED.getStateCode() : SuspensionState.ACTIVE.getStateCode());
186
+ assertThat(actual.getInstances()).isEqualTo(expectedInstances);
187
+ assertThat(actual.getIncidents()).isEqualTo(expectedIncidents);
188
+ }
189
+
190
+ @Test
191
+ public void shouldAggregateResultsByKeyAndTenantId() {
192
+ // given
193
+ deployProcesses(1, "A", "Process A", 1, 3, "default");
194
+ repositoryService.suspendProcessDefinitionByKey("A");
195
+ deployProcesses(1, "A", "Process A v2", 1, 0, "default");
196
+ deployProcesses(1, "A", "Process A v3", 2, 2, "default");
197
+ ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
198
+ .processDefinitionKey("A")
199
+ .latestVersion()
200
+ .singleResult();
201
+
202
+ // when
203
+ List<ProcessDefinitionStatisticsDto> actual = resource.queryStatistics(uriInfo, null, null);
204
+ CountResultDto actualCount = resource.getStatisticsCount(uriInfo);
205
+
206
+ // then
207
+ assertThat(actual).hasSize(1);
208
+ assertThat(actualCount.getCount()).isEqualTo(actual.size());
209
+ assertProcessDefinitionStatisticsDto(actual.get(0), processDefinition, 4, 5);
210
+ }
211
+
212
+ @Test
213
+ public void shouldNotAggregateIfTenantIdIsDifferent() {
214
+ // given
215
+ deployProcesses(1, "A", "Process A", 1, 3, "tenant1");
216
+ repositoryService.suspendProcessDefinitionByKey("A");
217
+ deployProcesses(1, "A", "Process A v2", 1, 0, "tenant1");
218
+ deployProcesses(1, "A", "Process A v3", 2, 2, "tenant2");
219
+ ProcessDefinition pdTenant1 = repositoryService.createProcessDefinitionQuery()
220
+ .processDefinitionKey("A")
221
+ .tenantIdIn("tenant1")
222
+ .latestVersion()
223
+ .singleResult();
224
+ ProcessDefinition pdTenant2 = repositoryService.createProcessDefinitionQuery()
225
+ .processDefinitionKey("A")
226
+ .tenantIdIn("tenant2")
227
+ .latestVersion()
228
+ .singleResult();
229
+ queryParameters.add("sortBy", "tenantId");
230
+ queryParameters.add("sortOrder", "asc");
231
+
232
+ // when
233
+ List<ProcessDefinitionStatisticsDto> actual = resource.queryStatistics(uriInfo, null, null);
234
+ CountResultDto actualCount = resource.getStatisticsCount(uriInfo);
235
+
236
+ // then
237
+ assertThat(actual).hasSize(2);
238
+ assertThat(actualCount.getCount()).isEqualTo(actual.size());
239
+ assertProcessDefinitionStatisticsDto(actual.get(0), pdTenant1, 2, 3);
240
+ assertProcessDefinitionStatisticsDto(actual.get(1), pdTenant2, 2, 2);
241
+ }
242
+
243
+ protected void verifyPaginatedResult(int firstResult, int maxResults, int expectedResults) {
244
+ // when
245
+ List<ProcessDefinitionStatisticsDto> actual = resource.queryStatistics(uriInfo, firstResult, maxResults);
246
+ CountResultDto actualCount = resource.getStatisticsCount(uriInfo);
247
+
248
+ // then
249
+ assertThat(actual).hasSize(expectedResults);
250
+ assertThat(actualCount.getCount()).isEqualTo(10);
251
+ for (int i = 0; i < expectedResults; i++) {
252
+ assertThat(actual.get(i).getKey()).isEqualTo("ProcessDefinition-" + (i + firstResult));
253
+ assertThat(actual.get(i).getName()).isEqualTo("Process Definition " + (i + firstResult));
254
+ }
255
+ }
256
+
257
+ @Test
258
+ public void shouldReturnPaginatedResult() {
259
+ // given
260
+ deployProcesses(10);
261
+ queryParameters.add("sortBy", "key");
262
+ queryParameters.add("sortOrder", "asc");
263
+
264
+ // verify pagination
265
+ verifyPaginatedResult(0, 2, 2);
266
+ verifyPaginatedResult(2, 2, 2);
267
+ verifyPaginatedResult(2, 10, 8);
268
+ verifyPaginatedResult(8, 10, 2);
269
+ }
270
+
271
+ protected void verifyFilteredResult(String filterBy, String key, String name) {
272
+ // given
273
+ queryParameters.clear();
274
+ queryParameters.add(filterBy, "key".equals(filterBy) ? key : name);
275
+
276
+ // when
277
+ List<ProcessDefinitionStatisticsDto> actual = resource.queryStatistics(uriInfo, null, null);
278
+ CountResultDto actualCount = resource.getStatisticsCount(uriInfo);
279
+
280
+ // then
281
+ assertThat(actual).hasSize(1);
282
+ assertThat(actualCount.getCount()).isEqualTo(actual.size());
283
+ assertThat(actual.get(0).getKey()).isEqualTo(key);
284
+ assertThat(actual.get(0).getName()).isEqualTo(name);
285
+ }
286
+
287
+ @Test
288
+ public void shouldFilterResultByKey() {
289
+ // given
290
+ deployProcesses(2);
291
+ deployProcesses(2, "Something", "Descriptive Name");
292
+
293
+ // verify filter by key
294
+ verifyFilteredResult("key", "ProcessDefinition-0", "Process Definition 0");
295
+ verifyFilteredResult("key", "Something-1", "Descriptive Name 1");
296
+ }
297
+
298
+ @Test
299
+ public void shouldFilterResultByName() {
300
+ // given
301
+ deployProcesses(2);
302
+ deployProcesses(2, "Something", "Descriptive Name");
303
+
304
+ // verify filter by name
305
+ verifyFilteredResult("name", "ProcessDefinition-0", "Process Definition 0");
306
+ verifyFilteredResult("name", "Something-1", "Descriptive Name 1");
307
+ }
308
+
309
+ private void verifyFilteredLikeResult(String filterBy, String filterValue, int expectedResults) {
310
+ // given
311
+ queryParameters.clear();
312
+ queryParameters.add(filterBy, filterValue);
313
+
314
+ // when
315
+ List<ProcessDefinitionStatisticsDto> actual = resource.queryStatistics(uriInfo, null, null);
316
+ CountResultDto actualCount = resource.getStatisticsCount(uriInfo);
317
+
318
+ // then
319
+ assertThat(actual).hasSize(expectedResults);
320
+ assertThat(actualCount.getCount()).isEqualTo(actual.size());
321
+ }
322
+
323
+ @Test
324
+ public void shouldFilterResultByLike() {
325
+ // given
326
+ deployProcesses(2);
327
+ deployProcesses(2, "AwesomeProcess", "Descriptive Process Name");
328
+
329
+ // verify filter by keyLike
330
+ verifyFilteredLikeResult("keyLike", "%some%", 2);
331
+ verifyFilteredLikeResult("keyLike", "Proc%", 2);
332
+ verifyFilteredLikeResult("keyLike", "%-1", 2);
333
+ verifyFilteredLikeResult("keyLike", "%Process%", 4);
334
+ }
335
+
336
+ @Test
337
+ public void shouldFilterResultByNameLike() {
338
+ // given
339
+ deployProcesses(2);
340
+ deployProcesses(2, "AwesomeProcess", "Descriptive Process Name");
341
+
342
+ // verify filter by nameLike
343
+ verifyFilteredLikeResult("nameLike", "%Definition%", 2);
344
+ verifyFilteredLikeResult("nameLike", "Descriptive%", 2);
345
+ verifyFilteredLikeResult("nameLike", "% 1", 2);
346
+ verifyFilteredLikeResult("nameLike", "%Process%", 4);
347
+ }
348
+
349
+ private void verifyOrderedResult(String sortBy, String sortOrder, List<String> expectedKeysOrder) {
350
+ // given
351
+ queryParameters.clear();
352
+ queryParameters.add("sortBy", sortBy);
353
+ queryParameters.add("sortOrder", sortOrder);
354
+
355
+ // when
356
+ List<ProcessDefinitionStatisticsDto> actual = resource.queryStatistics(uriInfo, null, null);
357
+ CountResultDto actualCount = resource.getStatisticsCount(uriInfo);
358
+
359
+ // then
360
+ assertThat(actual).hasSize(4);
361
+ assertThat(actualCount.getCount()).isEqualTo(actual.size());
362
+ for (int i = 0; i < expectedKeysOrder.size(); i++) {
363
+ String expectedKey = expectedKeysOrder.get(i);
364
+ assertThat(actual.get(i).getKey()).isEqualTo(expectedKey);
365
+ }
366
+ }
367
+
368
+ @Test
369
+ public void shouldSortResult() {
370
+ // given
371
+ deployProcesses(1, "A", "Process A", 1, 3, "tenant2");
372
+ deployProcesses(1, "B", "Process B", 3, 1, "tenant0");
373
+ deployProcesses(1, "p1", "Process 1", 2, 2, "tenant3");
374
+ deployProcesses(1, "p2", "Process 2", 0, 0, "tenant1");
375
+
376
+ // verify order by key
377
+ verifyOrderedResult("key", "asc", Arrays.asList("A", "B", "p1", "p2"));
378
+ verifyOrderedResult("key", "desc", Arrays.asList("p2", "p1", "B", "A"));
379
+
380
+ // verify order by name
381
+ verifyOrderedResult("name", "asc", Arrays.asList("p1", "p2", "A", "B"));
382
+ verifyOrderedResult("name", "desc", Arrays.asList("B", "A", "p2", "p1"));
383
+
384
+ // verify order by tenantId
385
+ verifyOrderedResult("tenantId", "asc", Arrays.asList("B", "p2", "A", "p1"));
386
+ verifyOrderedResult("tenantId", "desc", Arrays.asList("p1", "A", "p2", "B"));
387
+
388
+ // verify order by instances
389
+ verifyOrderedResult("instances", "asc", Arrays.asList("p2", "A", "p1", "B"));
390
+ verifyOrderedResult("instances", "desc", Arrays.asList("B", "p1", "A", "p2"));
391
+
392
+ // verify order by incidents
393
+ verifyOrderedResult("incidents", "asc", Arrays.asList("p2", "B", "p1", "A"));
394
+ verifyOrderedResult("incidents", "desc", Arrays.asList("A", "p1", "B", "p2"));
395
+ }
396
+
397
+ @Test
398
+ public void shouldReturnCorrectStatistics() {
399
+ // given a process with two process instances
400
+ deployProcesses(1, "A", "Process A", 2, 0, "tenant1");
401
+
402
+ var processInstances = runtimeService.createExecutionQuery()
403
+ .processDefinitionKey("A")
404
+ .list();
405
+
406
+ assertThat(processInstances).hasSize(2);
407
+
408
+ var processIncidents = runtimeService.createIncidentQuery()
409
+ .processDefinitionKeyIn("A")
410
+ .list();
411
+
412
+ assertIncidentSize(processIncidents, 0);
413
+
414
+ var pi1 = processInstances.get(0);
415
+ var pi2 = processInstances.get(1);
416
+
417
+ // and two different (failedJob, failedExternalTask) incidents occur for each process instance
418
+
419
+ addIncidentToProcess(pi1, "failedJob");
420
+ addIncidentToProcess(pi1, "failedExternalTask");
421
+
422
+ addIncidentToProcess(pi2, "failedJob");
423
+ addIncidentToProcess(pi2, "failedExternalTask");
424
+
425
+ processIncidents = runtimeService.createIncidentQuery()
426
+ .processDefinitionKeyIn("A")
427
+ .list();
428
+
429
+ assertIncidentSize(processIncidents, 4);
430
+
431
+ assertIncidentSize(processIncidents, "failedJob", 2);
432
+ assertIncidentSize(processIncidents, "failedExternalTask", 2);
433
+
434
+ // when
435
+ var results = resource.queryStatistics(uriInfo, 0, 50);
436
+
437
+ // then statistics should be correct
438
+ assertThat(results)
439
+ .withFailMessage("The result should contain one entry (process definition 'Process A')")
440
+ .hasSize(1);
441
+
442
+ assertThat(results.get(0).getInstances())
443
+ .withFailMessage("The number of process instances should be 2")
444
+ .isEqualTo(2);
445
+
446
+ assertThat(results.get(0).getIncidents())
447
+ .withFailMessage("The total number of incidents should be 4")
448
+ .isEqualTo(4);
449
+ }
450
+
451
+ private void addIncidentToProcess(Execution processInstance, String incidentType) {
452
+ runtimeService.createIncident(incidentType, processInstance.getId(), "someConfig", "The message of failure");
453
+ }
454
+
455
+ private void assertIncidentSize(List<Incident> incidents, int size) {
456
+ assertThat(incidents.size()).isEqualTo(size);
457
+ }
458
+
459
+ private void assertIncidentSize(List<Incident> incidents, String incidentType, int size) {
460
+ assertThat(incidents.stream()
461
+ .filter(incident -> incidentType.equals(incident.getIncidentType()))
462
+ .count())
463
+ .isEqualTo(size);
464
+ }
465
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/ProcessInstanceResourceTest.java ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.cockpit.plugin.base;
18
+
19
+ import static junit.framework.TestCase.fail;
20
+ import static org.assertj.core.api.Assertions.assertThat;
21
+
22
+ import java.sql.SQLException;
23
+ import java.util.List;
24
+
25
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.CalledProcessInstanceDto;
26
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.IncidentStatisticsDto;
27
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.ProcessInstanceDto;
28
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.query.CalledProcessInstanceQueryDto;
29
+ import org.camunda.bpm.cockpit.impl.plugin.base.sub.resources.ProcessInstanceResource;
30
+ import org.camunda.bpm.cockpit.plugin.test.AbstractCockpitPluginTest;
31
+ import org.camunda.bpm.engine.BadUserRequestException;
32
+ import org.camunda.bpm.engine.IdentityService;
33
+ import org.camunda.bpm.engine.ProcessEngine;
34
+ import org.camunda.bpm.engine.RepositoryService;
35
+ import org.camunda.bpm.engine.RuntimeService;
36
+ import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
37
+ import org.camunda.bpm.engine.repository.ProcessDefinition;
38
+ import org.camunda.bpm.engine.runtime.ActivityInstance;
39
+ import org.camunda.bpm.engine.runtime.ProcessInstance;
40
+ import org.camunda.bpm.engine.test.Deployment;
41
+ import org.junit.After;
42
+ import org.junit.Assert;
43
+ import org.junit.Before;
44
+ import org.junit.Test;
45
+
46
+ /**
47
+ * @author roman.smirnov
48
+ */
49
+ public class ProcessInstanceResourceTest extends AbstractCockpitPluginTest {
50
+
51
+ private ProcessInstanceResource resource;
52
+ private ProcessEngine processEngine;
53
+ protected ProcessEngineConfigurationImpl processEngineConfiguration;
54
+ private RuntimeService runtimeService;
55
+ private RepositoryService repositoryService;
56
+ protected IdentityService identityService;
57
+
58
+ @Before
59
+ public void setUp() throws Exception {
60
+ super.before();
61
+
62
+ processEngine = getProcessEngine();
63
+ processEngineConfiguration = (ProcessEngineConfigurationImpl) getProcessEngine()
64
+ .getProcessEngineConfiguration();
65
+ runtimeService = processEngine.getRuntimeService();
66
+ repositoryService = processEngine.getRepositoryService();
67
+ identityService = processEngine.getIdentityService();
68
+ }
69
+
70
+ @After
71
+ public void clearAuthentication() {
72
+ identityService.clearAuthentication();
73
+ }
74
+
75
+ @After
76
+ public void resetQueryMaxResultsLimit() {
77
+ processEngineConfiguration.setQueryMaxResultsLimit(Integer.MAX_VALUE);
78
+ }
79
+
80
+ @Test
81
+ @Deployment(resources = {
82
+ "processes/two-parallel-call-activities-calling-different-process.bpmn",
83
+ "processes/user-task-process.bpmn",
84
+ "processes/another-user-task-process.bpmn"
85
+ })
86
+ public void testGetCalledProcessInstancesByParentProcessInstanceId() {
87
+ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("TwoParallelCallActivitiesCallingDifferentProcess");
88
+
89
+ resource = new ProcessInstanceResource(getProcessEngine().getName(), processInstance.getId());
90
+
91
+ executeAvailableJobs();
92
+
93
+ ProcessDefinition userTaskProcess = repositoryService
94
+ .createProcessDefinitionQuery()
95
+ .processDefinitionKey("userTaskProcess")
96
+ .singleResult();
97
+
98
+ ProcessDefinition anotherUserTaskProcess = repositoryService
99
+ .createProcessDefinitionQuery()
100
+ .processDefinitionKey("anotherUserTaskProcess")
101
+ .singleResult();
102
+
103
+ CalledProcessInstanceQueryDto queryParameter = new CalledProcessInstanceQueryDto();
104
+
105
+ List<CalledProcessInstanceDto> result = resource.queryCalledProcessInstances(queryParameter);
106
+ assertThat(result).isNotEmpty();
107
+ assertThat(result).hasSize(2);
108
+
109
+ ProcessDefinition compareWith = null;
110
+ for (ProcessInstanceDto instance : result) {
111
+ CalledProcessInstanceDto dto = (CalledProcessInstanceDto) instance;
112
+ if (dto.getProcessDefinitionId().equals(userTaskProcess.getId())) {
113
+ compareWith = userTaskProcess;
114
+ assertThat(dto.getCallActivityId()).isEqualTo("firstCallActivity");
115
+ } else if (dto.getProcessDefinitionId().equals(anotherUserTaskProcess.getId())) {
116
+ compareWith = anotherUserTaskProcess;
117
+ assertThat(dto.getCallActivityId()).isEqualTo("secondCallActivity");
118
+ } else {
119
+ Assert.fail("Unexpected called process instance: " + dto.getId());
120
+ }
121
+
122
+ assertThat(dto.getCallActivityInstanceId()).isNotNull();
123
+
124
+ assertThat(dto.getProcessDefinitionId()).isEqualTo(compareWith.getId());
125
+ assertThat(dto.getProcessDefinitionName()).isEqualTo(compareWith.getName());
126
+ assertThat(dto.getProcessDefinitionKey()).isEqualTo(compareWith.getKey());
127
+ }
128
+ }
129
+
130
+ @Test
131
+ @Deployment(resources = {
132
+ "processes/two-parallel-call-activities-calling-different-process.bpmn",
133
+ "processes/user-task-process.bpmn",
134
+ "processes/another-user-task-process.bpmn"
135
+ })
136
+ public void testGetCalledProcessInstancesByParentProcessInstanceIdContainsBusinessKey() {
137
+ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("TwoParallelCallActivitiesCallingDifferentProcess", "myBusinessKey");
138
+
139
+ resource = new ProcessInstanceResource(getProcessEngine().getName(), processInstance.getId());
140
+ executeAvailableJobs();
141
+
142
+ CalledProcessInstanceQueryDto queryParameter = new CalledProcessInstanceQueryDto();
143
+
144
+ List<CalledProcessInstanceDto> result = resource.queryCalledProcessInstances(queryParameter);
145
+ assertThat(result).isNotEmpty();
146
+ assertThat(result).hasSize(2);
147
+ assertThat(result.get(0).getBusinessKey()).isEqualTo("firstCall:myBusinessKey");
148
+ assertThat(result.get(1).getBusinessKey()).isEqualTo("secondCall:myBusinessKey");
149
+ }
150
+
151
+
152
+ @Test
153
+ @Deployment(resources = {
154
+ "processes/two-parallel-call-activities-calling-different-process.bpmn",
155
+ "processes/user-task-process.bpmn",
156
+ "processes/another-user-task-process.bpmn"
157
+ })
158
+ public void testGetCalledProcessInstancesByParentProcessInstanceIdAndActivityInstanceId() {
159
+ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("TwoParallelCallActivitiesCallingDifferentProcess");
160
+
161
+ resource = new ProcessInstanceResource(getProcessEngine().getName(), processInstance.getId());
162
+
163
+ ActivityInstance processInstanceActivityInstance = runtimeService.getActivityInstance(processInstance.getId());
164
+
165
+ String firstActivityInstanceId = null;
166
+ String secondActivityInstanceId = null;
167
+
168
+ for (ActivityInstance child : processInstanceActivityInstance.getChildActivityInstances()) {
169
+ if (child.getActivityId().equals("firstCallActivity")) {
170
+ firstActivityInstanceId = child.getId();
171
+ } else if (child.getActivityId().equals("secondCallActivity")) {
172
+ secondActivityInstanceId = child.getId();
173
+ } else {
174
+ Assert.fail("Unexpected activity instance with activity id: " + child.getActivityId() + " and instance id: " + child.getId());
175
+ }
176
+ }
177
+
178
+ executeAvailableJobs();
179
+
180
+ CalledProcessInstanceQueryDto queryParameter1 = new CalledProcessInstanceQueryDto();
181
+
182
+ String[] activityInstanceIds1 = {firstActivityInstanceId};
183
+ queryParameter1.setActivityInstanceIdIn(activityInstanceIds1);
184
+
185
+ List<CalledProcessInstanceDto> result1 = resource.queryCalledProcessInstances(queryParameter1);
186
+ assertThat(result1).isNotEmpty();
187
+ assertThat(result1).hasSize(1);
188
+
189
+ CalledProcessInstanceQueryDto queryParameter2 = new CalledProcessInstanceQueryDto();
190
+ String[] activityInstanceIds2 = {secondActivityInstanceId};
191
+ queryParameter2.setActivityInstanceIdIn(activityInstanceIds2);
192
+
193
+ List<CalledProcessInstanceDto> result2 = resource.queryCalledProcessInstances(queryParameter2);
194
+ assertThat(result2).isNotEmpty();
195
+ assertThat(result2).hasSize(1);
196
+
197
+ CalledProcessInstanceQueryDto queryParameter3 = new CalledProcessInstanceQueryDto();
198
+ String[] activityInstanceIds3 = {firstActivityInstanceId, secondActivityInstanceId};
199
+ queryParameter3.setActivityInstanceIdIn(activityInstanceIds3);
200
+
201
+ List<CalledProcessInstanceDto> result3 = resource.queryCalledProcessInstances(queryParameter3);
202
+ assertThat(result3).isNotEmpty();
203
+ assertThat(result3).hasSize(2);
204
+ }
205
+
206
+ @Test
207
+ @Deployment(resources = {
208
+ "processes/call-activity.bpmn",
209
+ "processes/failing-process.bpmn"
210
+ })
211
+ public void testCalledProcessIntancesIncidents() {
212
+ ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("CallActivity");
213
+
214
+ resource = new ProcessInstanceResource(getProcessEngine().getName(), processInstance.getId());
215
+
216
+ runtimeService.getActivityInstance(processInstance.getId());
217
+
218
+ String processDefinition1 = repositoryService
219
+ .createProcessDefinitionQuery()
220
+ .processDefinitionKey("CallActivity")
221
+ .singleResult()
222
+ .getId();
223
+
224
+ String processDefinition2 = repositoryService
225
+ .createProcessDefinitionQuery()
226
+ .processDefinitionKey("FailingProcess")
227
+ .singleResult()
228
+ .getId();
229
+
230
+ executeAvailableJobs();
231
+
232
+ CalledProcessInstanceQueryDto queryParameter1 = new CalledProcessInstanceQueryDto();
233
+ queryParameter1.setProcessDefinitionId(processDefinition1);
234
+
235
+ List<CalledProcessInstanceDto> callActivityInstances = resource.queryCalledProcessInstances(queryParameter1);
236
+ assertThat(callActivityInstances).isNotEmpty();
237
+ assertThat(callActivityInstances).hasSize(1);
238
+
239
+ List<IncidentStatisticsDto> incidents1 = callActivityInstances.get(0).getIncidents();
240
+ assertThat(incidents1).isNotEmpty();
241
+ assertThat(incidents1).hasSize(1);
242
+
243
+ assertThat(incidents1.get(0).getIncidentCount()).isEqualTo(1);
244
+ assertThat(incidents1.get(0).getIncidentType()).isEqualTo("failedJob");
245
+
246
+ CalledProcessInstanceQueryDto queryParameter2 = new CalledProcessInstanceQueryDto();
247
+ queryParameter2.setProcessDefinitionId(processDefinition2);
248
+
249
+ List<CalledProcessInstanceDto> failingProcessInstance = resource.queryCalledProcessInstances(queryParameter2);
250
+ assertThat(failingProcessInstance).isNotEmpty();
251
+ assertThat(failingProcessInstance).hasSize(1);
252
+
253
+ List<IncidentStatisticsDto> incidents2 = failingProcessInstance.get(0).getIncidents();
254
+ assertThat(incidents2).isNotEmpty();
255
+ assertThat(incidents2).hasSize(1);
256
+
257
+ assertThat(incidents2.get(0).getIncidentCount()).isEqualTo(1);
258
+ assertThat(incidents2.get(0).getIncidentType()).isEqualTo("failedJob");
259
+ }
260
+
261
+ @Test
262
+ public void shouldNotThrowExceptionWhenQueryUnbounded() {
263
+ // given
264
+ resource = new ProcessInstanceResource(getProcessEngine().getName(), "anId");
265
+
266
+ processEngineConfiguration.setQueryMaxResultsLimit(10);
267
+
268
+ identityService.setAuthenticatedUserId("foo");
269
+
270
+ try {
271
+ // when
272
+ resource.queryCalledProcessInstances(new CalledProcessInstanceQueryDto());
273
+ // then: no exception thrown
274
+ } catch (BadUserRequestException e) {
275
+ fail("No exception expected");
276
+ }
277
+ }
278
+
279
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/ProcessInstanceRestServiceTest.java ADDED
The diff for this file is too large to render. See raw diff
 
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/authorization/AuthorizationTest.java ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.cockpit.plugin.base.authorization;
18
+
19
+ import static org.camunda.bpm.engine.authorization.Authorization.ANY;
20
+ import static org.camunda.bpm.engine.authorization.Authorization.AUTH_TYPE_GRANT;
21
+ import static org.camunda.bpm.engine.authorization.Permissions.ALL;
22
+ import static org.camunda.bpm.engine.authorization.Resources.AUTHORIZATION;
23
+ import static org.camunda.bpm.engine.authorization.Resources.USER;
24
+
25
+ import java.util.Arrays;
26
+ import org.camunda.bpm.cockpit.plugin.test.AbstractCockpitPluginTest;
27
+ import org.camunda.bpm.engine.AuthorizationService;
28
+ import org.camunda.bpm.engine.IdentityService;
29
+ import org.camunda.bpm.engine.ProcessEngine;
30
+ import org.camunda.bpm.engine.RepositoryService;
31
+ import org.camunda.bpm.engine.RuntimeService;
32
+ import org.camunda.bpm.engine.authorization.Authorization;
33
+ import org.camunda.bpm.engine.authorization.Permission;
34
+ import org.camunda.bpm.engine.authorization.Permissions;
35
+ import org.camunda.bpm.engine.authorization.Resource;
36
+ import org.camunda.bpm.engine.identity.Group;
37
+ import org.camunda.bpm.engine.identity.User;
38
+ import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
39
+ import org.camunda.bpm.engine.repository.Deployment;
40
+ import org.camunda.bpm.engine.repository.DeploymentBuilder;
41
+ import org.camunda.bpm.engine.repository.ProcessDefinition;
42
+ import org.camunda.bpm.engine.runtime.ProcessInstance;
43
+ import org.junit.After;
44
+ import org.junit.Before;
45
+
46
+ /**
47
+ * @author Roman Smirnov
48
+ *
49
+ */
50
+ public abstract class AuthorizationTest extends AbstractCockpitPluginTest {
51
+
52
+ protected ProcessEngine processEngine;
53
+ protected String engineName;
54
+ protected ProcessEngineConfigurationImpl processEngineConfiguration;
55
+
56
+ protected IdentityService identityService;
57
+ protected AuthorizationService authorizationService;
58
+ protected RepositoryService repositoryService;
59
+ protected RuntimeService runtimeService;
60
+
61
+ protected String userId = "test";
62
+ protected String groupId = "accounting";
63
+ protected User user;
64
+ protected Group group;
65
+
66
+ @Before
67
+ public void setUp() throws Exception {
68
+ super.before();
69
+
70
+ processEngine = getProcessEngine();
71
+ engineName = getProcessEngine().getName();
72
+ processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
73
+
74
+ identityService = processEngine.getIdentityService();
75
+ authorizationService = processEngine.getAuthorizationService();
76
+ repositoryService = processEngine.getRepositoryService();
77
+ runtimeService = processEngine.getRuntimeService();
78
+
79
+ user = createUser(userId);
80
+ group = createGroup(groupId);
81
+
82
+ identityService.createMembership(userId, groupId);
83
+
84
+ identityService.setAuthentication(userId, Arrays.asList(groupId));
85
+ enableAuthorization();
86
+ }
87
+
88
+ @After
89
+ public void tearDown() {
90
+ disableAuthorization();
91
+ for (User user : identityService.createUserQuery().list()) {
92
+ identityService.deleteUser(user.getId());
93
+ }
94
+ for (Group group : identityService.createGroupQuery().list()) {
95
+ identityService.deleteGroup(group.getId());
96
+ }
97
+ for (Authorization authorization : authorizationService.createAuthorizationQuery().list()) {
98
+ authorizationService.deleteAuthorization(authorization.getId());
99
+ }
100
+ }
101
+
102
+ // user ////////////////////////////////////////////////////////////////
103
+
104
+ protected User createUser(String userId) {
105
+ User user = identityService.newUser(userId);
106
+ identityService.saveUser(user);
107
+
108
+ // give user all permission to manipulate authorizations
109
+ Authorization authorization = createGrantAuthorization(AUTHORIZATION, ANY);
110
+ authorization.setUserId(userId);
111
+ authorization.addPermission(ALL);
112
+ saveAuthorization(authorization);
113
+
114
+ // give user all permission to manipulate users
115
+ authorization = createGrantAuthorization(USER, ANY);
116
+ authorization.setUserId(userId);
117
+ authorization.addPermission(Permissions.ALL);
118
+ saveAuthorization(authorization);
119
+
120
+ return user;
121
+ }
122
+
123
+ // group //////////////////////////////////////////////////////////////
124
+
125
+ protected Group createGroup(String groupId) {
126
+ Group group = identityService.newGroup(groupId);
127
+ identityService.saveGroup(group);;
128
+ return group;
129
+ }
130
+
131
+ // authorization ///////////////////////////////////////////////////////
132
+
133
+ protected void createGrantAuthorization(Resource resource, String resourceId, String userId, Permission... permissions) {
134
+ Authorization authorization = createGrantAuthorization(resource, resourceId);
135
+ authorization.setUserId(userId);
136
+ for (Permission permission : permissions) {
137
+ authorization.addPermission(permission);
138
+ }
139
+ saveAuthorization(authorization);
140
+ }
141
+
142
+ protected Authorization createGrantAuthorization(Resource resource, String resourceId) {
143
+ Authorization authorization = createAuthorization(AUTH_TYPE_GRANT, resource, resourceId);
144
+ return authorization;
145
+ }
146
+
147
+ protected Authorization createAuthorization(int type, Resource resource, String resourceId) {
148
+ Authorization authorization = authorizationService.createNewAuthorization(type);
149
+
150
+ authorization.setResource(resource);
151
+ if (resourceId != null) {
152
+ authorization.setResourceId(resourceId);
153
+ }
154
+
155
+ return authorization;
156
+ }
157
+
158
+ protected void saveAuthorization(Authorization authorization) {
159
+ authorizationService.saveAuthorization(authorization);
160
+ }
161
+
162
+ // enable/disable authorization //////////////////////////////////////////////
163
+
164
+ protected void enableAuthorization() {
165
+ processEngineConfiguration.setAuthorizationEnabled(true);
166
+ }
167
+
168
+ protected void disableAuthorization() {
169
+ processEngineConfiguration.setAuthorizationEnabled(false);
170
+ }
171
+
172
+ // actions (executed without authorization) ///////////////////////////////////
173
+
174
+ protected ProcessDefinition selectProcessDefinitionByKey(String processDefinitionKey) {
175
+ disableAuthorization();
176
+ ProcessDefinition definition = repositoryService
177
+ .createProcessDefinitionQuery()
178
+ .processDefinitionKey(processDefinitionKey)
179
+ .singleResult();
180
+ enableAuthorization();
181
+ return definition;
182
+ }
183
+
184
+ protected ProcessInstance selectAnyProcessInstanceByKey(String processDefinitionKey) {
185
+ disableAuthorization();
186
+ ProcessInstance instance = runtimeService.createProcessInstanceQuery().processDefinitionKey(processDefinitionKey).listPage(0, 1).get(0);
187
+ enableAuthorization();
188
+ return instance;
189
+ }
190
+
191
+ protected void startProcessInstances(String processDefinitionKey, int numOfInstances) {
192
+ disableAuthorization();
193
+ for (int i = 0; i < numOfInstances; i++) {
194
+ runtimeService.startProcessInstanceByKey(processDefinitionKey, "businessKey_" + i);
195
+ }
196
+ enableAuthorization();
197
+ }
198
+
199
+ protected Deployment createDeployment(String name, String... resources) {
200
+ disableAuthorization();
201
+ DeploymentBuilder builder = repositoryService.createDeployment();
202
+ for (String resource : resources) {
203
+ builder.addClasspathResource(resource);
204
+ }
205
+ Deployment deployment = builder.deploy();
206
+ enableAuthorization();
207
+ return deployment;
208
+ }
209
+
210
+ protected void deleteDeployment(String deploymentId) {
211
+ disableAuthorization();
212
+ repositoryService.deleteDeployment(deploymentId, true);
213
+ enableAuthorization();
214
+ }
215
+
216
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/authorization/IncidentRestServiceAuthorizationTest.java ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.cockpit.plugin.base.authorization;
18
+
19
+ import static org.camunda.bpm.engine.authorization.Authorization.ANY;
20
+ import static org.camunda.bpm.engine.authorization.Permissions.READ;
21
+ import static org.camunda.bpm.engine.authorization.Permissions.READ_INSTANCE;
22
+ import static org.camunda.bpm.engine.authorization.Resources.PROCESS_DEFINITION;
23
+ import static org.camunda.bpm.engine.authorization.Resources.PROCESS_INSTANCE;
24
+ import static org.assertj.core.api.Assertions.assertThat;
25
+
26
+ import java.util.List;
27
+
28
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.IncidentDto;
29
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.query.IncidentQueryDto;
30
+ import org.camunda.bpm.cockpit.impl.plugin.resources.IncidentRestService;
31
+ import org.junit.After;
32
+ import org.junit.Before;
33
+ import org.junit.Test;
34
+
35
+ /**
36
+ * @author Roman Smirnov
37
+ *
38
+ */
39
+ public class IncidentRestServiceAuthorizationTest extends AuthorizationTest {
40
+
41
+ protected static final String FAILING_PROCESS_KEY = "FailingProcess";
42
+
43
+ protected String deploymentId;
44
+
45
+ protected IncidentRestService resource;
46
+
47
+ @Override
48
+ @Before
49
+ public void setUp() throws Exception {
50
+ super.setUp();
51
+
52
+ runtimeService = processEngine.getRuntimeService();
53
+
54
+ deploymentId = createDeployment(null, "processes/failing-process.bpmn").getId();
55
+
56
+ resource = new IncidentRestService(engineName);
57
+
58
+ startProcessInstances(FAILING_PROCESS_KEY, 3);
59
+ disableAuthorization();
60
+ executeAvailableJobs();
61
+ enableAuthorization();
62
+ }
63
+
64
+ @Override
65
+ @After
66
+ public void tearDown() {
67
+ deleteDeployment(deploymentId);
68
+ super.tearDown();
69
+ }
70
+
71
+ @Test
72
+ public void testQueryWithoutAuthorization() {
73
+ // given
74
+ IncidentQueryDto queryParameter = new IncidentQueryDto();
75
+
76
+ // when
77
+ List<IncidentDto> incidents = resource.queryIncidents(queryParameter, null, null);
78
+
79
+ // then
80
+ assertThat(incidents).isEmpty();
81
+ }
82
+
83
+ @Test
84
+ public void testQueryWithReadPermissionOnProcessInstance() {
85
+ // given
86
+ String processInstanceId = selectAnyProcessInstanceByKey(FAILING_PROCESS_KEY).getId();
87
+ createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, READ);
88
+
89
+ IncidentQueryDto queryParameter = new IncidentQueryDto();
90
+
91
+ // when
92
+ List<IncidentDto> incidents = resource.queryIncidents(queryParameter, null, null);
93
+
94
+ // then
95
+ assertThat(incidents).isNotEmpty();
96
+ assertThat(incidents).hasSize(1);
97
+ assertThat(incidents.get(0).getProcessInstanceId()).isEqualTo(processInstanceId);
98
+ }
99
+
100
+ @Test
101
+ public void testQueryWithReadPermissionOnAnyProcessInstance() {
102
+ // given
103
+ createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, READ);
104
+
105
+ IncidentQueryDto queryParameter = new IncidentQueryDto();
106
+
107
+ // when
108
+ List<IncidentDto> incidents = resource.queryIncidents(queryParameter, null, null);
109
+
110
+ // then
111
+ assertThat(incidents).isNotEmpty();
112
+ assertThat(incidents).hasSize(3);
113
+ }
114
+
115
+ @Test
116
+ public void testQueryWithMultipleReadPermissions() {
117
+ // given
118
+ createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, READ);
119
+ String processInstanceId = selectAnyProcessInstanceByKey(FAILING_PROCESS_KEY).getId();
120
+ createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, READ);
121
+
122
+ IncidentQueryDto queryParameter = new IncidentQueryDto();
123
+
124
+ // when
125
+ List<IncidentDto> incidents = resource.queryIncidents(queryParameter, null, null);
126
+
127
+ // then
128
+ assertThat(incidents).isNotEmpty();
129
+ assertThat(incidents).hasSize(3);
130
+ }
131
+
132
+ @Test
133
+ public void testQueryWithReadPermissionOnProcessDefinition() {
134
+ // given
135
+ createGrantAuthorization(PROCESS_DEFINITION, FAILING_PROCESS_KEY, userId, READ_INSTANCE);
136
+
137
+ IncidentQueryDto queryParameter = new IncidentQueryDto();
138
+
139
+ // when
140
+ List<IncidentDto> incidents = resource.queryIncidents(queryParameter, null, null);
141
+
142
+ // then
143
+ assertThat(incidents).isNotEmpty();
144
+ assertThat(incidents).hasSize(3);
145
+ }
146
+
147
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/authorization/ProcessDefinitionResourceAuthorizationTest.java ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.cockpit.plugin.base.authorization;
18
+
19
+ import static org.camunda.bpm.engine.authorization.Authorization.ANY;
20
+ import static org.camunda.bpm.engine.authorization.Permissions.READ;
21
+ import static org.camunda.bpm.engine.authorization.Permissions.READ_INSTANCE;
22
+ import static org.camunda.bpm.engine.authorization.Resources.PROCESS_DEFINITION;
23
+ import static org.camunda.bpm.engine.authorization.Resources.PROCESS_INSTANCE;
24
+ import static org.assertj.core.api.Assertions.assertThat;
25
+
26
+ import java.util.HashMap;
27
+ import java.util.List;
28
+ import java.util.Map;
29
+
30
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.ProcessDefinitionDto;
31
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.query.ProcessDefinitionQueryDto;
32
+ import org.camunda.bpm.cockpit.impl.plugin.base.sub.resources.ProcessDefinitionResource;
33
+ import org.camunda.bpm.engine.test.Deployment;
34
+ import org.junit.After;
35
+ import org.junit.Before;
36
+ import org.junit.Test;
37
+
38
+ /**
39
+ * @author Roman Smirnov
40
+ *
41
+ */
42
+ public class ProcessDefinitionResourceAuthorizationTest extends AuthorizationTest {
43
+
44
+ protected static final String USER_TASK_PROCESS_KEY = "userTaskProcess";
45
+ protected static final String CALLING_USER_TASK_PROCESS_KEY = "CallingUserTaskProcess";
46
+
47
+ protected String deploymentId;
48
+
49
+ protected ProcessDefinitionResource resource;
50
+
51
+ @Override
52
+ @Before
53
+ public void setUp() throws Exception {
54
+ super.setUp();
55
+
56
+ runtimeService = processEngine.getRuntimeService();
57
+
58
+ deploymentId = createDeployment(null, "processes/user-task-process.bpmn", "processes/calling-user-task-process.bpmn").getId();
59
+
60
+ startProcessInstances(CALLING_USER_TASK_PROCESS_KEY, 3);
61
+ }
62
+
63
+ @Override
64
+ @After
65
+ public void tearDown() {
66
+ deleteDeployment(deploymentId);
67
+ super.tearDown();
68
+ }
69
+
70
+ @Test
71
+ public void testCalledProcessDefinitionQueryWithoutAuthorization() {
72
+ // given
73
+ String processDefinitionId = selectProcessDefinitionByKey(CALLING_USER_TASK_PROCESS_KEY).getId();
74
+ resource = new ProcessDefinitionResource(engineName, processDefinitionId);
75
+
76
+ ProcessDefinitionQueryDto queryParameter = new ProcessDefinitionQueryDto();
77
+
78
+ // when
79
+ List<ProcessDefinitionDto> calledDefinitions = resource.queryCalledProcessDefinitions(queryParameter);
80
+
81
+ // then
82
+ assertThat(calledDefinitions).isEmpty();
83
+ }
84
+
85
+ @Test
86
+ public void testCalledProcessDefinitionQueryWithReadPermissionOnProcessInstance() {
87
+ // given
88
+ String processDefinitionId = selectProcessDefinitionByKey(CALLING_USER_TASK_PROCESS_KEY).getId();
89
+ resource = new ProcessDefinitionResource(engineName, processDefinitionId);
90
+
91
+ String processInstanceId = selectAnyProcessInstanceByKey(CALLING_USER_TASK_PROCESS_KEY).getId();
92
+ createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, READ);
93
+
94
+ ProcessDefinitionQueryDto queryParameter = new ProcessDefinitionQueryDto();
95
+
96
+ // when
97
+ List<ProcessDefinitionDto> calledDefinitions = resource.queryCalledProcessDefinitions(queryParameter);
98
+
99
+ // then
100
+ assertThat(calledDefinitions).isNotEmpty();
101
+
102
+ ProcessDefinitionDto calledProcessDefinition = calledDefinitions.get(0);
103
+ assertThat(calledProcessDefinition.getKey()).isEqualTo(USER_TASK_PROCESS_KEY);
104
+ }
105
+
106
+ @Test
107
+ public void testCalledProcessDefinitionQueryWithReadPermissionOnAnyProcessInstance() {
108
+ // given
109
+ String processDefinitionId = selectProcessDefinitionByKey(CALLING_USER_TASK_PROCESS_KEY).getId();
110
+ resource = new ProcessDefinitionResource(engineName, processDefinitionId);
111
+
112
+ createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, READ);
113
+
114
+ ProcessDefinitionQueryDto queryParameter = new ProcessDefinitionQueryDto();
115
+
116
+ // when
117
+ List<ProcessDefinitionDto> calledDefinitions = resource.queryCalledProcessDefinitions(queryParameter);
118
+
119
+ // then
120
+ assertThat(calledDefinitions).isNotEmpty();
121
+
122
+ ProcessDefinitionDto calledProcessDefinition = calledDefinitions.get(0);
123
+ assertThat(calledProcessDefinition.getKey()).isEqualTo(USER_TASK_PROCESS_KEY);
124
+ }
125
+
126
+ @Test
127
+ public void testCalledProcessDefinitionQueryWithMultipleReadPermissions() {
128
+ // given
129
+ String processDefinitionId = selectProcessDefinitionByKey(CALLING_USER_TASK_PROCESS_KEY).getId();
130
+ resource = new ProcessDefinitionResource(engineName, processDefinitionId);
131
+
132
+ String processInstanceId = selectAnyProcessInstanceByKey(CALLING_USER_TASK_PROCESS_KEY).getId();
133
+ createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, READ);
134
+
135
+ createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, READ);
136
+
137
+ ProcessDefinitionQueryDto queryParameter = new ProcessDefinitionQueryDto();
138
+
139
+ // when
140
+ List<ProcessDefinitionDto> calledDefinitions = resource.queryCalledProcessDefinitions(queryParameter);
141
+
142
+ // then
143
+ assertThat(calledDefinitions.size()).isEqualTo(1);
144
+
145
+ ProcessDefinitionDto calledProcessDefinition = calledDefinitions.get(0);
146
+ assertThat(calledProcessDefinition.getKey()).isEqualTo(USER_TASK_PROCESS_KEY);
147
+ }
148
+
149
+ @Test
150
+ public void testCalledProcessDefinitionQueryWithReadInstancePermissionOnProcessDefinition() {
151
+ // given
152
+ String processDefinitionId = selectProcessDefinitionByKey(CALLING_USER_TASK_PROCESS_KEY).getId();
153
+ resource = new ProcessDefinitionResource(engineName, processDefinitionId);
154
+
155
+ createGrantAuthorization(PROCESS_DEFINITION, CALLING_USER_TASK_PROCESS_KEY, userId, READ_INSTANCE);
156
+
157
+ ProcessDefinitionQueryDto queryParameter = new ProcessDefinitionQueryDto();
158
+
159
+ // when
160
+ List<ProcessDefinitionDto> calledDefinitions = resource.queryCalledProcessDefinitions(queryParameter);
161
+
162
+ // then
163
+ assertThat(calledDefinitions).isNotEmpty();
164
+
165
+ ProcessDefinitionDto calledProcessDefinition = calledDefinitions.get(0);
166
+ assertThat(calledProcessDefinition.getKey()).isEqualTo(USER_TASK_PROCESS_KEY);
167
+ }
168
+
169
+ @Test
170
+ @Deployment(resources = {
171
+ "processes/another-user-task-process.bpmn",
172
+ "processes/dynamic-call-activity.bpmn"
173
+ })
174
+ public void testCalledProcessDefinitionQueryDifferentCalledProcesses() {
175
+ // given
176
+ String processDefinitionId = selectProcessDefinitionByKey("DynamicCallActivity").getId();
177
+ resource = new ProcessDefinitionResource(engineName, processDefinitionId);
178
+
179
+ disableAuthorization();
180
+ Map<String, Object> vars1 = new HashMap<String, Object>();
181
+ vars1.put("callProcess", "anotherUserTaskProcess");
182
+ String firstProcessInstanceId = runtimeService.startProcessInstanceByKey("DynamicCallActivity", vars1).getId();
183
+
184
+ Map<String, Object> vars2 = new HashMap<String, Object>();
185
+ vars2.put("callProcess", "userTaskProcess");
186
+ runtimeService.startProcessInstanceByKey("DynamicCallActivity", vars2);
187
+ enableAuthorization();
188
+
189
+ createGrantAuthorization(PROCESS_INSTANCE, firstProcessInstanceId, userId, READ);
190
+
191
+ ProcessDefinitionQueryDto queryParameter = new ProcessDefinitionQueryDto();
192
+
193
+ // when
194
+ List<ProcessDefinitionDto> calledDefinitions = resource.queryCalledProcessDefinitions(queryParameter);
195
+
196
+ // then
197
+ assertThat(calledDefinitions).isNotEmpty();
198
+
199
+ ProcessDefinitionDto calledProcessDefinition = calledDefinitions.get(0);
200
+ assertThat(calledProcessDefinition.getKey()).isEqualTo("anotherUserTaskProcess");
201
+ }
202
+
203
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/authorization/ProcessDefinitionRestServiceAuthorizationTest.java ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.cockpit.plugin.base.authorization;
18
+
19
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.ProcessDefinitionStatisticsDto;
20
+ import org.camunda.bpm.cockpit.impl.plugin.resources.ProcessDefinitionRestService;
21
+ import org.camunda.bpm.engine.rest.dto.CountResultDto;
22
+ import org.junit.After;
23
+ import org.junit.Before;
24
+ import org.junit.Test;
25
+ import org.mockito.Mockito;
26
+
27
+ import javax.ws.rs.core.MultivaluedHashMap;
28
+ import javax.ws.rs.core.MultivaluedMap;
29
+ import javax.ws.rs.core.UriInfo;
30
+ import java.util.List;
31
+
32
+ import static org.assertj.core.api.Assertions.assertThat;
33
+ import static org.assertj.core.api.Assertions.tuple;
34
+ import static org.camunda.bpm.engine.authorization.Authorization.ANY;
35
+ import static org.camunda.bpm.engine.authorization.Permissions.READ;
36
+ import static org.camunda.bpm.engine.authorization.Resources.PROCESS_DEFINITION;
37
+
38
+ public class ProcessDefinitionRestServiceAuthorizationTest extends AuthorizationTest {
39
+
40
+ private static final String USER_TASK_PROCESS_KEY = "userTaskProcess";
41
+ private static final String CALLING_USER_TASK_PROCESS_KEY = "CallingUserTaskProcess";
42
+ private String deploymentId;
43
+ private ProcessDefinitionRestService resource;
44
+ private UriInfo uriInfo;
45
+ private final MultivaluedMap<String, String> queryParameters = new MultivaluedHashMap<>();
46
+
47
+ @Override
48
+ @Before
49
+ public void setUp() throws Exception {
50
+ super.setUp();
51
+
52
+ resource = new ProcessDefinitionRestService(engineName);
53
+ runtimeService = processEngine.getRuntimeService();
54
+
55
+ deploymentId = createDeployment(null, "processes/user-task-process.bpmn", "processes/calling-user-task-process.bpmn").getId();
56
+
57
+ startProcessInstances(CALLING_USER_TASK_PROCESS_KEY, 3);
58
+
59
+ uriInfo = Mockito.mock(UriInfo.class);
60
+ Mockito.doReturn(queryParameters).when(uriInfo).getQueryParameters();
61
+ queryParameters.add("sortBy", "key");
62
+ queryParameters.add("sortOrder", "asc");
63
+ }
64
+
65
+ @Override
66
+ @After
67
+ public void tearDown() {
68
+ queryParameters.clear();
69
+ deleteDeployment(deploymentId);
70
+ super.tearDown();
71
+ }
72
+
73
+ @Test
74
+ public void queryStatisticsWithoutAuthorization() {
75
+ // when
76
+ List<ProcessDefinitionStatisticsDto> actual = resource.queryStatistics(uriInfo, null, null);
77
+
78
+ // then
79
+ assertThat(actual).isEmpty();
80
+ }
81
+
82
+ @Test
83
+ public void queryStatisticsWithReadPermissionOnProcessDefinition() {
84
+ // given
85
+ String key = selectProcessDefinitionByKey(CALLING_USER_TASK_PROCESS_KEY).getKey();
86
+ createGrantAuthorization(PROCESS_DEFINITION, key, userId, READ);
87
+
88
+ // when
89
+ List<ProcessDefinitionStatisticsDto> actual = resource.queryStatistics(uriInfo, null, null);
90
+
91
+ // then
92
+ assertThat(actual).hasSize(1);
93
+ assertThat(actual).extracting("key", "tenantId")
94
+ .containsOnly(tuple(CALLING_USER_TASK_PROCESS_KEY, null));
95
+ }
96
+
97
+ @Test
98
+ public void queryStatisticsWithReadPermissionOnAnyProcessDefinition() {
99
+ // given
100
+ createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ);
101
+
102
+ // when
103
+ List<ProcessDefinitionStatisticsDto> actual = resource.queryStatistics(uriInfo, null, null);
104
+
105
+ // then
106
+ assertThat(actual).hasSize(2);
107
+ assertThat(actual).extracting("key", "tenantId")
108
+ .containsOnly(tuple(CALLING_USER_TASK_PROCESS_KEY, null),
109
+ tuple(USER_TASK_PROCESS_KEY, null));
110
+ }
111
+
112
+ @Test
113
+ public void queryStatisticsWithMultipleReadPermissions() {
114
+ // given
115
+ String key = selectProcessDefinitionByKey(CALLING_USER_TASK_PROCESS_KEY).getKey();
116
+ createGrantAuthorization(PROCESS_DEFINITION, key, userId, READ);
117
+ createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ);
118
+
119
+ // when
120
+ List<ProcessDefinitionStatisticsDto> actual = resource.queryStatistics(uriInfo, null, null);
121
+
122
+ // then
123
+ assertThat(actual).hasSize(2);
124
+ assertThat(actual).extracting("key", "tenantId")
125
+ .containsOnly(tuple(CALLING_USER_TASK_PROCESS_KEY, null),
126
+ tuple(USER_TASK_PROCESS_KEY, null));
127
+ }
128
+
129
+ @Test
130
+ public void getStatisticsCountWithoutAuthorization() {
131
+ // when
132
+ CountResultDto actual = resource.getStatisticsCount(uriInfo);
133
+
134
+ // then
135
+ assertThat(actual.getCount()).isEqualTo(0);
136
+ }
137
+
138
+ @Test
139
+ public void getStatisticsCountWithReadPermissionOnProcessDefinition() {
140
+ // given
141
+ String key = selectProcessDefinitionByKey(CALLING_USER_TASK_PROCESS_KEY).getKey();
142
+ createGrantAuthorization(PROCESS_DEFINITION, key, userId, READ);
143
+
144
+ // when
145
+ CountResultDto actual = resource.getStatisticsCount(uriInfo);
146
+
147
+ // then
148
+ assertThat(actual.getCount()).isEqualTo(1);
149
+ }
150
+
151
+ @Test
152
+ public void getStatisticsCountWithReadPermissionOnAnyProcessDefinition() {
153
+ // given
154
+ createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ);
155
+
156
+ // when
157
+ CountResultDto actual = resource.getStatisticsCount(uriInfo);
158
+
159
+ // then
160
+ assertThat(actual.getCount()).isEqualTo(2);
161
+ }
162
+
163
+ @Test
164
+ public void getStatisticsCountWithMultipleReadPermissions() {
165
+ // given
166
+ String key = selectProcessDefinitionByKey(CALLING_USER_TASK_PROCESS_KEY).getKey();
167
+ createGrantAuthorization(PROCESS_DEFINITION, key, userId, READ);
168
+ createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ);
169
+
170
+ // when
171
+ CountResultDto actual = resource.getStatisticsCount(uriInfo);
172
+
173
+ // then
174
+ assertThat(actual.getCount()).isEqualTo(2);
175
+ }
176
+
177
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/authorization/ProcessInstanceResourceAuthorizationTest.java ADDED
@@ -0,0 +1,276 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.cockpit.plugin.base.authorization;
18
+
19
+ import static org.camunda.bpm.engine.authorization.Authorization.ANY;
20
+ import static org.camunda.bpm.engine.authorization.Permissions.READ;
21
+ import static org.camunda.bpm.engine.authorization.Permissions.READ_INSTANCE;
22
+ import static org.camunda.bpm.engine.authorization.Resources.PROCESS_DEFINITION;
23
+ import static org.camunda.bpm.engine.authorization.Resources.PROCESS_INSTANCE;
24
+ import static org.assertj.core.api.Assertions.assertThat;
25
+
26
+ import java.util.List;
27
+
28
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.CalledProcessInstanceDto;
29
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.query.CalledProcessInstanceQueryDto;
30
+ import org.camunda.bpm.cockpit.impl.plugin.base.sub.resources.ProcessInstanceResource;
31
+ import org.camunda.bpm.engine.impl.db.AuthorizationCheck;
32
+ import org.camunda.bpm.engine.impl.db.PermissionCheck;
33
+ import org.camunda.bpm.engine.impl.identity.Authentication;
34
+ import org.junit.After;
35
+ import org.junit.Before;
36
+ import org.junit.Test;
37
+
38
+ /**
39
+ * @author Roman Smirnov
40
+ *
41
+ */
42
+ public class ProcessInstanceResourceAuthorizationTest extends AuthorizationTest {
43
+
44
+ protected static final String USER_TASK_PROCESS_KEY = "userTaskProcess";
45
+ protected static final String CALLING_USER_TASK_PROCESS_KEY = "CallingUserTaskProcess";
46
+
47
+ protected String deploymentId;
48
+
49
+ protected ProcessInstanceResource resource;
50
+
51
+ @Override
52
+ @Before
53
+ public void setUp() throws Exception {
54
+ super.setUp();
55
+
56
+ runtimeService = processEngine.getRuntimeService();
57
+
58
+ deploymentId = createDeployment(null, "processes/user-task-process.bpmn", "processes/calling-user-task-process.bpmn").getId();
59
+
60
+ startProcessInstances(CALLING_USER_TASK_PROCESS_KEY, 3);
61
+ }
62
+
63
+ @Override
64
+ @After
65
+ public void tearDown() {
66
+ deleteDeployment(deploymentId);
67
+ super.tearDown();
68
+ }
69
+
70
+ // ProcessInstanceResource#queryCalledProcessInstances() /////////////////////////////
71
+
72
+ @Test
73
+ public void testCalledInstancesWithoutAuthorization() {
74
+ // given
75
+ String processInstanceId = selectAnyProcessInstanceByKey(CALLING_USER_TASK_PROCESS_KEY).getId();
76
+
77
+ resource = new ProcessInstanceResource(engineName, processInstanceId);
78
+
79
+ CalledProcessInstanceQueryDto queryParameter = new CalledProcessInstanceQueryDto();
80
+
81
+ // when
82
+ List<CalledProcessInstanceDto> calledInstances = resource.queryCalledProcessInstances(queryParameter);
83
+
84
+ // then
85
+ assertThat(calledInstances).isEmpty();
86
+ }
87
+
88
+ @Test
89
+ public void testCalledInstancesWithReadPermissionOnProcessInstance() {
90
+ // given
91
+ String processInstanceId = selectAnyProcessInstanceByKey(CALLING_USER_TASK_PROCESS_KEY).getId();
92
+ createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, READ);
93
+
94
+ resource = new ProcessInstanceResource(engineName, processInstanceId);
95
+
96
+ CalledProcessInstanceQueryDto queryParameter = new CalledProcessInstanceQueryDto();
97
+
98
+ // when
99
+ List<CalledProcessInstanceDto> calledInstances = resource.queryCalledProcessInstances(queryParameter);
100
+
101
+ // then
102
+ assertThat(calledInstances).isNotEmpty();
103
+ assertThat(calledInstances).hasSize(1);
104
+ assertThat(calledInstances.get(0).getId()).isNotEqualTo(processInstanceId);
105
+ }
106
+
107
+ @Test
108
+ public void testCalledInstancesWithReadPermissionOnAnyProcessInstance() {
109
+ // given
110
+ String processInstanceId = selectAnyProcessInstanceByKey(CALLING_USER_TASK_PROCESS_KEY).getId();
111
+ createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, READ);
112
+
113
+ resource = new ProcessInstanceResource(engineName, processInstanceId);
114
+
115
+ CalledProcessInstanceQueryDto queryParameter = new CalledProcessInstanceQueryDto();
116
+
117
+ // when
118
+ List<CalledProcessInstanceDto> calledInstances = resource.queryCalledProcessInstances(queryParameter);
119
+
120
+ // then
121
+ assertThat(calledInstances).isNotEmpty();
122
+ assertThat(calledInstances).hasSize(1);
123
+ assertThat(calledInstances.get(0).getId()).isNotEqualTo(processInstanceId);
124
+ }
125
+
126
+ @Test
127
+ public void testCalledInstancesWithReadPermissionOnProcessDefinition() {
128
+ // given
129
+ createGrantAuthorization(PROCESS_DEFINITION, CALLING_USER_TASK_PROCESS_KEY, userId, READ_INSTANCE);
130
+
131
+ String processInstanceId = selectAnyProcessInstanceByKey(CALLING_USER_TASK_PROCESS_KEY).getId();
132
+ resource = new ProcessInstanceResource(engineName, processInstanceId);
133
+
134
+ CalledProcessInstanceQueryDto queryParameter = new CalledProcessInstanceQueryDto();
135
+
136
+ // when
137
+ List<CalledProcessInstanceDto> calledInstances = resource.queryCalledProcessInstances(queryParameter);
138
+
139
+ // then
140
+ assertThat(calledInstances).isNotEmpty();
141
+ assertThat(calledInstances).hasSize(1);
142
+ assertThat(calledInstances.get(0).getId()).isNotEqualTo(processInstanceId);
143
+ }
144
+
145
+ @Test
146
+ public void testCalledInstancesWithMultipleReadPermissions() {
147
+ // given
148
+ String processInstanceId = selectAnyProcessInstanceByKey(CALLING_USER_TASK_PROCESS_KEY).getId();
149
+ createGrantAuthorization(PROCESS_DEFINITION, CALLING_USER_TASK_PROCESS_KEY, userId, READ_INSTANCE);
150
+ createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, READ);
151
+
152
+ resource = new ProcessInstanceResource(engineName, processInstanceId);
153
+
154
+ CalledProcessInstanceQueryDto queryParameter = new CalledProcessInstanceQueryDto();
155
+
156
+ // when
157
+ List<CalledProcessInstanceDto> calledInstances = resource.queryCalledProcessInstances(queryParameter);
158
+
159
+ // then
160
+ assertThat(calledInstances).isNotEmpty();
161
+ assertThat(calledInstances).hasSize(1);
162
+ assertThat(calledInstances.get(0).getId()).isNotEqualTo(processInstanceId);
163
+ }
164
+
165
+
166
+ // query "selectCalledProcessInstances" //////////////////////////////////////////////
167
+
168
+ @Test
169
+ public void testCalledInstancesQueryWithoutAuthorization() {
170
+ // given
171
+ CalledProcessInstanceQueryDto queryParameter = new CalledProcessInstanceQueryDto();
172
+
173
+ // when
174
+ List<CalledProcessInstanceDto> calledInstances = executeCalledInstancesQueryWithAuthorization(queryParameter);
175
+
176
+ // then
177
+ assertThat(calledInstances).isEmpty();
178
+ }
179
+
180
+ @Test
181
+ public void testCalledInstancesQueryWithReadPermissionOnProcessInstance() {
182
+ // given
183
+ String processInstanceId = selectAnyProcessInstanceByKey(CALLING_USER_TASK_PROCESS_KEY).getId();
184
+ createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, READ);
185
+
186
+ CalledProcessInstanceQueryDto queryParameter = new CalledProcessInstanceQueryDto();
187
+
188
+ // when
189
+ List<CalledProcessInstanceDto> calledInstances = executeCalledInstancesQueryWithAuthorization(queryParameter);
190
+
191
+ // then
192
+ assertThat(calledInstances).isNotEmpty();
193
+ assertThat(calledInstances).hasSize(1);
194
+ assertThat(calledInstances.get(0).getId()).isNotEqualTo(processInstanceId);
195
+ }
196
+
197
+ @Test
198
+ public void testCalledInstancesQueryWithReadPermissionOnAnyProcessInstance() {
199
+ // given
200
+ createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, READ);
201
+
202
+ CalledProcessInstanceQueryDto queryParameter = new CalledProcessInstanceQueryDto();
203
+
204
+ // when
205
+ List<CalledProcessInstanceDto> calledInstances = executeCalledInstancesQueryWithAuthorization(queryParameter);
206
+
207
+ // then
208
+ assertThat(calledInstances).isNotEmpty();
209
+ assertThat(calledInstances).hasSize(3);
210
+ }
211
+
212
+ @Test
213
+ public void testCalledInstancesQueryWithReadInstancePermissionOnProcessDefinition() {
214
+ // given
215
+ createGrantAuthorization(PROCESS_DEFINITION, CALLING_USER_TASK_PROCESS_KEY, userId, READ_INSTANCE);
216
+
217
+ CalledProcessInstanceQueryDto queryParameter = new CalledProcessInstanceQueryDto();
218
+
219
+ // when
220
+ List<CalledProcessInstanceDto> calledInstances = executeCalledInstancesQueryWithAuthorization(queryParameter);
221
+
222
+ // then
223
+ assertThat(calledInstances).isNotEmpty();
224
+ assertThat(calledInstances).hasSize(3);
225
+ }
226
+
227
+ @Test
228
+ public void testCalledInstancesQueryWithMultipleReadPermissins() {
229
+ // given
230
+ createGrantAuthorization(PROCESS_DEFINITION, CALLING_USER_TASK_PROCESS_KEY, userId, READ_INSTANCE);
231
+ createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, READ);
232
+
233
+ CalledProcessInstanceQueryDto queryParameter = new CalledProcessInstanceQueryDto();
234
+
235
+ // when
236
+ List<CalledProcessInstanceDto> calledInstances = executeCalledInstancesQueryWithAuthorization(queryParameter);
237
+
238
+ // then
239
+ assertThat(calledInstances).isNotEmpty();
240
+ assertThat(calledInstances).hasSize(3);
241
+ }
242
+
243
+ // helper ////////////////////////////////////////////////////////////////////////////
244
+
245
+ protected Authentication getCurrentAuthentication() {
246
+ return identityService.getCurrentAuthentication();
247
+ }
248
+
249
+ protected List<CalledProcessInstanceDto> executeCalledInstancesQueryWithAuthorization(CalledProcessInstanceQueryDto query) {
250
+ Authentication currentAuthentication = getCurrentAuthentication();
251
+
252
+ AuthorizationCheck authCheck = query.getAuthCheck();
253
+
254
+ authCheck.getPermissionChecks().clear();
255
+ authCheck.setAuthorizationCheckEnabled(true);
256
+ String currentUserId = currentAuthentication.getUserId();
257
+ List<String> currentGroupIds = currentAuthentication.getGroupIds();
258
+ authCheck.setAuthUserId(currentUserId);
259
+ authCheck.setAuthGroupIds(currentGroupIds);
260
+
261
+ PermissionCheck firstPermCheck = new PermissionCheck();
262
+ firstPermCheck.setResource(PROCESS_INSTANCE);
263
+ firstPermCheck.setResourceIdQueryParam("EXEC1.PROC_INST_ID_");
264
+ firstPermCheck.setPermission(READ);
265
+ authCheck.addAtomicPermissionCheck(firstPermCheck);
266
+
267
+ PermissionCheck secondPermCheck = new PermissionCheck();
268
+ secondPermCheck.setResource(PROCESS_DEFINITION);
269
+ secondPermCheck.setResourceIdQueryParam("PROCDEF.KEY_");
270
+ secondPermCheck.setPermission(READ_INSTANCE);
271
+ authCheck.addAtomicPermissionCheck(secondPermCheck);
272
+
273
+ return getQueryService().executeQuery("selectCalledProcessInstances", query);
274
+ }
275
+
276
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/authorization/ProcessInstanceRestServiceAuthorizationTest.java ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.cockpit.plugin.base.authorization;
18
+
19
+ import static org.camunda.bpm.engine.authorization.Authorization.ANY;
20
+ import static org.camunda.bpm.engine.authorization.Permissions.READ;
21
+ import static org.camunda.bpm.engine.authorization.Permissions.READ_INSTANCE;
22
+ import static org.camunda.bpm.engine.authorization.Resources.PROCESS_DEFINITION;
23
+ import static org.camunda.bpm.engine.authorization.Resources.PROCESS_INSTANCE;
24
+ import static org.assertj.core.api.Assertions.assertThat;
25
+
26
+ import java.util.List;
27
+
28
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.ProcessInstanceDto;
29
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.query.ProcessInstanceQueryDto;
30
+ import org.camunda.bpm.cockpit.impl.plugin.resources.ProcessInstanceRestService;
31
+ import org.junit.After;
32
+ import org.junit.Before;
33
+ import org.junit.Test;
34
+
35
+ /**
36
+ * @author Roman Smirnov
37
+ *
38
+ */
39
+ public class ProcessInstanceRestServiceAuthorizationTest extends AuthorizationTest {
40
+
41
+ protected static final String USER_TASK_PROCESS_KEY = "userTaskProcess";
42
+
43
+ protected String deploymentId;
44
+
45
+ protected ProcessInstanceRestService resource;
46
+
47
+ @Override
48
+ @Before
49
+ public void setUp() throws Exception {
50
+ super.setUp();
51
+
52
+ deploymentId = createDeployment(null, "processes/user-task-process.bpmn").getId();
53
+
54
+ startProcessInstances(USER_TASK_PROCESS_KEY, 3);
55
+
56
+ resource = new ProcessInstanceRestService(engineName);
57
+ }
58
+
59
+ @Override
60
+ @After
61
+ public void tearDown() {
62
+ deleteDeployment(deploymentId);
63
+ super.tearDown();
64
+ }
65
+
66
+ @Test
67
+ public void testQueryWithoutAuthorization() {
68
+ // given
69
+ ProcessInstanceQueryDto queryParameter = new ProcessInstanceQueryDto();
70
+
71
+ // when
72
+ List<ProcessInstanceDto> instances = resource.queryProcessInstances(queryParameter, null, null);
73
+
74
+ // then
75
+ assertThat(instances).isEmpty();
76
+ }
77
+
78
+ @Test
79
+ public void testQueryWithReadPermissionOnProcessInstance() {
80
+ // given
81
+ String processInstanceId = selectAnyProcessInstanceByKey(USER_TASK_PROCESS_KEY).getId();
82
+
83
+ createGrantAuthorization(PROCESS_INSTANCE, processInstanceId, userId, READ);
84
+
85
+ ProcessInstanceQueryDto queryParameter = new ProcessInstanceQueryDto();
86
+
87
+ // when
88
+ List<ProcessInstanceDto> instances = resource.queryProcessInstances(queryParameter, null, null);
89
+
90
+ // then
91
+ assertThat(instances).isNotEmpty();
92
+ assertThat(instances).hasSize(1);
93
+ assertThat(instances.get(0).getId()).isEqualTo(processInstanceId);
94
+ }
95
+
96
+ @Test
97
+ public void testQueryWithReadPermissionOnAnyProcessInstance() {
98
+ // given
99
+ createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, READ);
100
+
101
+ ProcessInstanceQueryDto queryParameter = new ProcessInstanceQueryDto();
102
+
103
+ // when
104
+ List<ProcessInstanceDto> instances = resource.queryProcessInstances(queryParameter, null, null);
105
+
106
+ // then
107
+ assertThat(instances).isNotEmpty();
108
+ assertThat(instances).hasSize(3);
109
+ }
110
+
111
+ @Test
112
+ public void testQueryWithReadInstancePermissionOnProcessDefinition() {
113
+ // given
114
+ createGrantAuthorization(PROCESS_DEFINITION, USER_TASK_PROCESS_KEY, userId, READ_INSTANCE);
115
+
116
+ ProcessInstanceQueryDto queryParameter = new ProcessInstanceQueryDto();
117
+
118
+ // when
119
+ List<ProcessInstanceDto> instances = resource.queryProcessInstances(queryParameter, null, null);
120
+
121
+ // then
122
+ assertThat(instances).isNotEmpty();
123
+ assertThat(instances).hasSize(3);
124
+ }
125
+
126
+ @Test
127
+ public void testQueryPaginationWithOverlappingPermissions() {
128
+ // given
129
+ createGrantAuthorization(PROCESS_DEFINITION, USER_TASK_PROCESS_KEY, userId, READ_INSTANCE);
130
+ createGrantAuthorization(PROCESS_INSTANCE, ANY, userId, READ);
131
+
132
+ ProcessInstanceQueryDto queryParameter = new ProcessInstanceQueryDto();
133
+
134
+ // when
135
+ List<ProcessInstanceDto> result = resource.queryProcessInstances(queryParameter, 0, 3);
136
+
137
+ // then
138
+ assertThat(result).isNotEmpty();
139
+ assertThat(result).hasSize(3);
140
+
141
+ result = resource.queryProcessInstances(queryParameter, 0, 2);
142
+ assertThat(result).isNotEmpty();
143
+ assertThat(result).hasSize(2);
144
+
145
+ result = resource.queryProcessInstances(queryParameter, 2, 2);
146
+ assertThat(result).isNotEmpty();
147
+ assertThat(result).hasSize(1);
148
+ }
149
+
150
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/pa/CreateIncidentsDelegate.java ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.cockpit.plugin.base.pa;
18
+
19
+ import org.camunda.bpm.engine.delegate.DelegateExecution;
20
+ import org.camunda.bpm.engine.delegate.JavaDelegate;
21
+ import org.camunda.bpm.engine.impl.incident.IncidentContext;
22
+ import org.camunda.bpm.engine.impl.persistence.entity.IncidentEntity;
23
+
24
+ public class CreateIncidentsDelegate implements JavaDelegate {
25
+
26
+ @Override
27
+ public void execute(DelegateExecution execution) throws Exception {
28
+
29
+ IncidentEntity.createAndInsertIncident("anIncident", createIncidentContext(execution, "test1"), "aMessage");
30
+ IncidentEntity.createAndInsertIncident("anIncident", createIncidentContext(execution, "test2"), "aMessage");
31
+ IncidentEntity.createAndInsertIncident("anIncident", createIncidentContext(execution, "test3"), "aMessage");
32
+
33
+ IncidentEntity.createAndInsertIncident("anotherIncident", createIncidentContext(execution, "test1"), "anotherMessage");
34
+ IncidentEntity.createAndInsertIncident("anotherIncident", createIncidentContext(execution, "test2"), "anotherMessage");
35
+ IncidentEntity.createAndInsertIncident("anotherIncident", createIncidentContext(execution, "test3"), "anotherMessage");
36
+ IncidentEntity.createAndInsertIncident("anotherIncident", createIncidentContext(execution, "test4"), "anotherMessage");
37
+ IncidentEntity.createAndInsertIncident("anotherIncident", createIncidentContext(execution, "test5"), "anotherMessage");
38
+ }
39
+
40
+ private IncidentContext createIncidentContext(DelegateExecution execution, String configuration) {
41
+ IncidentContext incidentContext = new IncidentContext();
42
+ incidentContext.setExecutionId(execution.getId());
43
+ incidentContext.setActivityId(execution.getCurrentActivityId());
44
+ incidentContext.setProcessDefinitionId(execution.getProcessDefinitionId());
45
+ incidentContext.setTenantId(execution.getTenantId());
46
+ incidentContext.setConfiguration(configuration);
47
+ return incidentContext;
48
+ }
49
+
50
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/pa/FailingDelegate.java ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.cockpit.plugin.base.pa;
18
+
19
+ import org.camunda.bpm.engine.delegate.DelegateExecution;
20
+ import org.camunda.bpm.engine.delegate.JavaDelegate;
21
+
22
+ public class FailingDelegate implements JavaDelegate {
23
+
24
+ @Override
25
+ public void execute(DelegateExecution execution) throws Exception {
26
+ throw new RuntimeException("I am failing!");
27
+ }
28
+
29
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/pa/VariableSavingDelegate.java ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.cockpit.plugin.base.pa;
18
+
19
+ import org.camunda.bpm.engine.delegate.DelegateExecution;
20
+ import org.camunda.bpm.engine.delegate.JavaDelegate;
21
+
22
+ public class VariableSavingDelegate implements JavaDelegate {
23
+
24
+ @Override
25
+ public void execute(DelegateExecution execution) throws Exception {
26
+
27
+ execution.setVariable("varstring", "FOO");
28
+ execution.setVariable("varstring2", "F_OO");
29
+ execution.setVariable("varinteger", 12);
30
+ execution.setVariable("varfloat", 12.12);
31
+ execution.setVariable("varboolean", true);
32
+ }
33
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/tenantcheck/IncidentRestServiceTenantCheckTest.java ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.cockpit.plugin.base.tenantcheck;
18
+
19
+ import static org.assertj.core.api.Assertions.assertThat;
20
+
21
+ import java.util.Arrays;
22
+ import java.util.Collections;
23
+ import java.util.HashSet;
24
+ import java.util.List;
25
+ import java.util.Set;
26
+
27
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.IncidentDto;
28
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.query.IncidentQueryDto;
29
+ import org.camunda.bpm.cockpit.impl.plugin.resources.IncidentRestService;
30
+ import org.camunda.bpm.cockpit.plugin.test.AbstractCockpitPluginTest;
31
+ import org.camunda.bpm.engine.IdentityService;
32
+ import org.camunda.bpm.engine.ProcessEngine;
33
+ import org.camunda.bpm.engine.RuntimeService;
34
+ import org.camunda.bpm.engine.authorization.Groups;
35
+ import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
36
+ import org.junit.After;
37
+ import org.junit.Before;
38
+ import org.junit.Test;
39
+
40
+ public class IncidentRestServiceTenantCheckTest extends AbstractCockpitPluginTest {
41
+
42
+ protected static final String TENANT_ONE = "tenant1";
43
+ protected static final String TENANT_TWO = "tenant2";
44
+ protected static final String ADMIN_GROUP = "adminGroup";
45
+ protected static final String ADMIN_USER = "adminUser";
46
+
47
+ private ProcessEngine processEngine;
48
+ private ProcessEngineConfigurationImpl processEngineConfiguration;
49
+ private RuntimeService runtimeService;
50
+ private IdentityService identityService;
51
+
52
+ private IncidentRestService resource;
53
+ private IncidentQueryDto queryParameter;
54
+
55
+ private String processInstanceTenantOne;
56
+ private String processInstanceTenantTwo;
57
+
58
+ @Before
59
+ public void init() throws Exception {
60
+
61
+ processEngine = getProcessEngine();
62
+ processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
63
+
64
+ runtimeService = processEngine.getRuntimeService();
65
+ identityService = processEngine.getIdentityService();
66
+
67
+ processEngineConfiguration.getAdminGroups().add(ADMIN_GROUP);
68
+ processEngineConfiguration.getAdminUsers().add(ADMIN_USER);
69
+
70
+ resource = new IncidentRestService(processEngine.getName());
71
+
72
+ deployForTenant(TENANT_ONE, "processes/failing-process.bpmn");
73
+ deployForTenant(TENANT_TWO, "processes/failing-process.bpmn");
74
+
75
+ processInstanceTenantOne = runtimeService.createProcessInstanceByKey("FailingProcess")
76
+ .processDefinitionTenantId(TENANT_ONE).execute().getId();
77
+
78
+ processInstanceTenantTwo = runtimeService.createProcessInstanceByKey("FailingProcess")
79
+ .processDefinitionTenantId(TENANT_TWO).execute().getId();
80
+
81
+ executeAvailableJobs();
82
+
83
+ queryParameter = new IncidentQueryDto();
84
+ queryParameter.setProcessInstanceIdIn(new String[]{processInstanceTenantOne, processInstanceTenantTwo});
85
+ }
86
+
87
+ @After
88
+ public void tearDown() {
89
+ processEngineConfiguration.getAdminGroups().remove(ADMIN_GROUP);
90
+ processEngineConfiguration.getAdminUsers().remove(ADMIN_USER);
91
+ }
92
+
93
+ @Test
94
+ public void queryIncidentsByProcessInstanceIdsNoAuthenticatedTenants() {
95
+
96
+ identityService.setAuthentication("user", null, null);
97
+
98
+ List<IncidentDto> result = resource.queryIncidents(queryParameter, null, null);
99
+ assertThat(result).isEmpty();
100
+ }
101
+
102
+ @Test
103
+ public void queryIncidentsByProcessInstanceIdsWithAuthenticatedTenant() {
104
+
105
+ identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE));
106
+
107
+ List<IncidentDto> result = resource.queryIncidents(queryParameter, null, null);
108
+ assertThat(result).isNotEmpty();
109
+ assertThat(result).hasSize(1);
110
+
111
+ IncidentDto incident = result.get(0);
112
+ assertThat(incident.getProcessInstanceId()).isEqualTo(processInstanceTenantOne);
113
+ }
114
+
115
+ @Test
116
+ public void queryIncidentsByProcessInstanceIdsDisabledTenantCheck() {
117
+
118
+ processEngineConfiguration.setTenantCheckEnabled(false);
119
+ identityService.setAuthentication("user", null, null);
120
+
121
+ List<IncidentDto> result = resource.queryIncidents(queryParameter, null, null);
122
+ assertThat(result).hasSize(2);
123
+
124
+ Set<String> processInstnaceIds = new HashSet<>();
125
+ for (IncidentDto incidentDto : result) {
126
+ processInstnaceIds.add(incidentDto.getProcessInstanceId());
127
+ }
128
+
129
+ assertThat(processInstnaceIds).contains(processInstanceTenantOne);
130
+ assertThat(processInstnaceIds).contains(processInstanceTenantTwo);
131
+ }
132
+
133
+ @Test
134
+ public void queryIncidentsByProcessInstanceIdsWithCamundaAdmin() {
135
+
136
+ identityService.setAuthentication("user", Collections.singletonList(Groups.CAMUNDA_ADMIN), null);
137
+
138
+
139
+ List<IncidentDto> result = resource.queryIncidents(queryParameter, null, null);
140
+ assertThat(result).hasSize(2);
141
+
142
+ Set<String> processInstnaceIds = new HashSet<>();
143
+ for (IncidentDto incidentDto : result) {
144
+ processInstnaceIds.add(incidentDto.getProcessInstanceId());
145
+ }
146
+
147
+ assertThat(processInstnaceIds).contains(processInstanceTenantOne);
148
+ assertThat(processInstnaceIds).contains(processInstanceTenantTwo);
149
+ }
150
+
151
+ @Test
152
+ public void queryIncidentsByProcessInstanceIdsWithAdminGroups() {
153
+
154
+ identityService.setAuthentication("user", Collections.singletonList(ADMIN_GROUP), null);
155
+
156
+
157
+ List<IncidentDto> result = resource.queryIncidents(queryParameter, null, null);
158
+ assertThat(result).hasSize(2);
159
+
160
+ Set<String> processInstnaceIds = new HashSet<>();
161
+ for (IncidentDto incidentDto : result) {
162
+ processInstnaceIds.add(incidentDto.getProcessInstanceId());
163
+ }
164
+
165
+ assertThat(processInstnaceIds).contains(processInstanceTenantOne);
166
+ assertThat(processInstnaceIds).contains(processInstanceTenantTwo);
167
+ }
168
+
169
+ @Test
170
+ public void queryIncidentsByProcessInstanceIdsWithAdminUsers() {
171
+
172
+ identityService.setAuthentication("adminUser", null, null);
173
+
174
+
175
+ List<IncidentDto> result = resource.queryIncidents(queryParameter, null, null);
176
+ assertThat(result).hasSize(2);
177
+
178
+ Set<String> processInstnaceIds = new HashSet<>();
179
+ for (IncidentDto incidentDto : result) {
180
+ processInstnaceIds.add(incidentDto.getProcessInstanceId());
181
+ }
182
+
183
+ assertThat(processInstnaceIds).contains(processInstanceTenantOne);
184
+ assertThat(processInstnaceIds).contains(processInstanceTenantTwo);
185
+ }
186
+
187
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/tenantcheck/ProcessDefinitionResourceTenantCheckTest.java ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.cockpit.plugin.base.tenantcheck;
18
+
19
+ import static org.assertj.core.api.Assertions.assertThat;
20
+
21
+ import java.util.ArrayList;
22
+ import java.util.Arrays;
23
+ import java.util.Collections;
24
+ import java.util.List;
25
+
26
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.ProcessDefinitionDto;
27
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.query.ProcessDefinitionQueryDto;
28
+ import org.camunda.bpm.cockpit.impl.plugin.base.sub.resources.ProcessDefinitionResource;
29
+ import org.camunda.bpm.cockpit.plugin.test.AbstractCockpitPluginTest;
30
+ import org.camunda.bpm.engine.IdentityService;
31
+ import org.camunda.bpm.engine.ProcessEngine;
32
+ import org.camunda.bpm.engine.RuntimeService;
33
+ import org.camunda.bpm.engine.authorization.Groups;
34
+ import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
35
+ import org.camunda.bpm.engine.runtime.ProcessInstance;
36
+ import org.junit.After;
37
+ import org.junit.Before;
38
+ import org.junit.Test;
39
+
40
+ public class ProcessDefinitionResourceTenantCheckTest extends AbstractCockpitPluginTest {
41
+
42
+ protected static final String TENANT_ONE = "tenant1";
43
+ protected static final String TENANT_TWO = "tenant2";
44
+ protected static final String ADMIN_GROUP = "adminGroup";
45
+ protected static final String ADMIN_USER = "adminUser";
46
+
47
+ private ProcessEngine processEngine;
48
+ private ProcessEngineConfigurationImpl processEngineConfiguration;
49
+ private RuntimeService runtimeService;
50
+ private IdentityService identityService;
51
+
52
+ private ProcessDefinitionResource resource;
53
+ private ProcessDefinitionQueryDto queryParameter;
54
+
55
+ @Before
56
+ public void init() throws Exception {
57
+
58
+ processEngine = getProcessEngine();
59
+ processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
60
+
61
+ runtimeService = processEngine.getRuntimeService();
62
+ identityService = processEngine.getIdentityService();
63
+
64
+ processEngineConfiguration.getAdminGroups().add(ADMIN_GROUP);
65
+ processEngineConfiguration.getAdminUsers().add(ADMIN_USER);
66
+
67
+ deploy("processes/multi-tenancy-call-activity.bpmn");
68
+ deployForTenant(TENANT_ONE, "processes/user-task-process.bpmn");
69
+ deployForTenant(TENANT_TWO, "processes/user-task-process.bpmn");
70
+
71
+
72
+ ProcessInstance processInstance = runtimeService.createProcessInstanceByKey("multiTenancyCallActivity").execute();
73
+
74
+ resource = new ProcessDefinitionResource(getProcessEngine().getName(), processInstance.getProcessDefinitionId());
75
+
76
+ queryParameter = new ProcessDefinitionQueryDto();
77
+ }
78
+
79
+ @After
80
+ public void tearDown() {
81
+ processEngineConfiguration.getAdminGroups().remove(ADMIN_GROUP);
82
+ processEngineConfiguration.getAdminUsers().remove(ADMIN_USER);
83
+ }
84
+
85
+ @Test
86
+ public void calledProcessDefinitionByParentProcessDefinitionIdNoAuthenticatedTenant() {
87
+
88
+ identityService.setAuthentication("user", null, null);
89
+
90
+ List<ProcessDefinitionDto> result = resource.queryCalledProcessDefinitions(queryParameter);
91
+ assertThat(result).isEmpty();
92
+ }
93
+
94
+ @Test
95
+ public void calledProcessDefinitionByParentProcessDefinitionIdWithAuthenticatedTenant() {
96
+
97
+ identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE));
98
+
99
+ List<ProcessDefinitionDto> result = resource.queryCalledProcessDefinitions(queryParameter);
100
+ assertThat(result).isNotEmpty();
101
+ assertThat(result).hasSize(1);
102
+
103
+ assertThat(getCalledFromActivityIds(result)).containsOnly("CallActivity_Tenant1");
104
+ }
105
+
106
+ @Test
107
+ public void calledProcessDefinitionByParentProcessDefinitionIdDisabledTenantCheck() {
108
+
109
+ processEngineConfiguration.setTenantCheckEnabled(false);
110
+ identityService.setAuthentication("user", null, null);
111
+
112
+ List<ProcessDefinitionDto> result = resource.queryCalledProcessDefinitions(queryParameter);
113
+ assertThat(result).isNotEmpty();
114
+ assertThat(result).hasSize(2);
115
+
116
+ assertThat(getCalledFromActivityIds(result)).contains("CallActivity_Tenant1", "CallActivity_Tenant2");
117
+ }
118
+
119
+ @Test
120
+ public void calledProcessDefinitionByParentProcessDefinitionIdWithCamundaAdmin() {
121
+
122
+ identityService.setAuthentication("user", Collections.singletonList(Groups.CAMUNDA_ADMIN), null);
123
+
124
+ List<ProcessDefinitionDto> result = resource.queryCalledProcessDefinitions(queryParameter);
125
+ assertThat(result).isNotEmpty();
126
+ assertThat(result).hasSize(2);
127
+
128
+ assertThat(getCalledFromActivityIds(result)).contains("CallActivity_Tenant1", "CallActivity_Tenant2");
129
+ }
130
+
131
+ @Test
132
+ public void calledProcessDefinitionByParentProcessDefinitionIdWithAdminGroups() {
133
+
134
+ identityService.setAuthentication("user", Collections.singletonList(ADMIN_GROUP), null);
135
+
136
+ List<ProcessDefinitionDto> result = resource.queryCalledProcessDefinitions(queryParameter);
137
+ assertThat(result).isNotEmpty();
138
+ assertThat(result).hasSize(2);
139
+
140
+ assertThat(getCalledFromActivityIds(result)).contains("CallActivity_Tenant1", "CallActivity_Tenant2");
141
+ }
142
+
143
+ @Test
144
+ public void calledProcessDefinitionByParentProcessDefinitionIdWithAdminUsers() {
145
+
146
+ identityService.setAuthentication("adminUser", null, null);
147
+
148
+ List<ProcessDefinitionDto> result = resource.queryCalledProcessDefinitions(queryParameter);
149
+ assertThat(result).isNotEmpty();
150
+ assertThat(result).hasSize(2);
151
+
152
+ assertThat(getCalledFromActivityIds(result)).contains("CallActivity_Tenant1", "CallActivity_Tenant2");
153
+ }
154
+
155
+ protected List<String> getCalledFromActivityIds(List<ProcessDefinitionDto> processDefinitions) {
156
+ List<String> activityIds = new ArrayList<>();
157
+
158
+ for (ProcessDefinitionDto processDefinition : processDefinitions) {
159
+ activityIds.addAll(processDefinition.getCalledFromActivityIds());
160
+ }
161
+
162
+ return activityIds;
163
+ }
164
+
165
+
166
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/tenantcheck/ProcessDefinitionRestServiceTenantCheckTest.java ADDED
@@ -0,0 +1,251 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.cockpit.plugin.base.tenantcheck;
18
+
19
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.ProcessDefinitionStatisticsDto;
20
+ import org.camunda.bpm.cockpit.impl.plugin.resources.ProcessDefinitionRestService;
21
+ import org.camunda.bpm.cockpit.plugin.test.AbstractCockpitPluginTest;
22
+ import org.camunda.bpm.engine.IdentityService;
23
+ import org.camunda.bpm.engine.ProcessEngine;
24
+ import org.camunda.bpm.engine.authorization.Groups;
25
+ import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
26
+ import org.camunda.bpm.engine.rest.dto.CountResultDto;
27
+ import org.junit.After;
28
+ import org.junit.Before;
29
+ import org.junit.Test;
30
+ import org.mockito.Mockito;
31
+
32
+ import javax.ws.rs.core.MultivaluedHashMap;
33
+ import javax.ws.rs.core.MultivaluedMap;
34
+ import javax.ws.rs.core.UriInfo;
35
+ import java.util.Collections;
36
+ import java.util.List;
37
+
38
+ import static org.assertj.core.api.Assertions.assertThat;
39
+ import static org.assertj.core.api.Assertions.tuple;
40
+
41
+ public class ProcessDefinitionRestServiceTenantCheckTest extends AbstractCockpitPluginTest {
42
+
43
+ protected static final String TENANT_ONE = "tenant1";
44
+ protected static final String TENANT_TWO = "tenant2";
45
+ protected static final String ADMIN_GROUP = "adminGroup";
46
+ protected static final String ADMIN_USER = "adminUser";
47
+
48
+ private ProcessEngineConfigurationImpl processEngineConfiguration;
49
+ private IdentityService identityService;
50
+ private ProcessDefinitionRestService resource;
51
+ private UriInfo uriInfo;
52
+ private final MultivaluedMap<String, String> queryParameters = new MultivaluedHashMap<>();
53
+
54
+ @Before
55
+ public void init() throws Exception {
56
+
57
+ ProcessEngine processEngine = getProcessEngine();
58
+ processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
59
+
60
+ identityService = processEngine.getIdentityService();
61
+
62
+ processEngineConfiguration.getAdminGroups().add(ADMIN_GROUP);
63
+ processEngineConfiguration.getAdminUsers().add(ADMIN_USER);
64
+
65
+ deploy("processes/multi-tenancy-call-activity.bpmn");
66
+ deployForTenant(TENANT_ONE, "processes/user-task-process.bpmn");
67
+ deployForTenant(TENANT_TWO, "processes/user-task-process.bpmn");
68
+
69
+ resource = new ProcessDefinitionRestService(getProcessEngine().getName());
70
+
71
+ uriInfo = Mockito.mock(UriInfo.class);
72
+ Mockito.doReturn(queryParameters).when(uriInfo).getQueryParameters();
73
+ queryParameters.add("sortBy", "tenantId");
74
+ queryParameters.add("sortOrder", "asc");
75
+ }
76
+
77
+ @After
78
+ public void tearDown() {
79
+ processEngineConfiguration.getAdminGroups().remove(ADMIN_GROUP);
80
+ processEngineConfiguration.getAdminUsers().remove(ADMIN_USER);
81
+ queryParameters.clear();
82
+ }
83
+
84
+ @Test
85
+ public void queryStatisticsNoAuthenticatedTenant() {
86
+ // given
87
+ identityService.setAuthentication("user", null, null);
88
+
89
+ // when
90
+ List<ProcessDefinitionStatisticsDto> actual = resource.queryStatistics(uriInfo, null, null);
91
+
92
+ // then
93
+ assertThat(actual).hasSize(1);
94
+ assertThat(actual).extracting("key", "tenantId")
95
+ .containsOnly(tuple("multiTenancyCallActivity", null));
96
+ }
97
+
98
+ @Test
99
+ public void queryStatisticsWithAuthenticatedTenant() {
100
+ // given
101
+ identityService.setAuthentication("user", null, Collections.singletonList(TENANT_ONE));
102
+
103
+ // when
104
+ List<ProcessDefinitionStatisticsDto> actual = resource.queryStatistics(uriInfo, null, null);
105
+
106
+ // then
107
+ assertThat(actual).hasSize(2);
108
+ assertThat(actual).extracting("key", "tenantId")
109
+ .containsOnly(tuple("multiTenancyCallActivity", null),
110
+ tuple("userTaskProcess", TENANT_ONE));
111
+ }
112
+
113
+ @Test
114
+ public void queryStatisticsWithDisabledTenantCheck() {
115
+ // given
116
+ processEngineConfiguration.setTenantCheckEnabled(false);
117
+ identityService.setAuthentication("user", null, null);
118
+
119
+ // when
120
+ List<ProcessDefinitionStatisticsDto> actual = resource.queryStatistics(uriInfo, null, null);
121
+
122
+ // then
123
+ assertThat(actual).hasSize(3);
124
+ assertThat(actual).extracting("key", "tenantId")
125
+ .containsOnly(tuple("multiTenancyCallActivity", null),
126
+ tuple("userTaskProcess", TENANT_ONE),
127
+ tuple("userTaskProcess", TENANT_TWO));
128
+ }
129
+
130
+ @Test
131
+ public void queryStatisticsWithCamundaAdmin() {
132
+ // given
133
+ identityService.setAuthentication("user", Collections.singletonList(Groups.CAMUNDA_ADMIN), null);
134
+
135
+ // when
136
+ List<ProcessDefinitionStatisticsDto> actual = resource.queryStatistics(uriInfo, null, null);
137
+
138
+ // then
139
+ assertThat(actual).hasSize(3);
140
+ assertThat(actual).extracting("key", "tenantId")
141
+ .containsOnly(tuple("multiTenancyCallActivity", null),
142
+ tuple("userTaskProcess", TENANT_ONE),
143
+ tuple("userTaskProcess", TENANT_TWO));
144
+ }
145
+
146
+ @Test
147
+ public void queryStatisticsWithAdminGroups() {
148
+ // given
149
+ identityService.setAuthentication("user", Collections.singletonList(ADMIN_GROUP), null);
150
+
151
+ // when
152
+ List<ProcessDefinitionStatisticsDto> actual = resource.queryStatistics(uriInfo, null, null);
153
+
154
+ // then
155
+ assertThat(actual).hasSize(3);
156
+ assertThat(actual).extracting("key", "tenantId")
157
+ .containsOnly(tuple("multiTenancyCallActivity", null),
158
+ tuple("userTaskProcess", TENANT_ONE),
159
+ tuple("userTaskProcess", TENANT_TWO));
160
+ }
161
+
162
+ @Test
163
+ public void queryStatisticsWithAdminUsers() {
164
+ // given
165
+ identityService.setAuthentication("adminUser", null, null);
166
+
167
+ // when
168
+ List<ProcessDefinitionStatisticsDto> actual = resource.queryStatistics(uriInfo, null, null);
169
+
170
+ // then
171
+ assertThat(actual).hasSize(3);
172
+ assertThat(actual).extracting("key", "tenantId")
173
+ .containsOnly(tuple("multiTenancyCallActivity", null),
174
+ tuple("userTaskProcess", TENANT_ONE),
175
+ tuple("userTaskProcess", TENANT_TWO));
176
+ }
177
+
178
+ @Test
179
+ public void getStatisticsCountNoAuthenticatedTenant() {
180
+ // given
181
+ identityService.setAuthentication("user", null, null);
182
+
183
+ // when
184
+ CountResultDto actual = resource.getStatisticsCount(uriInfo);
185
+
186
+ // then
187
+ assertThat(actual.getCount()).isEqualTo(1);
188
+ }
189
+
190
+ @Test
191
+ public void getStatisticsCountWithAuthenticatedTenant() {
192
+ // given
193
+ identityService.setAuthentication("user", null, Collections.singletonList(TENANT_ONE));
194
+
195
+ // when
196
+ CountResultDto actual = resource.getStatisticsCount(uriInfo);
197
+
198
+ // then
199
+ assertThat(actual.getCount()).isEqualTo(2);
200
+ }
201
+
202
+ @Test
203
+ public void getStatisticsCountWithDisabledTenantCheck() {
204
+ // given
205
+ processEngineConfiguration.setTenantCheckEnabled(false);
206
+ identityService.setAuthentication("user", null, null);
207
+
208
+ // when
209
+ CountResultDto actual = resource.getStatisticsCount(uriInfo);
210
+
211
+ // then
212
+ assertThat(actual.getCount()).isEqualTo(3);
213
+ }
214
+
215
+ @Test
216
+ public void getStatisticsCountWithCamundaAdmin() {
217
+ // given
218
+ identityService.setAuthentication("user", Collections.singletonList(Groups.CAMUNDA_ADMIN), null);
219
+
220
+ // when
221
+ CountResultDto actual = resource.getStatisticsCount(uriInfo);
222
+
223
+ // then
224
+ assertThat(actual.getCount()).isEqualTo(3);
225
+ }
226
+
227
+ @Test
228
+ public void getStatisticsCountWithAdminGroups() {
229
+ // given
230
+ identityService.setAuthentication("user", Collections.singletonList(ADMIN_GROUP), null);
231
+
232
+ // when
233
+ CountResultDto actual = resource.getStatisticsCount(uriInfo);
234
+
235
+ // then
236
+ assertThat(actual.getCount()).isEqualTo(3);
237
+ }
238
+
239
+ @Test
240
+ public void getStatisticsCountWithAdminUsers() {
241
+ // given
242
+ identityService.setAuthentication("adminUser", null, null);
243
+
244
+ // when
245
+ CountResultDto actual = resource.getStatisticsCount(uriInfo);
246
+
247
+ // then
248
+ assertThat(actual.getCount()).isEqualTo(3);
249
+ }
250
+
251
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/tenantcheck/ProcessInstanceResourceTenantCheckTest.java ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.cockpit.plugin.base.tenantcheck;
18
+
19
+ import static org.assertj.core.api.Assertions.assertThat;
20
+ import java.util.Arrays;
21
+ import java.util.Collections;
22
+ import java.util.HashSet;
23
+ import java.util.List;
24
+ import java.util.Set;
25
+
26
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.CalledProcessInstanceDto;
27
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.query.CalledProcessInstanceQueryDto;
28
+ import org.camunda.bpm.cockpit.impl.plugin.base.sub.resources.ProcessInstanceResource;
29
+ import org.camunda.bpm.cockpit.plugin.test.AbstractCockpitPluginTest;
30
+ import org.camunda.bpm.engine.IdentityService;
31
+ import org.camunda.bpm.engine.ProcessEngine;
32
+ import org.camunda.bpm.engine.RuntimeService;
33
+ import org.camunda.bpm.engine.authorization.Groups;
34
+ import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
35
+ import org.camunda.bpm.engine.runtime.ProcessInstance;
36
+ import org.junit.After;
37
+ import org.junit.Before;
38
+ import org.junit.Test;
39
+
40
+ public class ProcessInstanceResourceTenantCheckTest extends AbstractCockpitPluginTest {
41
+
42
+ protected static final String TENANT_ONE = "tenant1";
43
+ protected static final String TENANT_TWO = "tenant2";
44
+ protected static final String ADMIN_GROUP = "adminGroup";
45
+ protected static final String ADMIN_USER = "adminUser";
46
+
47
+ private ProcessInstanceResource resource;
48
+ private ProcessEngine processEngine;
49
+ private ProcessEngineConfigurationImpl processEngineConfiguration;
50
+ private RuntimeService runtimeService;
51
+ private IdentityService identityService;
52
+ private CalledProcessInstanceQueryDto queryParameter;
53
+
54
+ @Before
55
+ public void init() throws Exception {
56
+
57
+ processEngine = getProcessEngine();
58
+ processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
59
+ runtimeService = processEngine.getRuntimeService();
60
+ identityService = processEngine.getIdentityService();
61
+
62
+ processEngineConfiguration.getAdminGroups().add(ADMIN_GROUP);
63
+ processEngineConfiguration.getAdminUsers().add(ADMIN_USER);
64
+
65
+ deploy("processes/multi-tenancy-call-activity.bpmn");
66
+ deployForTenant(TENANT_ONE, "processes/user-task-process.bpmn");
67
+ deployForTenant(TENANT_TWO, "processes/user-task-process.bpmn");
68
+
69
+ ProcessInstance processInstance = runtimeService.createProcessInstanceByKey("multiTenancyCallActivity").execute();
70
+
71
+ resource = new ProcessInstanceResource(getProcessEngine().getName(), processInstance.getId());
72
+
73
+ queryParameter = new CalledProcessInstanceQueryDto();
74
+ }
75
+
76
+ @After
77
+ public void tearDown() {
78
+ processEngineConfiguration.getAdminGroups().remove(ADMIN_GROUP);
79
+ processEngineConfiguration.getAdminUsers().remove(ADMIN_USER);
80
+ }
81
+
82
+ @Test
83
+ public void getCalledProcessInstancesByParentProcessInstanceIdNoAuthenticatedTenants() {
84
+
85
+ identityService.setAuthentication("user", null, null);
86
+
87
+ List<CalledProcessInstanceDto> result = resource.queryCalledProcessInstances(queryParameter);
88
+ assertThat(result).isEmpty();
89
+ }
90
+
91
+ @Test
92
+ public void getCalledProcessInstancesByParentProcessInstanceIdWithAuthenticatedTenant() {
93
+
94
+ identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE));
95
+
96
+ List<CalledProcessInstanceDto> result = resource.queryCalledProcessInstances(queryParameter);
97
+ assertThat(result).isNotEmpty();
98
+ assertThat(result).hasSize(1);
99
+
100
+ CalledProcessInstanceDto dto = result.get(0);
101
+ assertThat(dto.getCallActivityId()).isEqualTo("CallActivity_Tenant1");
102
+ }
103
+
104
+ @Test
105
+ public void getCalledProcessInstancesByParentProcessInstanceIdDisabledTenantCheck() {
106
+
107
+ processEngineConfiguration.setTenantCheckEnabled(false);
108
+ identityService.setAuthentication("user", null, null);
109
+
110
+ List<CalledProcessInstanceDto> result = resource.queryCalledProcessInstances(queryParameter);
111
+ assertThat(result).isNotEmpty();
112
+ assertThat(result).hasSize(2);
113
+
114
+ assertThat(getCalledActivityIds(result)).contains("CallActivity_Tenant1", "CallActivity_Tenant2");
115
+ }
116
+
117
+ @Test
118
+ public void getCalledProcessInstancesByParentProcessInstanceIdWithCamundaAdmin() {
119
+
120
+ identityService.setAuthentication("user", Collections.singletonList(Groups.CAMUNDA_ADMIN), null);
121
+
122
+ List<CalledProcessInstanceDto> result = resource.queryCalledProcessInstances(queryParameter);
123
+ assertThat(result).isNotEmpty();
124
+ assertThat(result).hasSize(2);
125
+
126
+ assertThat(getCalledActivityIds(result)).contains("CallActivity_Tenant1", "CallActivity_Tenant2");
127
+ }
128
+
129
+ @Test
130
+ public void getCalledProcessInstancesByParentProcessInstanceIdWithAdminGroups() {
131
+
132
+ identityService.setAuthentication("user", Collections.singletonList(ADMIN_GROUP), null);
133
+
134
+ List<CalledProcessInstanceDto> result = resource.queryCalledProcessInstances(queryParameter);
135
+ assertThat(result).isNotEmpty();
136
+ assertThat(result).hasSize(2);
137
+
138
+ assertThat(getCalledActivityIds(result)).contains("CallActivity_Tenant1", "CallActivity_Tenant2");
139
+ }
140
+
141
+ @Test
142
+ public void getCalledProcessInstancesByParentProcessInstanceIdWithAdminUsers() {
143
+
144
+ identityService.setAuthentication("adminUser", null, null);
145
+
146
+ List<CalledProcessInstanceDto> result = resource.queryCalledProcessInstances(queryParameter);
147
+ assertThat(result).isNotEmpty();
148
+ assertThat(result).hasSize(2);
149
+
150
+ assertThat(getCalledActivityIds(result)).contains("CallActivity_Tenant1", "CallActivity_Tenant2");
151
+ }
152
+
153
+ private Set<String> getCalledActivityIds(List<CalledProcessInstanceDto> result) {
154
+ Set<String> callActivityIds = new HashSet<>();
155
+ for (CalledProcessInstanceDto calledProcessInstanceDto : result) {
156
+ callActivityIds.add(calledProcessInstanceDto.getCallActivityId());
157
+ }
158
+ return callActivityIds;
159
+ }
160
+
161
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/cockpit/plugin/base/tenantcheck/ProcessInstanceRestServiceTenantCheckTest.java ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.cockpit.plugin.base.tenantcheck;
18
+
19
+ import static org.assertj.core.api.Assertions.assertThat;
20
+
21
+ import java.util.Arrays;
22
+ import java.util.Collections;
23
+ import java.util.List;
24
+
25
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.IncidentStatisticsDto;
26
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.ProcessInstanceDto;
27
+ import org.camunda.bpm.cockpit.impl.plugin.base.dto.query.ProcessInstanceQueryDto;
28
+ import org.camunda.bpm.cockpit.impl.plugin.resources.ProcessInstanceRestService;
29
+ import org.camunda.bpm.cockpit.plugin.test.AbstractCockpitPluginTest;
30
+ import org.camunda.bpm.engine.IdentityService;
31
+ import org.camunda.bpm.engine.ProcessEngine;
32
+ import org.camunda.bpm.engine.RuntimeService;
33
+ import org.camunda.bpm.engine.authorization.Groups;
34
+ import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
35
+ import org.camunda.bpm.engine.rest.dto.CountResultDto;
36
+ import org.junit.After;
37
+ import org.junit.Before;
38
+ import org.junit.Test;
39
+
40
+ public class ProcessInstanceRestServiceTenantCheckTest extends AbstractCockpitPluginTest {
41
+
42
+ protected static final String TENANT_ONE = "tenant1";
43
+ protected static final String TENANT_TWO = "tenant2";
44
+ protected static final String ADMIN_GROUP = "adminGroup";
45
+ protected static final String ADMIN_USER = "adminUser";
46
+
47
+ private ProcessEngine processEngine;
48
+ private ProcessEngineConfigurationImpl processEngineConfiguration;
49
+ private RuntimeService runtimeService;
50
+ private IdentityService identityService;
51
+
52
+ private ProcessInstanceRestService resource;
53
+ private ProcessInstanceQueryDto queryParameter;
54
+
55
+ @Before
56
+ public void init() throws Exception {
57
+
58
+ processEngine = getProcessEngine();
59
+ processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
60
+
61
+ runtimeService = processEngine.getRuntimeService();
62
+ identityService = processEngine.getIdentityService();
63
+
64
+ processEngineConfiguration.getAdminGroups().add(ADMIN_GROUP);
65
+ processEngineConfiguration.getAdminUsers().add(ADMIN_USER);
66
+
67
+ resource = new ProcessInstanceRestService(processEngine.getName());
68
+
69
+ deployForTenant(TENANT_ONE, "processes/failing-process.bpmn");
70
+ deployForTenant(TENANT_TWO, "processes/failing-process.bpmn");
71
+
72
+ startProcessInstancesWithTenantId("FailingProcess", TENANT_ONE);
73
+ startProcessInstancesWithTenantId("FailingProcess", TENANT_TWO);
74
+
75
+ queryParameter = new ProcessInstanceQueryDto();
76
+ queryParameter.setActivityIdIn(new String[] { "ServiceTask_1" });
77
+ }
78
+
79
+ @After
80
+ public void tearDown() {
81
+ processEngineConfiguration.getAdminGroups().remove(ADMIN_GROUP);
82
+ processEngineConfiguration.getAdminUsers().remove(ADMIN_USER);
83
+ }
84
+
85
+ @Test
86
+ public void queryCountNoAuthenticatedTenants() {
87
+
88
+ identityService.setAuthentication("user", null, null);
89
+
90
+ CountResultDto result = resource.queryProcessInstancesCount(queryParameter);
91
+ assertThat(result).isNotNull();
92
+ assertThat(result.getCount()).isEqualTo(0);
93
+ }
94
+
95
+ @Test
96
+ public void queryCountWithAuthenticatedTenant() {
97
+
98
+ identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE));
99
+
100
+ CountResultDto result = resource.queryProcessInstancesCount(queryParameter);
101
+ assertThat(result).isNotNull();
102
+ assertThat(result.getCount()).isEqualTo(1);
103
+ }
104
+
105
+ @Test
106
+ public void queryCountDisabledTenantCheck() {
107
+
108
+ processEngineConfiguration.setTenantCheckEnabled(false);
109
+ identityService.setAuthentication("user", null, null);
110
+
111
+ CountResultDto result = resource.queryProcessInstancesCount(queryParameter);
112
+ assertThat(result).isNotNull();
113
+ assertThat(result.getCount()).isEqualTo(2);
114
+ }
115
+
116
+ @Test
117
+ public void queryCountWithCamundaAdmin() {
118
+
119
+ identityService.setAuthentication("user", Collections.singletonList(Groups.CAMUNDA_ADMIN), null);
120
+
121
+ CountResultDto result = resource.queryProcessInstancesCount(queryParameter);
122
+ assertThat(result).isNotNull();
123
+ assertThat(result.getCount()).isEqualTo(2);
124
+ }
125
+
126
+ @Test
127
+ public void queryWithContainingIncidentsNoAuthenticatedTenants() {
128
+
129
+ identityService.setAuthentication("user", null, null);
130
+
131
+ List<ProcessInstanceDto> result = resource.queryProcessInstances(queryParameter, null, null);
132
+ assertThat(result).isEmpty();
133
+ }
134
+
135
+ @Test
136
+ public void queryWithContainingIncidentsWithAuthenticatedTenant() {
137
+
138
+ identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE));
139
+
140
+ List<ProcessInstanceDto> result = resource.queryProcessInstances(queryParameter, null, null);
141
+ assertThat(result).isNotEmpty();
142
+ assertThat(result).hasSize(1);
143
+
144
+ List<IncidentStatisticsDto> incidents = result.get(0).getIncidents();
145
+ assertThat(incidents).isNotEmpty();
146
+ assertThat(incidents).hasSize(1);
147
+ }
148
+
149
+ @Test
150
+ public void queryWithContainingIncidentsDisabledTenantCheck() {
151
+
152
+ processEngineConfiguration.setTenantCheckEnabled(false);
153
+ identityService.setAuthentication("user", null, null);
154
+
155
+ List<ProcessInstanceDto> result = resource.queryProcessInstances(queryParameter, null, null);
156
+ assertThat(result).isNotEmpty();
157
+ assertThat(result).hasSize(2);
158
+
159
+ List<IncidentStatisticsDto> incidents = result.get(0).getIncidents();
160
+ assertThat(incidents).isNotEmpty();
161
+ assertThat(incidents).hasSize(1);
162
+
163
+ incidents = result.get(1).getIncidents();
164
+ assertThat(incidents).isNotEmpty();
165
+ assertThat(incidents).hasSize(1);
166
+ }
167
+
168
+ @Test
169
+ public void queryWithContainingIncidentsWithCamundaAdmin() {
170
+
171
+ identityService.setAuthentication("user", Collections.singletonList(Groups.CAMUNDA_ADMIN), null);
172
+
173
+ List<ProcessInstanceDto> result = resource.queryProcessInstances(queryParameter, null, null);
174
+ assertThat(result).isNotEmpty();
175
+ assertThat(result).hasSize(2);
176
+
177
+ List<IncidentStatisticsDto> incidents = result.get(0).getIncidents();
178
+ assertThat(incidents).isNotEmpty();
179
+ assertThat(incidents).hasSize(1);
180
+
181
+ incidents = result.get(1).getIncidents();
182
+ assertThat(incidents).isNotEmpty();
183
+ assertThat(incidents).hasSize(1);
184
+ }
185
+
186
+ @Test
187
+ public void queryWithContainingIncidentsWithAdminGroups() {
188
+
189
+ identityService.setAuthentication("user", Collections.singletonList(ADMIN_GROUP), null);
190
+
191
+ List<ProcessInstanceDto> result = resource.queryProcessInstances(queryParameter, null, null);
192
+ assertThat(result).isNotEmpty();
193
+ assertThat(result).hasSize(2);
194
+
195
+ List<IncidentStatisticsDto> incidents = result.get(0).getIncidents();
196
+ assertThat(incidents).isNotEmpty();
197
+ assertThat(incidents).hasSize(1);
198
+
199
+ incidents = result.get(1).getIncidents();
200
+ assertThat(incidents).isNotEmpty();
201
+ assertThat(incidents).hasSize(1);
202
+ }
203
+
204
+ @Test
205
+ public void queryWithContainingIncidentsWithAdminUsers() {
206
+
207
+ identityService.setAuthentication("adminUser", null, null);
208
+
209
+ List<ProcessInstanceDto> result = resource.queryProcessInstances(queryParameter, null, null);
210
+ assertThat(result).isNotEmpty();
211
+ assertThat(result).hasSize(2);
212
+
213
+ List<IncidentStatisticsDto> incidents = result.get(0).getIncidents();
214
+ assertThat(incidents).isNotEmpty();
215
+ assertThat(incidents).hasSize(1);
216
+
217
+ incidents = result.get(1).getIncidents();
218
+ assertThat(incidents).isNotEmpty();
219
+ assertThat(incidents).hasSize(1);
220
+ }
221
+
222
+ private void startProcessInstancesWithTenantId(String processDefinitionKey, String tenantId) {
223
+
224
+ runtimeService
225
+ .createProcessInstanceByKey(processDefinitionKey)
226
+ .processDefinitionTenantId(tenantId)
227
+ .execute();
228
+
229
+ executeAvailableJobs();
230
+ }
231
+
232
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/db/QuerySessionFactoryTest.java ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.webapp.impl.db;
18
+
19
+ import static org.assertj.core.api.Assertions.assertThat;
20
+
21
+ import java.util.Collections;
22
+ import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
23
+ import org.camunda.bpm.engine.test.ProcessEngineRule;
24
+ import org.junit.Before;
25
+ import org.junit.Rule;
26
+ import org.junit.Test;
27
+
28
+ public class QuerySessionFactoryTest {
29
+
30
+ @Rule
31
+ public ProcessEngineRule processEngineRule = new ProcessEngineRule("camunda-skip-check.cfg.xml");
32
+
33
+ private ProcessEngineConfigurationImpl processEngineConfiguration;
34
+
35
+ @Before
36
+ public void setUp() throws Exception {
37
+ processEngineConfiguration = processEngineRule.getProcessEngineConfiguration();
38
+ }
39
+
40
+ @Test
41
+ public void testQuerySessionFactoryInitializationFromEngineConfig() {
42
+ // given
43
+ QuerySessionFactory querySessionFactory = new QuerySessionFactory();
44
+ processEngineConfiguration = processEngineRule.getProcessEngineConfiguration();
45
+
46
+ // when
47
+ querySessionFactory.initFromProcessEngineConfiguration(processEngineConfiguration, Collections.emptyList());
48
+
49
+ // then
50
+ assertThat(querySessionFactory.getWrappedConfiguration()).isEqualTo(processEngineConfiguration);
51
+ assertThat(querySessionFactory.getDatabaseType()).isEqualTo(processEngineConfiguration.getDatabaseType());
52
+ assertThat(querySessionFactory.getDataSource()).isEqualTo(processEngineConfiguration.getDataSource());
53
+ assertThat(querySessionFactory.getDatabaseTablePrefix()).isEqualTo(processEngineConfiguration.getDatabaseTablePrefix());
54
+ assertThat(querySessionFactory.getSkipIsolationLevelCheck()).isTrue();
55
+ assertThat(querySessionFactory.getHistoryLevel()).isEqualTo(processEngineConfiguration.getHistoryLevel());
56
+ assertThat(querySessionFactory.getHistory()).isEqualTo(processEngineConfiguration.getHistory());
57
+
58
+ }
59
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/engine/EnginesFilterTest.java ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.webapp.impl.engine;
18
+
19
+ import static org.assertj.core.api.Assertions.assertThat;
20
+ import static org.junit.Assert.fail;
21
+
22
+ import java.util.Collections;
23
+ import java.util.Set;
24
+ import java.util.regex.Matcher;
25
+ import java.util.regex.Pattern;
26
+
27
+ import org.camunda.bpm.cockpit.Cockpit;
28
+ import org.camunda.bpm.cockpit.impl.DefaultCockpitRuntimeDelegate;
29
+ import org.camunda.bpm.engine.ProcessEngine;
30
+ import org.camunda.bpm.engine.rest.spi.ProcessEngineProvider;
31
+ import org.camunda.bpm.webapp.impl.IllegalWebAppConfigurationException;
32
+ import org.junit.After;
33
+ import org.junit.Test;
34
+
35
+ /**
36
+ *
37
+ * @author nico.rehwaldt
38
+ */
39
+ public class EnginesFilterTest {
40
+
41
+ @Test
42
+ public void testHTML_FILE_PATTERN() throws Exception {
43
+
44
+ // given
45
+ Pattern pattern = ProcessEnginesFilter.APP_PREFIX_PATTERN;
46
+
47
+ // when
48
+ Matcher matcher1 = pattern.matcher("/app/cockpit/");
49
+ Matcher matcher2 = pattern.matcher("/app/cockpit/engine1/");
50
+ Matcher matcher3 = pattern.matcher("/app/cockpit/engine1/something/asd.html");
51
+ Matcher matcher4 = pattern.matcher("/app/admin/engine1/something/asd.html");
52
+ Matcher matcher5 = pattern.matcher("/app/cockpit/index.html");
53
+ Matcher matcher6 = pattern.matcher("/app/tasklist/spring-engine/");
54
+
55
+ // then
56
+ assertThat(matcher1.matches()).isTrue();
57
+ assertThat(matcher1.group(1)).isEqualTo("cockpit");
58
+ assertThat(matcher1.groupCount()).isEqualTo(3);
59
+ assertThat(matcher1.group(2)).isNull();
60
+
61
+ assertThat(matcher2.matches()).isTrue();
62
+ assertThat(matcher2.group(1)).isEqualTo("cockpit");
63
+ assertThat(matcher2.group(2)).isEqualTo("engine1");
64
+ assertThat(matcher2.group(3)).isEmpty();
65
+
66
+ assertThat(matcher3.matches()).isTrue();
67
+ assertThat(matcher3.group(1)).isEqualTo("cockpit");
68
+ assertThat(matcher3.group(2)).isEqualTo("engine1");
69
+ assertThat(matcher3.group(3)).isEqualTo("something/asd.html");
70
+
71
+ assertThat(matcher4.matches()).isTrue();
72
+ assertThat(matcher4.group(1)).isEqualTo("admin");
73
+ assertThat(matcher4.group(2)).isEqualTo("engine1");
74
+ assertThat(matcher4.group(3)).isEqualTo("something/asd.html");
75
+
76
+ assertThat(matcher5.matches()).isTrue();
77
+ assertThat(matcher5.group(1)).isEqualTo("cockpit");
78
+ assertThat(matcher5.group(2)).isEqualTo("index.html");
79
+ assertThat(matcher5.group(3)).isEmpty();
80
+
81
+ assertThat(matcher6.matches()).isTrue();
82
+ assertThat(matcher6.group(1)).isEqualTo("tasklist");
83
+ assertThat(matcher6.group(2)).isEqualTo("spring-engine");
84
+ assertThat(matcher6.group(3)).isEmpty();
85
+ }
86
+
87
+ @Test
88
+ public void testGetDefaultProcessEngine() {
89
+
90
+ // see https://app.camunda.com/jira/browse/CAM-2126
91
+
92
+ // runtime delegate returns single, non-default-named process engine engine
93
+
94
+ Cockpit.setCockpitRuntimeDelegate(new DefaultCockpitRuntimeDelegate() {
95
+
96
+ protected ProcessEngineProvider loadProcessEngineProvider() {
97
+ return null;
98
+ }
99
+
100
+ public Set<String> getProcessEngineNames() {
101
+ return Collections.singleton("foo");
102
+ }
103
+ public ProcessEngine getDefaultProcessEngine() {
104
+ return null;
105
+ }
106
+ });
107
+
108
+ ProcessEnginesFilter processEnginesFilter = new ProcessEnginesFilter();
109
+ String defaultEngineName = processEnginesFilter.getDefaultEngineName();
110
+ assertThat(defaultEngineName).isEqualTo("foo");
111
+
112
+
113
+ // now it returns 'null'
114
+
115
+ Cockpit.setCockpitRuntimeDelegate(new DefaultCockpitRuntimeDelegate() {
116
+
117
+ protected ProcessEngineProvider loadProcessEngineProvider() {
118
+ return null;
119
+ }
120
+
121
+ public Set<String> getProcessEngineNames() {
122
+ return Collections.emptySet();
123
+ }
124
+ public ProcessEngine getDefaultProcessEngine() {
125
+ return null;
126
+ }
127
+ });
128
+
129
+ try {
130
+ defaultEngineName = processEnginesFilter.getDefaultEngineName();
131
+ fail();
132
+ } catch(IllegalWebAppConfigurationException e) {
133
+ // expected
134
+ }
135
+
136
+ }
137
+
138
+ @After
139
+ public void cleanup() {
140
+ Cockpit.setCockpitRuntimeDelegate(null);
141
+ }
142
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/engine/WebappsDatabaseNamingConsistencyTest.java ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.webapp.impl.engine;
18
+
19
+ import static org.assertj.core.api.Assertions.fail;
20
+
21
+ import java.io.File;
22
+ import java.io.IOException;
23
+ import java.net.URL;
24
+ import java.nio.file.Files;
25
+ import java.util.concurrent.atomic.AtomicInteger;
26
+ import java.util.regex.Matcher;
27
+ import java.util.regex.Pattern;
28
+ import java.util.stream.Stream;
29
+ import org.junit.Test;
30
+
31
+ public class WebappsDatabaseNamingConsistencyTest {
32
+
33
+ public static String COLUMN_NAME_REGEX = "([a-zA-Z_]*(?=[a-z]+)[a-zA-Z_]+_)[,\\s]";
34
+ public static String[] SCANNED_FOLDERS = { "org/camunda/bpm/cockpit/plugin/base/queries",
35
+ "org/camunda/bpm/admin/plugin/base/queries" };
36
+
37
+ @Test
38
+ public void shouldNotFindLowercaseDbColumnNamesInMappings() {
39
+ // given the rule that all DB column names are created in uppercase
40
+
41
+ // when scanning all mapping files for lowercase column names
42
+ StringBuilder errorMessageBuilder = new StringBuilder();
43
+ Pattern pattern = Pattern.compile(COLUMN_NAME_REGEX);
44
+ try {
45
+ for (String scannedFolder : SCANNED_FOLDERS) {
46
+ URL resource = getClass().getClassLoader().getResource(scannedFolder);
47
+ if (resource == null) {
48
+ throw new IOException("Could not find path: " + scannedFolder);
49
+ }
50
+ File folder = new File(resource.getFile());
51
+ File[] filesInFolder = folder.listFiles();
52
+ for (File file : filesInFolder) {
53
+ AtomicInteger lineNumber = new AtomicInteger(0);
54
+ try (Stream<String> lines = Files.lines(file.toPath())) {
55
+ lines.forEach(line -> {
56
+ lineNumber.getAndIncrement();
57
+ Matcher matcher = pattern.matcher(line);
58
+ while (matcher.find()) {
59
+ errorMessageBuilder.append(
60
+ "Found illegal lowercase column name " + matcher.group(1) + " in SQL " + file + " at line "
61
+ + lineNumber + ". All SQL column names should be uppercase.\n");
62
+ }
63
+ });
64
+ }
65
+ }
66
+ }
67
+ } catch (IOException e) {
68
+ fail("Unable to find test resource for test " + getClass().getName() + "\n" + e.getMessage());
69
+ }
70
+ // then don't expect any results
71
+ String errorMessage = errorMessageBuilder.toString();
72
+ if (!errorMessage.isEmpty()) {
73
+ fail(errorMessage);
74
+ }
75
+ }
76
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/auth/AuthCacheTest.java ADDED
@@ -0,0 +1,540 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.webapp.impl.security.auth;
18
+
19
+ import org.camunda.bpm.engine.ProcessEngine;
20
+ import org.camunda.bpm.engine.identity.User;
21
+ import org.camunda.bpm.engine.impl.util.ClockUtil;
22
+ import org.camunda.bpm.webapp.impl.IllegalWebAppConfigurationException;
23
+ import org.camunda.bpm.webapp.impl.security.SecurityActions;
24
+ import org.camunda.bpm.webapp.impl.util.ProcessEngineUtil;
25
+ import org.camunda.bpm.webapp.impl.util.ServletContextUtil;
26
+ import org.junit.After;
27
+ import org.junit.Before;
28
+ import org.junit.Test;
29
+ import org.mockito.MockedStatic;
30
+ import org.springframework.mock.web.MockFilterChain;
31
+ import org.springframework.mock.web.MockFilterConfig;
32
+ import org.springframework.mock.web.MockHttpServletRequest;
33
+ import org.springframework.mock.web.MockHttpServletResponse;
34
+
35
+ import javax.servlet.ServletException;
36
+ import javax.servlet.http.HttpSession;
37
+ import java.io.IOException;
38
+ import java.util.ArrayList;
39
+ import java.util.Arrays;
40
+ import java.util.Date;
41
+ import java.util.List;
42
+
43
+ import static org.assertj.core.api.Assertions.assertThat;
44
+ import static org.assertj.core.api.Assertions.assertThatThrownBy;
45
+ import static org.camunda.bpm.engine.rest.util.DateTimeUtils.addDays;
46
+ import static org.mockito.ArgumentMatchers.anyLong;
47
+ import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
48
+ import static org.mockito.Mockito.any;
49
+ import static org.mockito.Mockito.eq;
50
+ import static org.mockito.Mockito.mock;
51
+ import static org.mockito.Mockito.mockStatic;
52
+ import static org.mockito.Mockito.when;
53
+
54
+ public class AuthCacheTest {
55
+
56
+ protected MockedStatic<AuthenticationUtil> mockedAuthenticationUtil;
57
+
58
+ protected MockedStatic<SecurityActions> mockedSecurityActions;
59
+
60
+ protected MockedStatic<ProcessEngineUtil> mockedProcessEngineUtil;
61
+
62
+ @Before
63
+ public void setup() {
64
+ ClockUtil.setCurrentTime(ClockUtil.getCurrentTime());
65
+ }
66
+
67
+ @After
68
+ public void reset() {
69
+ Authentications.clearCurrent();
70
+ ClockUtil.reset();
71
+ if (mockedAuthenticationUtil != null) {
72
+ mockedAuthenticationUtil.close();
73
+ }
74
+ if (mockedSecurityActions != null) {
75
+ mockedSecurityActions.close();
76
+ }
77
+ if (mockedProcessEngineUtil != null) {
78
+ mockedProcessEngineUtil.close();
79
+ }
80
+ }
81
+
82
+ @Test
83
+ public void shouldThrowExceptionWhenTimeToLiveIsNegative() {
84
+ AuthenticationFilter authenticationFilter = new AuthenticationFilter();
85
+ MockFilterConfig config = new MockFilterConfig();
86
+ config.addInitParameter(AuthenticationFilter.AUTH_CACHE_TTL_INIT_PARAM_NAME, "-1000");
87
+ assertThatThrownBy(() -> authenticationFilter.init(config))
88
+ .isInstanceOf(IllegalWebAppConfigurationException.class)
89
+ .hasMessage("'cacheTimeToLive' cannot be negative.");
90
+ }
91
+
92
+ @Test
93
+ public void shouldThrowExceptionSinceTimeToLiveIsNotALong() {
94
+ AuthenticationFilter authenticationFilter = new AuthenticationFilter();
95
+ MockFilterConfig config = new MockFilterConfig();
96
+ config.addInitParameter(AuthenticationFilter.AUTH_CACHE_TTL_INIT_PARAM_NAME, "6.7");
97
+ assertThatThrownBy(() -> authenticationFilter.init(config))
98
+ .isInstanceOf(NumberFormatException.class)
99
+ .hasMessage("For input string: \"6.7\"");
100
+ }
101
+
102
+ @Test
103
+ public void shouldTrimTimeToLive() throws ServletException {
104
+ AuthenticationFilter authenticationFilter = new AuthenticationFilter();
105
+ MockFilterConfig config = new MockFilterConfig();
106
+ config.addInitParameter(AuthenticationFilter.AUTH_CACHE_TTL_INIT_PARAM_NAME, " 123 ");
107
+ authenticationFilter.init(config);
108
+ assertThat(authenticationFilter.getCacheTimeToLive()).isEqualTo(123);
109
+ }
110
+
111
+ @Test
112
+ public void shouldRevalidateWhenValidationTimeDue() throws ServletException, IOException {
113
+ // given
114
+ setupEngineMock();
115
+ AuthenticationFilter filter = setupFilter(1000 * 60 * 5);
116
+ Authentications authentications = setupAuth();
117
+ UserAuthentication initialAuthentication = getAuthByEngine(authentications, "engine1");
118
+
119
+ // assume
120
+ assertThat(initialAuthentication.getCacheValidationTime()).isNull();
121
+
122
+ applyFilter(filter, new MockHttpServletRequest());
123
+
124
+ UserAuthentication nextAuth = getAuthByEngine(authentications, "engine1");
125
+ assertThat(nextAuth.getCacheValidationTime())
126
+ .isEqualTo(addMinutes(5, ClockUtil.getCurrentTime()));
127
+
128
+ assertThat(initialAuthentication).isNotSameAs(nextAuth);
129
+
130
+ Date currentTime = addDays(ClockUtil.getCurrentTime(), 2);
131
+ ClockUtil.setCurrentTime(currentTime);
132
+
133
+ // when
134
+ applyFilter(filter, new MockHttpServletRequest());
135
+
136
+ // then
137
+ assertThat(getAuthByEngine(authentications, "engine1").getCacheValidationTime())
138
+ .isEqualTo(addMinutes(5, ClockUtil.getCurrentTime()));
139
+ assertThat(initialAuthentication).isNotSameAs(getAuthByEngine(authentications, "engine1"));
140
+ }
141
+
142
+ @Test
143
+ public void shouldRevalidateWhenTTLZero() throws ServletException, IOException {
144
+ // given
145
+ setupEngineMock();
146
+ AuthenticationFilter filter = setupFilter(0);
147
+ Authentications authentications = setupAuth();
148
+ UserAuthentication initialAuthentication = getAuthByEngine(authentications, "engine1");
149
+
150
+ // assume
151
+ assertThat(initialAuthentication.getCacheValidationTime()).isNull();
152
+
153
+ applyFilter(filter, new MockHttpServletRequest());
154
+
155
+ UserAuthentication nextAuth = getAuthByEngine(authentications, "engine1");
156
+ assertThat(nextAuth.getCacheValidationTime()).isNull();
157
+
158
+ assertThat(initialAuthentication).isNotSameAs(nextAuth);
159
+
160
+ Date currentTime = addDays(ClockUtil.getCurrentTime(), 2);
161
+ ClockUtil.setCurrentTime(currentTime);
162
+
163
+ // when
164
+ applyFilter(filter, new MockHttpServletRequest());
165
+
166
+ // then
167
+ assertThat(getAuthByEngine(authentications, "engine1").getCacheValidationTime()).isNull();
168
+ assertThat(initialAuthentication).isNotSameAs(getAuthByEngine(authentications, "engine1"));
169
+ }
170
+
171
+ @Test
172
+ public void shouldNotRevalidateWhenValidationTimeNotDue() throws ServletException, IOException {
173
+ // given
174
+ setupEngineMock();
175
+ AuthenticationFilter filter = setupFilter(1000 * 60 * 5);
176
+ Authentications authentications = setupAuth();
177
+ UserAuthentication initialAuthentication = getAuthByEngine(authentications, "engine1");
178
+
179
+ MockHttpServletRequest request = new MockHttpServletRequest();
180
+
181
+ // assume
182
+ assertThat(initialAuthentication.getCacheValidationTime()).isNull();
183
+
184
+ applyFilter(filter, request);
185
+
186
+ Date datePlus5Minutes = addMinutes(5, ClockUtil.getCurrentTime());
187
+
188
+ UserAuthentication nextAuth = getAuthByEngine(authentications, "engine1");
189
+ assertThat(nextAuth.getCacheValidationTime()).isEqualTo(datePlus5Minutes);
190
+ assertThat(initialAuthentication).isNotSameAs(nextAuth);
191
+
192
+ // when
193
+ applyFilter(filter, request);
194
+
195
+ // then
196
+ assertThat(getAuthByEngine(authentications, "engine1").getCacheValidationTime())
197
+ .isEqualTo(datePlus5Minutes);
198
+ assertThat(nextAuth).isSameAs(getAuthByEngine(authentications, "engine1"));
199
+ }
200
+
201
+ @Test
202
+ public void shouldNotRevalidateWhenDisabled() throws ServletException, IOException {
203
+ setupEngineMock();
204
+ Authentications authentications = setupAuth();
205
+ UserAuthentication initialAuthentication = getAuthByEngine(authentications, "engine1");
206
+
207
+ MockHttpServletRequest request = new MockHttpServletRequest();
208
+
209
+ // assume
210
+ assertThat(initialAuthentication.getCacheValidationTime()).isNull();
211
+
212
+ // when
213
+ applyFilter(setupFilter(new MockFilterConfig()), request);
214
+
215
+ // then
216
+ assertThat(initialAuthentication.getCacheValidationTime()).isNull();
217
+ assertThat(initialAuthentication).isSameAs(getAuthByEngine(authentications, "engine1"));
218
+ }
219
+
220
+ @Test
221
+ public void shouldSetValidationTimeInitially() throws ServletException, IOException {
222
+ // given
223
+ setupEngineMock();
224
+ Authentications authentications = setupAuth();
225
+ UserAuthentication initialAuthentication = getAuthByEngine(authentications, "engine1");
226
+
227
+ MockHttpServletRequest request = new MockHttpServletRequest();
228
+
229
+ // assume
230
+ assertThat(initialAuthentication.getCacheValidationTime()).isNull();
231
+
232
+ // when
233
+ applyFilter(setupFilter(1000 * 60 * 5), request);
234
+
235
+ // then
236
+ UserAuthentication nextAuth = getAuthByEngine(authentications, "engine1");
237
+ assertThat(nextAuth.getCacheValidationTime())
238
+ .isEqualTo(addMinutes(5, ClockUtil.getCurrentTime()));
239
+ assertThat(initialAuthentication).isNotSameAs(nextAuth);
240
+ }
241
+
242
+ @Test
243
+ public void shouldHaveValidationTimeInitially() throws ServletException, IOException {
244
+ // given
245
+ setupEngineMock();
246
+ Authentications authentications = setupAuth();
247
+ UserAuthentication initialAuthentication = getAuthByEngine(authentications, "engine1");
248
+
249
+ MockHttpServletRequest request = new MockHttpServletRequest();
250
+
251
+ // assume
252
+ assertThat(ServletContextUtil.getAuthCacheValidationTime(request.getServletContext())).isNull();
253
+
254
+ // when
255
+ applyFilter(setupFilter(1000 * 60 * 5), request);
256
+
257
+ // then
258
+ assertThat(ServletContextUtil.getAuthCacheValidationTime(request.getServletContext())).isNotNull();
259
+ UserAuthentication nextAuth = getAuthByEngine(authentications, "engine1");
260
+ assertThat(nextAuth.getCacheValidationTime())
261
+ .isEqualTo(addMinutes(5, ClockUtil.getCurrentTime()));
262
+ assertThat(initialAuthentication).isNotSameAs(nextAuth);
263
+ }
264
+
265
+ @Test
266
+ public void shouldInvalidateSessionDueToDeletedUser() throws ServletException, IOException {
267
+ // given
268
+ ProcessEngine engineMock = setupEngineMock()[0];
269
+ Authentications authentications = setupAuth();
270
+ UserAuthentication initialAuthentication = getAuthByEngine(authentications, "engine1");
271
+ AuthenticationFilter filter = setupFilter(1000 * 60 * 5);
272
+
273
+ MockHttpServletRequest request = new MockHttpServletRequest();
274
+
275
+ // assume
276
+ assertThat(initialAuthentication.getCacheValidationTime()).isNull();
277
+
278
+ applyFilter(filter, request);
279
+
280
+ UserAuthentication nextAuth = getAuthByEngine(authentications, "engine1");
281
+ assertThat(nextAuth.getCacheValidationTime()).isEqualTo(addMinutes(5, ClockUtil.getCurrentTime()));
282
+ assertThat(initialAuthentication).isNotSameAs(nextAuth);
283
+
284
+ User user = engineMock.getIdentityService()
285
+ .createUserQuery()
286
+ .userId("userId1")
287
+ .singleResult();
288
+
289
+ when(user).thenReturn(null);
290
+
291
+ Date currentTime = addDays(ClockUtil.getCurrentTime(), 2);
292
+ ClockUtil.setCurrentTime(currentTime);
293
+
294
+ MockHttpServletResponse response = new MockHttpServletResponse();
295
+
296
+ // when
297
+ applyFilter(filter, request, response);
298
+
299
+ // then
300
+ assertThat(getAuthByEngine(authentications, "engine1")).isNull();
301
+ }
302
+
303
+ @Test
304
+ public void shouldRevalidateWhenValidationTimeDueWithMultipleAuths() throws ServletException, IOException {
305
+ // given
306
+ setupEngineMock("engine1", "engine2", "engine3");
307
+ AuthenticationFilter filter = setupFilter(1000 * 60 * 5);
308
+ Authentications authentications = setupAuth("engine1", "engine2", "engine3");
309
+
310
+ UserAuthentication authEngineOne = getAuthByEngine(authentications, "engine1");
311
+ UserAuthentication authEngineTwo = getAuthByEngine(authentications, "engine2");
312
+ UserAuthentication authEngineThree = getAuthByEngine(authentications, "engine3");
313
+
314
+ MockHttpServletRequest request = new MockHttpServletRequest();
315
+
316
+ // assume
317
+ assertThat(authEngineOne.getCacheValidationTime()).isNull();
318
+ assertThat(authEngineTwo.getCacheValidationTime()).isNull();
319
+ assertThat(authEngineThree.getCacheValidationTime()).isNull();
320
+
321
+ applyFilter(filter, request);
322
+
323
+ UserAuthentication nextAuthEngineOne = getAuthByEngine(authentications, "engine1");
324
+ assertThat(authEngineOne).isNotSameAs(nextAuthEngineOne);
325
+ UserAuthentication nextAuthEngineTwo = getAuthByEngine(authentications, "engine2");
326
+ assertThat(authEngineTwo).isNotSameAs(nextAuthEngineTwo);
327
+ UserAuthentication nextAuthEngineThree = getAuthByEngine(authentications, "engine3");
328
+ assertThat(authEngineThree).isNotSameAs(nextAuthEngineThree);
329
+
330
+ Date datePlus5Minutes = addMinutes(5, ClockUtil.getCurrentTime());
331
+ assertThat(nextAuthEngineOne.getCacheValidationTime()).isEqualTo(datePlus5Minutes);
332
+ assertThat(nextAuthEngineTwo.getCacheValidationTime()).isEqualTo(datePlus5Minutes);
333
+ assertThat(nextAuthEngineThree.getCacheValidationTime()).isEqualTo(datePlus5Minutes);
334
+
335
+ Date currentTime = addDays(ClockUtil.getCurrentTime(), 2);
336
+ ClockUtil.setCurrentTime(currentTime);
337
+
338
+ request = new MockHttpServletRequest();
339
+
340
+ // when
341
+ applyFilter(filter, request);
342
+
343
+ // then
344
+ assertThat(authEngineOne)
345
+ .isNotSameAs(nextAuthEngineOne)
346
+ .isNotSameAs(getAuthByEngine(authentications, "engine1"));
347
+ assertThat(authEngineTwo)
348
+ .isNotSameAs(nextAuthEngineTwo)
349
+ .isNotSameAs(getAuthByEngine(authentications, "engine2"));
350
+ assertThat(authEngineThree)
351
+ .isNotSameAs(nextAuthEngineThree)
352
+ .isNotSameAs(getAuthByEngine(authentications, "engine3"));
353
+
354
+ assertThat(getAuthByEngine(authentications, "engine1").getCacheValidationTime())
355
+ .isEqualTo(addMinutes(5, ClockUtil.getCurrentTime()));
356
+ assertThat(getAuthByEngine(authentications, "engine2").getCacheValidationTime())
357
+ .isEqualTo(addMinutes(5, ClockUtil.getCurrentTime()));
358
+ assertThat(getAuthByEngine(authentications, "engine3").getCacheValidationTime())
359
+ .isEqualTo(addMinutes(5, ClockUtil.getCurrentTime()));
360
+ }
361
+
362
+ @Test
363
+ public void shouldInvalidateSessionDueToDeletedUserWithMultipleAuths() throws ServletException, IOException {
364
+ // given
365
+ ProcessEngine[] engineMocks = setupEngineMock("engine1", "engine2", "engine3");
366
+ Authentications authentications = setupAuth("engine1", "engine2", "engine3");
367
+ AuthenticationFilter filter = setupFilter(1000 * 60 * 5);
368
+
369
+ UserAuthentication authEngineOne = getAuthByEngine(authentications, "engine1");
370
+ UserAuthentication authEngineTwo = getAuthByEngine(authentications, "engine2");
371
+ UserAuthentication authEngineThree = getAuthByEngine(authentications, "engine3");
372
+
373
+ MockHttpServletRequest request = new MockHttpServletRequest();
374
+
375
+ // assume
376
+ assertThat(authEngineOne.getCacheValidationTime()).isNull();
377
+ assertThat(authEngineTwo.getCacheValidationTime()).isNull();
378
+ assertThat(authEngineThree.getCacheValidationTime()).isNull();
379
+
380
+ applyFilter(filter, request);
381
+
382
+ UserAuthentication nextAuthEngineOne = getAuthByEngine(authentications, "engine1");
383
+ assertThat(authEngineOne).isNotSameAs(nextAuthEngineOne);
384
+ UserAuthentication nextAuthEngineTwo = getAuthByEngine(authentications, "engine2");
385
+ assertThat(authEngineTwo).isNotSameAs(nextAuthEngineTwo);
386
+ UserAuthentication nextAuthEngineThree = getAuthByEngine(authentications, "engine3");
387
+ assertThat(authEngineThree).isNotSameAs(nextAuthEngineThree);
388
+
389
+ Date datePlus5Minutes = addMinutes(5, ClockUtil.getCurrentTime());
390
+ assertThat(nextAuthEngineOne.getCacheValidationTime())
391
+ .isEqualTo(datePlus5Minutes);
392
+ assertThat(nextAuthEngineTwo.getCacheValidationTime())
393
+ .isEqualTo(datePlus5Minutes);
394
+ assertThat(nextAuthEngineThree.getCacheValidationTime())
395
+ .isEqualTo(datePlus5Minutes);
396
+
397
+ User user = engineMocks[1].getIdentityService()
398
+ .createUserQuery()
399
+ .userId("userId2")
400
+ .singleResult();
401
+
402
+ when(user).thenReturn(null);
403
+
404
+ Date currentTime = addDays(ClockUtil.getCurrentTime(), 2);
405
+ ClockUtil.setCurrentTime(currentTime);
406
+
407
+ MockHttpServletResponse response = new MockHttpServletResponse();
408
+
409
+ // when
410
+ applyFilter(filter, request, response);
411
+
412
+ // then
413
+ assertThat(getAuthByEngine(authentications, "engine1")).isNotNull();
414
+ assertThat(getAuthByEngine(authentications, "engine2")).isNull();
415
+ assertThat(getAuthByEngine(authentications, "engine3")).isNotNull();
416
+ }
417
+
418
+ @Test
419
+ public void shouldNotRevalidateWhenValidationTimeNotDueWithMultipleAuths() throws ServletException, IOException {
420
+ // given
421
+ setupEngineMock("engine1", "engine2", "engine3");
422
+ AuthenticationFilter filter = setupFilter(1000 * 60 * 5);
423
+ Authentications authentications = setupAuth("engine1", "engine2", "engine3");
424
+
425
+ UserAuthentication authEngineOne = getAuthByEngine(authentications, "engine1");
426
+ UserAuthentication authEngineTwo = getAuthByEngine(authentications, "engine2");
427
+ UserAuthentication authEngineThree = getAuthByEngine(authentications, "engine3");
428
+
429
+ MockHttpServletRequest request = new MockHttpServletRequest();
430
+
431
+ // assume
432
+ assertThat(authEngineOne.getCacheValidationTime()).isNull();
433
+ assertThat(authEngineTwo.getCacheValidationTime()).isNull();
434
+ assertThat(authEngineThree.getCacheValidationTime()).isNull();
435
+
436
+ applyFilter(filter, request);
437
+
438
+ UserAuthentication nextAuthEngineOne = getAuthByEngine(authentications, "engine1");
439
+ assertThat(authEngineOne).isNotSameAs(nextAuthEngineOne);
440
+ UserAuthentication nextAuthEngineTwo = getAuthByEngine(authentications, "engine2");
441
+ assertThat(authEngineTwo).isNotSameAs(nextAuthEngineTwo);
442
+ UserAuthentication nextAuthEngineThree = getAuthByEngine(authentications, "engine3");
443
+ assertThat(authEngineThree).isNotSameAs(nextAuthEngineThree);
444
+
445
+ Date datePlus5Minutes = addMinutes(5, ClockUtil.getCurrentTime());
446
+ assertThat(nextAuthEngineOne.getCacheValidationTime()).isEqualTo(datePlus5Minutes);
447
+ assertThat(nextAuthEngineTwo.getCacheValidationTime()).isEqualTo(datePlus5Minutes);
448
+ assertThat(nextAuthEngineThree.getCacheValidationTime()).isEqualTo(datePlus5Minutes);
449
+
450
+ // when
451
+ applyFilter(filter, request);
452
+
453
+ // then
454
+ assertThat(nextAuthEngineOne)
455
+ .isSameAs(getAuthByEngine(authentications, "engine1"));
456
+ assertThat(nextAuthEngineTwo)
457
+ .isSameAs(getAuthByEngine(authentications, "engine2"));
458
+ assertThat(nextAuthEngineThree)
459
+ .isSameAs(getAuthByEngine(authentications, "engine3"));
460
+ assertThat(getAuthByEngine(authentications, "engine1").getCacheValidationTime()).isEqualTo(datePlus5Minutes);
461
+ assertThat(getAuthByEngine(authentications, "engine1").getCacheValidationTime()).isEqualTo(datePlus5Minutes);
462
+ assertThat(getAuthByEngine(authentications, "engine1").getCacheValidationTime()).isEqualTo(datePlus5Minutes);
463
+ }
464
+
465
+ // helpers ///////////////////////////////////////////////////////////////////////////////////////////////////////////
466
+
467
+ protected ProcessEngine[] setupEngineMock(String... engines) {
468
+ if (engines.length == 0) engines = new String[]{"engine1"};
469
+
470
+ mockedAuthenticationUtil = mockStatic(AuthenticationUtil.class);
471
+ mockedProcessEngineUtil = mockStatic(ProcessEngineUtil.class);
472
+ List<ProcessEngine> processEngines = new ArrayList<>();
473
+ Arrays.asList(engines).forEach(engine -> {
474
+ ProcessEngine processEngineMock = mock(ProcessEngine.class, RETURNS_DEEP_STUBS);
475
+ processEngines.add(processEngineMock);
476
+
477
+ when(processEngineMock.getName()).thenReturn(engine);
478
+ mockedProcessEngineUtil.when(() -> ProcessEngineUtil.lookupProcessEngine(eq(engine))).thenReturn(processEngineMock);
479
+ mockedAuthenticationUtil.when(() -> AuthenticationUtil.updateCache(any(), any(), anyLong())).thenCallRealMethod();
480
+ mockedAuthenticationUtil.when(() -> AuthenticationUtil.getSessionMutex(any())).thenCallRealMethod();
481
+ mockedAuthenticationUtil.when(() -> AuthenticationUtil.createAuthentication(eq(engine), any())).thenCallRealMethod();
482
+ mockedAuthenticationUtil.when(() -> AuthenticationUtil.createAuthentication(eq(engine), any(), any(), any())).thenCallRealMethod();
483
+ mockedAuthenticationUtil.when(() -> AuthenticationUtil.createAuthentication(eq(processEngineMock), any(), any(), any())).thenCallRealMethod();
484
+ });
485
+ return processEngines.toArray(new ProcessEngine[0]);
486
+ }
487
+
488
+ protected Authentications setupAuth(String... engines) {
489
+ if (engines.length == 0) engines = new String[]{"engine1"};
490
+
491
+ Authentications authentications = new Authentications();
492
+ List<String> enginesAsList = Arrays.asList(engines);
493
+ for (int i = 0; i < enginesAsList.size(); i++) {
494
+ String engine = enginesAsList.get(i);
495
+ UserAuthentication userAuthentication = AuthenticationUtil.createAuthentication(engine, "userId" + (i + 1));
496
+ authentications.addOrReplace(userAuthentication);
497
+ }
498
+ mockedAuthenticationUtil.when(() -> AuthenticationUtil.getAuthsFromSession(any(HttpSession.class))).thenReturn(authentications);
499
+ return authentications;
500
+ }
501
+
502
+ protected AuthenticationFilter setupFilter(long cacheTTL) throws ServletException {
503
+ MockFilterConfig config = new MockFilterConfig();
504
+ config.addInitParameter(AuthenticationFilter.AUTH_CACHE_TTL_INIT_PARAM_NAME, String.valueOf(cacheTTL));
505
+ return setupFilter(config);
506
+ }
507
+
508
+ protected AuthenticationFilter setupFilter(MockFilterConfig config) throws ServletException {
509
+ mockedSecurityActions = mockStatic(SecurityActions.class);
510
+ AuthenticationFilter authenticationFilter = new AuthenticationFilter();
511
+ authenticationFilter.init(config);
512
+ return authenticationFilter;
513
+ }
514
+
515
+ protected void applyFilter(AuthenticationFilter filter, MockHttpServletRequest request) throws ServletException, IOException {
516
+ applyFilter(filter, request, null);
517
+ }
518
+
519
+ protected void applyFilter(AuthenticationFilter filter, MockHttpServletRequest request, MockHttpServletResponse response) throws ServletException, IOException {
520
+ if (response == null) {
521
+ response = new MockHttpServletResponse();
522
+ }
523
+
524
+ filter.doFilter(request, response, new MockFilterChain());
525
+ }
526
+
527
+ protected UserAuthentication getAuthByEngine(Authentications authentications, String engineName) {
528
+ return authentications.getAuthentications()
529
+ .stream()
530
+ .filter(UserAuthentication -> UserAuthentication.getProcessEngineName().equals(engineName))
531
+ .findFirst()
532
+ .orElse(null);
533
+ }
534
+
535
+ protected Date addMinutes(int minutes, Date currentTime) {
536
+ return new Date(currentTime.getTime() + 1000L * 60L * minutes);
537
+ }
538
+
539
+ }
540
+
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/auth/ContainerAuthenticationFilterTest.java ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.webapp.impl.security.auth;
18
+
19
+ import static org.mockito.Mockito.any;
20
+ import static org.mockito.Mockito.anyBoolean;
21
+ import static org.mockito.Mockito.anyString;
22
+ import static org.mockito.Mockito.mock;
23
+ import static org.mockito.Mockito.mockStatic;
24
+ import static org.mockito.Mockito.never;
25
+ import static org.mockito.Mockito.verify;
26
+ import static org.mockito.Mockito.when;
27
+
28
+ import java.io.IOException;
29
+ import java.security.Principal;
30
+ import java.util.ArrayList;
31
+ import java.util.Arrays;
32
+ import java.util.Collection;
33
+
34
+ import javax.servlet.Filter;
35
+ import javax.servlet.FilterChain;
36
+ import javax.servlet.ServletException;
37
+ import javax.ws.rs.core.Response.Status;
38
+
39
+ import org.camunda.bpm.engine.AuthorizationService;
40
+ import org.camunda.bpm.engine.IdentityService;
41
+ import org.camunda.bpm.engine.ProcessEngine;
42
+ import org.camunda.bpm.engine.identity.Group;
43
+ import org.camunda.bpm.engine.identity.GroupQuery;
44
+ import org.camunda.bpm.engine.identity.Tenant;
45
+ import org.camunda.bpm.engine.identity.TenantQuery;
46
+ import org.camunda.bpm.engine.identity.User;
47
+ import org.camunda.bpm.engine.identity.UserQuery;
48
+ import org.camunda.bpm.engine.impl.AuthorizationServiceImpl;
49
+ import org.camunda.bpm.engine.impl.IdentityServiceImpl;
50
+ import org.camunda.bpm.engine.rest.helper.MockProvider;
51
+ import org.camunda.bpm.engine.rest.security.auth.ProcessEngineAuthenticationFilter;
52
+ import org.camunda.bpm.engine.rest.security.auth.impl.ContainerBasedAuthenticationProvider;
53
+ import org.camunda.bpm.engine.rest.spi.ProcessEngineProvider;
54
+ import org.camunda.bpm.engine.rest.spi.impl.MockedProcessEngineProvider;
55
+ import org.camunda.bpm.webapp.impl.util.ProcessEngineUtil;
56
+ import org.camunda.bpm.webapp.impl.util.ServletContextUtil;
57
+ import org.junit.After;
58
+ import org.junit.Assert;
59
+ import org.junit.Before;
60
+ import org.junit.Test;
61
+ import org.junit.runner.RunWith;
62
+ import org.junit.runners.Parameterized;
63
+ import org.junit.runners.Parameterized.Parameters;
64
+ import org.mockito.MockedStatic;
65
+ import org.springframework.mock.web.MockFilterChain;
66
+ import org.springframework.mock.web.MockFilterConfig;
67
+ import org.springframework.mock.web.MockHttpServletRequest;
68
+ import org.springframework.mock.web.MockHttpServletResponse;
69
+ import org.springframework.mock.web.MockServletContext;
70
+
71
+ @RunWith(Parameterized.class)
72
+ public class ContainerAuthenticationFilterTest {
73
+
74
+ protected static final String SERVICE_PATH = "/camunda";
75
+
76
+ private Authentications authentications;
77
+
78
+ protected AuthorizationService authorizationService;
79
+ protected IdentityService identityService;
80
+
81
+ protected Filter authenticationFilter;
82
+
83
+ protected String requestUrl;
84
+ protected String engineName;
85
+ protected boolean alreadyAuthenticated;
86
+ protected boolean authenticationExpected;
87
+
88
+ protected ProcessEngine currentEngine;
89
+
90
+ private MockedStatic<AuthenticationUtil> authenticationUtilMockedStatic;
91
+ private MockedStatic<ProcessEngineUtil> processEngineUtilMockedStatic;
92
+
93
+ public ContainerAuthenticationFilterTest(String requestUrl, String engineName, boolean alreadyAuthenticated, boolean authenticationExpected) {
94
+ this.requestUrl = requestUrl;
95
+ this.engineName = engineName;
96
+ if (engineName == null) {
97
+ this.engineName = "default";
98
+ }
99
+ this.alreadyAuthenticated = alreadyAuthenticated;
100
+ this.authenticationExpected = authenticationExpected;
101
+ }
102
+
103
+ @Parameters
104
+ public static Collection<Object[]> getRequestUrls() {
105
+ return Arrays.asList(new Object[][]{
106
+ {"/app/cockpit/default/", "default", false, true},
107
+ {"/app/cockpit/engine2/", "engine2", false, true},
108
+ {"/api/cockpit/plugin/some-plugin/default/process-instance", "default", false, true},
109
+ {"/api/cockpit/plugin/some-plugin/static/process-instance", null, false, false},
110
+
111
+ {"/app/cockpit/default/", "default", true, false},
112
+ {"/app/cockpit/engine2/", "engine2", true, false},
113
+ {"/api/cockpit/plugin/some-plugin/default/process-instance", "default", true, false},
114
+ {"/api/cockpit/plugin/some-plugin/static/process-instance", null, true, false},
115
+
116
+ {"/app/tasklist/default/", "default", false, true},
117
+ {"/app/tasklist/engine2/", "engine2", false, true},
118
+ {"/api/tasklist/plugin/some-plugin/default/process-instance", "default", false, true},
119
+ {"/api/tasklist/plugin/some-plugin/static/process-instance", null, false, false},
120
+
121
+ {"/app/tasklist/default/", "default", true, false},
122
+ {"/app/tasklist/engine2/", "engine2", true, false},
123
+ {"/api/tasklist/plugin/some-plugin/default/process-instance", "default", true, false},
124
+ {"/api/tasklist/plugin/some-plugin/static/process-instance", null, true, false},
125
+
126
+ {"/app/admin/default/", "default", false, true},
127
+ {"/app/admin/engine2/", "engine2", false, true},
128
+ {"/api/admin/plugin/some-plugin/default/process-instance", "default", false, true},
129
+ {"/api/admin/plugin/some-plugin/static/process-instance", null, false, false},
130
+
131
+ {"/app/admin/default/", "default", true, false},
132
+ {"/app/admin/engine2/", "engine2", true, false},
133
+ {"/api/admin/plugin/some-plugin/default/process-instance", "default", true, false},
134
+ {"/api/admin/plugin/some-plugin/static/process-instance", null, true, false},
135
+
136
+ {"/app/welcome/default/", "default", false, true},
137
+ {"/app/welcome/engine2/", "engine2", false, true},
138
+ {"/api/welcome/plugin/some-plugin/default/process-instance", "default", false, true},
139
+ {"/api/welcome/plugin/some-plugin/static/process-instance", null, false, false},
140
+
141
+ {"/api/engine/engine/default/process-instance", "default", false, true},
142
+ {"/api/engine/engine/engine2/process-instance", "engine2", false, true},
143
+
144
+ {"/api/engine/engine/default/process-instance", "default", true, false},
145
+ {"/api/engine/engine/engine2/process-instance", "engine2", true, false},
146
+
147
+ {"/lib/deps.js", null, false, false},
148
+ {"/app/cockpit/styles/styles.css", null, false, false},
149
+ {"/api/admin/auth/user/default", null, false, false},
150
+
151
+ {"/lib/deps.js", null, true, false},
152
+ {"/app/cockpit/styles/styles.css", null, true, false},
153
+ {"/api/admin/auth/user/default", null, true, false}
154
+ });
155
+ }
156
+
157
+ @Before
158
+ public void setup() throws ServletException {
159
+ setupProcessEngine();
160
+ setupAuthentications();
161
+ setupFilter();
162
+ }
163
+
164
+ protected void setupProcessEngine() {
165
+ final ProcessEngineProvider provider = new MockedProcessEngineProvider();
166
+ currentEngine = provider.getProcessEngine(engineName);
167
+
168
+ authorizationService = mock(AuthorizationServiceImpl.class);
169
+ identityService = mock(IdentityServiceImpl.class);
170
+
171
+ when(currentEngine.getAuthorizationService()).thenReturn(authorizationService);
172
+ when(currentEngine.getIdentityService()).thenReturn(identityService);
173
+ processEngineUtilMockedStatic = mockStatic(ProcessEngineUtil.class);
174
+ processEngineUtilMockedStatic.when(() -> ProcessEngineUtil.lookupProcessEngine(any())).thenReturn(currentEngine);
175
+
176
+ User mockedUser = mock(User.class);
177
+ when(mockedUser.getId()).thenReturn(MockProvider.EXAMPLE_USER_ID);
178
+
179
+ UserQuery mockUserQuery = mock(UserQuery.class);
180
+ when(identityService.createUserQuery()).thenReturn(mockUserQuery);
181
+ when(mockUserQuery.userId(any())).thenReturn(mockUserQuery);
182
+ when(mockUserQuery.singleResult()).thenReturn(mockedUser);
183
+
184
+ GroupQuery mockGroupQuery = mock(GroupQuery.class);
185
+ when(identityService.createGroupQuery()).thenReturn(mockGroupQuery);
186
+ when(mockGroupQuery.groupMember(any())).thenReturn(mockGroupQuery);
187
+ when(mockGroupQuery.list()).thenReturn(new ArrayList<Group>());
188
+
189
+ TenantQuery mockTenantQuery = mock(TenantQuery.class);
190
+ when(identityService.createTenantQuery()).thenReturn(mockTenantQuery);
191
+ when(mockTenantQuery.userMember(any())).thenReturn(mockTenantQuery);
192
+ when(mockTenantQuery.includingGroupsOfUser(anyBoolean())).thenReturn(mockTenantQuery);
193
+ when(mockTenantQuery.list()).thenReturn(new ArrayList<Tenant>());
194
+ }
195
+
196
+ protected void setupAuthentications() {
197
+ Authentications.clearCurrent();
198
+ authenticationUtilMockedStatic = mockStatic(AuthenticationUtil.class);
199
+ authentications = mock(Authentications.class);
200
+ authenticationUtilMockedStatic.when(() -> AuthenticationUtil.getAuthsFromSession(any())).thenReturn(authentications);
201
+ UserAuthentication authentication = mock(UserAuthentication.class);
202
+ authenticationUtilMockedStatic
203
+ .when(() -> AuthenticationUtil.createAuthentication(any(ProcessEngine.class), any(), any(), any()))
204
+ .thenReturn(authentication);
205
+ }
206
+
207
+ protected void setupFilter() throws ServletException {
208
+ MockFilterConfig config = new MockFilterConfig();
209
+ config.addInitParameter(ProcessEngineAuthenticationFilter.AUTHENTICATION_PROVIDER_PARAM, ContainerBasedAuthenticationProvider.class.getName());
210
+ authenticationFilter = new ContainerBasedAuthenticationFilter();
211
+ authenticationFilter.init(config);
212
+ }
213
+
214
+ protected void applyFilter(MockHttpServletRequest request, MockHttpServletResponse response, String username) throws IOException, ServletException {
215
+ Principal principal = mock(Principal.class);
216
+ when(principal.getName()).thenReturn(username);
217
+ request.setUserPrincipal(principal);
218
+ request.setMethod("GET");
219
+ FilterChain filterChain = new MockFilterChain();
220
+ authenticationFilter.doFilter(request, response, filterChain);
221
+ }
222
+
223
+ @After
224
+ public void teardown() {
225
+ authenticationUtilMockedStatic.close();
226
+ processEngineUtilMockedStatic.close();
227
+ }
228
+
229
+ @Test
230
+ public void shouldCheckCustomApplicationPath() throws IOException, ServletException {
231
+ testContainerAuthenticationCheck("/my-custom/application/path");
232
+ }
233
+
234
+ @Test
235
+ public void shouldCheckEmptyApplicationPath() throws IOException, ServletException {
236
+ testContainerAuthenticationCheck("");
237
+ }
238
+
239
+ public void testContainerAuthenticationCheck(String applicationPath) throws IOException, ServletException {
240
+ if (alreadyAuthenticated) {
241
+ Authentication authentication = mock(Authentication.class);
242
+ when(authentication.getProcessEngineName()).thenReturn(engineName);
243
+ when(authentication.getIdentityId()).thenReturn(MockProvider.EXAMPLE_USER_ID);
244
+
245
+ when(authentications.getAuthenticationForProcessEngine(anyString())).thenReturn(authentication);
246
+ }
247
+ else {
248
+ when(authentications.getAuthenticationForProcessEngine(anyString())).thenReturn(null);
249
+ }
250
+
251
+ MockHttpServletResponse response = new MockHttpServletResponse();
252
+ MockHttpServletRequest request = null;
253
+
254
+ if (!applicationPath.isEmpty()) {
255
+ MockServletContext mockServletContext = new MockServletContext();
256
+ request = new MockHttpServletRequest(mockServletContext);
257
+ requestUrl = applicationPath + requestUrl;
258
+ ServletContextUtil.setAppPath(applicationPath, mockServletContext);
259
+
260
+ } else {
261
+ request = new MockHttpServletRequest();
262
+
263
+ }
264
+
265
+ request.setRequestURI(SERVICE_PATH + requestUrl);
266
+ request.setContextPath(SERVICE_PATH);
267
+ applyFilter(request, response, MockProvider.EXAMPLE_USER_ID);
268
+
269
+ Assert.assertEquals(Status.OK.getStatusCode(), response.getStatus());
270
+
271
+ if (authenticationExpected) {
272
+ verify(authentications).addOrReplace(any(UserAuthentication.class));
273
+
274
+ } else {
275
+ verify(authentications, never()).addOrReplace(any(UserAuthentication.class));
276
+ }
277
+ }
278
+ }
279
+
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/auth/UserAuthenticationResourceLoggingTest.java ADDED
@@ -0,0 +1,303 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.webapp.impl.security.auth;
18
+
19
+ import static org.assertj.core.api.Assertions.assertThat;
20
+
21
+ import ch.qos.logback.classic.Level;
22
+ import ch.qos.logback.classic.spi.ILoggingEvent;
23
+ import java.util.List;
24
+ import org.camunda.bpm.engine.AuthorizationService;
25
+ import org.camunda.bpm.engine.IdentityService;
26
+ import org.camunda.bpm.engine.ProcessEngine;
27
+ import org.camunda.bpm.engine.authorization.Authorization;
28
+ import org.camunda.bpm.engine.authorization.Permissions;
29
+ import org.camunda.bpm.engine.authorization.Resources;
30
+ import org.camunda.bpm.engine.identity.User;
31
+ import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
32
+ import org.camunda.bpm.engine.impl.util.ClockUtil;
33
+ import org.camunda.bpm.engine.test.ProcessEngineRule;
34
+ import org.camunda.commons.testing.ProcessEngineLoggingRule;
35
+ import org.junit.After;
36
+ import org.junit.Before;
37
+ import org.junit.Rule;
38
+ import org.junit.Test;
39
+ import org.springframework.mock.web.MockHttpServletRequest;
40
+
41
+ public class UserAuthenticationResourceLoggingTest {
42
+
43
+ @Rule
44
+ public ProcessEngineRule processEngineRule = new ProcessEngineRule("camunda-test-engine.cfg.xml");
45
+ @Rule
46
+ public ProcessEngineLoggingRule loggingRule = new ProcessEngineLoggingRule().watch("org.camunda.bpm.webapp")
47
+ .level(Level.INFO);
48
+
49
+ protected ProcessEngine processEngine;
50
+ protected ProcessEngineConfigurationImpl processEngineConfiguration;
51
+ protected IdentityService identityService;
52
+ protected AuthorizationService authorizationService;
53
+
54
+ protected boolean authorizationEnabledInitialValue;
55
+ protected boolean webappsAuthenticationLoggingEnabledInitialValue;
56
+
57
+ @Before
58
+ public void setUp() {
59
+ this.processEngine = processEngineRule.getProcessEngine();
60
+ this.processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
61
+ this.identityService = processEngine.getIdentityService();
62
+ this.authorizationService = processEngine.getAuthorizationService();
63
+
64
+ authorizationEnabledInitialValue = processEngineConfiguration.isAuthorizationEnabled();
65
+ webappsAuthenticationLoggingEnabledInitialValue = processEngineConfiguration.isWebappsAuthenticationLoggingEnabled();
66
+ }
67
+
68
+ @After
69
+ public void tearDown() {
70
+ ClockUtil.reset();
71
+ processEngineConfiguration.setAuthorizationEnabled(authorizationEnabledInitialValue);
72
+ processEngineConfiguration.setWebappsAuthenticationLoggingEnabled(webappsAuthenticationLoggingEnabledInitialValue);
73
+
74
+ for (User user : identityService.createUserQuery().list()) {
75
+ identityService.deleteUser(user.getId());
76
+ }
77
+ for (Authorization authorization : authorizationService.createAuthorizationQuery().list()) {
78
+ authorizationService.deleteAuthorization(authorization.getId());
79
+ }
80
+
81
+ Authentications.clearCurrent();
82
+ }
83
+
84
+ @Test
85
+ public void shouldProduceLogStatementOnValidLogin() {
86
+ // given
87
+ User jonny = identityService.newUser("jonny");
88
+ jonny.setPassword("jonnyspassword");
89
+ identityService.saveUser(jonny);
90
+
91
+ UserAuthenticationResource authResource = new UserAuthenticationResource();
92
+ authResource.request = new MockHttpServletRequest();
93
+
94
+ processEngineConfiguration.setWebappsAuthenticationLoggingEnabled(true);
95
+
96
+ // when
97
+ authResource.doLogin("webapps-test-engine", "tasklist", "jonny", "jonnyspassword");
98
+
99
+ // then
100
+ List<ILoggingEvent> filteredLog = loggingRule.getFilteredLog("jonny");
101
+ assertThat(filteredLog).hasSize(1);
102
+ assertThat(filteredLog.get(0).getFormattedMessage()).contains("Successful login for user jonny");
103
+ }
104
+
105
+ @Test
106
+ public void shouldNotProduceLogStatementOnValidLoginWhenDisabled() {
107
+ // given
108
+ User jonny = identityService.newUser("jonny");
109
+ jonny.setPassword("jonnyspassword");
110
+ identityService.saveUser(jonny);
111
+
112
+ UserAuthenticationResource authResource = new UserAuthenticationResource();
113
+ authResource.request = new MockHttpServletRequest();
114
+
115
+ processEngineConfiguration.setWebappsAuthenticationLoggingEnabled(false);
116
+
117
+ // when
118
+ authResource.doLogin("webapps-test-engine", "tasklist", "jonny", "jonnyspassword");
119
+
120
+ // then
121
+ List<ILoggingEvent> filteredLog = loggingRule.getFilteredLog("jonny");
122
+ assertThat(filteredLog).hasSize(0);
123
+ }
124
+
125
+ @Test
126
+ public void shouldProduceLogStatementOnInvalidLogin() {
127
+ // given
128
+ User jonny = identityService.newUser("jonny");
129
+ jonny.setPassword("jonnyspassword");
130
+ identityService.saveUser(jonny);
131
+
132
+ UserAuthenticationResource authResource = new UserAuthenticationResource();
133
+ authResource.request = new MockHttpServletRequest();
134
+
135
+ processEngineConfiguration.setWebappsAuthenticationLoggingEnabled(true);
136
+
137
+ // when
138
+ authResource.doLogin("webapps-test-engine", "tasklist", "jonny", "NOT_jonnyspassword");
139
+
140
+ // then
141
+ List<ILoggingEvent> filteredLog = loggingRule.getFilteredLog("jonny");
142
+ assertThat(filteredLog).hasSize(1);
143
+ assertThat(filteredLog.get(0).getFormattedMessage()).contains("Failed login attempt for user jonny. Reason: bad credentials");
144
+ }
145
+
146
+ @Test
147
+ public void shouldNotProduceLogStatementOnInvalidLoginWhenDisabled() {
148
+ // given
149
+ User jonny = identityService.newUser("jonny");
150
+ jonny.setPassword("jonnyspassword");
151
+ identityService.saveUser(jonny);
152
+
153
+ UserAuthenticationResource authResource = new UserAuthenticationResource();
154
+ authResource.request = new MockHttpServletRequest();
155
+
156
+ processEngineConfiguration.setWebappsAuthenticationLoggingEnabled(false);
157
+
158
+ // when
159
+ authResource.doLogin("webapps-test-engine", "tasklist", "jonny", "NOT_jonnyspassword");
160
+
161
+ // then
162
+ List<ILoggingEvent> filteredLog = loggingRule.getFilteredLog("jonny");
163
+ assertThat(filteredLog).hasSize(0);
164
+ }
165
+
166
+ @Test
167
+ public void shouldProduceLogStatementOnLogout() {
168
+ // given
169
+ User jonny = identityService.newUser("jonny");
170
+ jonny.setPassword("jonnyspassword");
171
+ identityService.saveUser(jonny);
172
+ setAuthentication("jonny", "webapps-test-engine");
173
+
174
+ UserAuthenticationResource authResource = new UserAuthenticationResource();
175
+ authResource.request = new MockHttpServletRequest();
176
+
177
+ processEngineConfiguration.setWebappsAuthenticationLoggingEnabled(true);
178
+
179
+ // when
180
+ authResource.doLogout("webapps-test-engine");
181
+
182
+ // then
183
+ List<ILoggingEvent> filteredLog = loggingRule.getFilteredLog("jonny");
184
+ assertThat(filteredLog).hasSize(1);
185
+ assertThat(filteredLog.get(0).getFormattedMessage()).contains("Successful logout for user jonny");
186
+ }
187
+
188
+ @Test
189
+ public void shouldNotProduceLogStatementOnLogoutWhenDisabled() {
190
+ // given
191
+ User jonny = identityService.newUser("jonny");
192
+ jonny.setPassword("jonnyspassword");
193
+ identityService.saveUser(jonny);
194
+ setAuthentication("jonny", "webapps-test-engine");
195
+
196
+ UserAuthenticationResource authResource = new UserAuthenticationResource();
197
+ authResource.request = new MockHttpServletRequest();
198
+
199
+ processEngineConfiguration.setWebappsAuthenticationLoggingEnabled(false);
200
+
201
+ // when
202
+ authResource.doLogout("webapps-test-engine");
203
+
204
+ // then
205
+ List<ILoggingEvent> filteredLog = loggingRule.getFilteredLog("jonny");
206
+ assertThat(filteredLog).hasSize(0);
207
+ }
208
+
209
+ @Test
210
+ public void shouldNotProduceLogStatementOnLogoutWhenNoAuthentication() {
211
+ // given
212
+ UserAuthenticationResource authResource = new UserAuthenticationResource();
213
+ authResource.request = new MockHttpServletRequest();
214
+
215
+ processEngineConfiguration.setWebappsAuthenticationLoggingEnabled(true);
216
+
217
+ // when
218
+ authResource.doLogout("webapps-test-engine");
219
+
220
+ // then
221
+ List<ILoggingEvent> filteredLog = loggingRule.getFilteredLog("jonny");
222
+ assertThat(filteredLog).hasSize(0);
223
+ }
224
+
225
+ @Test
226
+ public void shouldProduceLogStatementOnLoginWhenAuthorized() {
227
+ // given
228
+ User jonny = identityService.newUser("jonny");
229
+ jonny.setPassword("jonnyspassword");
230
+ identityService.saveUser(jonny);
231
+
232
+ Authorization authorization = authorizationService.createNewAuthorization(Authorization.AUTH_TYPE_GRANT);
233
+ authorization.setResource(Resources.APPLICATION);
234
+ authorization.setResourceId("tasklist");
235
+ authorization.setPermissions(new Permissions[] {Permissions.ACCESS});
236
+ authorization.setUserId(jonny.getId());
237
+ authorizationService.saveAuthorization(authorization);
238
+
239
+ processEngineConfiguration.setAuthorizationEnabled(true);
240
+ processEngineConfiguration.setWebappsAuthenticationLoggingEnabled(true);
241
+
242
+ UserAuthenticationResource authResource = new UserAuthenticationResource();
243
+ authResource.request = new MockHttpServletRequest();
244
+
245
+ // when
246
+ authResource.doLogin("webapps-test-engine", "tasklist", "jonny", "jonnyspassword");
247
+
248
+ // then
249
+ List<ILoggingEvent> filteredLog = loggingRule.getFilteredLog("jonny");
250
+ assertThat(filteredLog).hasSize(1);
251
+ assertThat(filteredLog.get(0).getFormattedMessage()).contains("Successful login for user jonny");
252
+ }
253
+
254
+ @Test
255
+ public void shouldProduceLogStatementOnLoginWhenNotAuthorized() {
256
+ // given
257
+ User jonny = identityService.newUser("jonny");
258
+ jonny.setPassword("jonnyspassword");
259
+ identityService.saveUser(jonny);
260
+
261
+ processEngineConfiguration.setAuthorizationEnabled(true);
262
+ processEngineConfiguration.setWebappsAuthenticationLoggingEnabled(true);
263
+
264
+ UserAuthenticationResource authResource = new UserAuthenticationResource();
265
+ authResource.request = new MockHttpServletRequest();
266
+
267
+ // when
268
+ authResource.doLogin("webapps-test-engine", "tasklist", "jonny", "jonnyspassword");
269
+
270
+ // then
271
+ List<ILoggingEvent> filteredLog = loggingRule.getFilteredLog("jonny");
272
+ assertThat(filteredLog).hasSize(1);
273
+ assertThat(filteredLog.get(0).getFormattedMessage()).contains("Failed login attempt for user jonny. Reason: not authorized");
274
+ }
275
+
276
+ @Test
277
+ public void shouldNotProduceLogStatementOnLoginWhenNotAuthorizedAndWebappsLoggingDisabled() {
278
+ // given
279
+ User jonny = identityService.newUser("jonny");
280
+ jonny.setPassword("jonnyspassword");
281
+ identityService.saveUser(jonny);
282
+
283
+ processEngineConfiguration.setAuthorizationEnabled(true);
284
+ processEngineConfiguration.setWebappsAuthenticationLoggingEnabled(false);
285
+
286
+ UserAuthenticationResource authResource = new UserAuthenticationResource();
287
+ authResource.request = new MockHttpServletRequest();
288
+
289
+ // when
290
+ authResource.doLogin("webapps-test-engine", "tasklist", "jonny", "jonnyspassword");
291
+
292
+ // then
293
+ List<ILoggingEvent> filteredLog = loggingRule.getFilteredLog("jonny");
294
+ assertThat(filteredLog).hasSize(0);
295
+ }
296
+
297
+ protected void setAuthentication(String user, String engineName) {
298
+ Authentications authentications = new Authentications();
299
+ authentications.addOrReplace(new UserAuthentication(user, engineName));
300
+ Authentications.setCurrent(authentications);
301
+ }
302
+
303
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/auth/UserAuthenticationResourceTest.java ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.webapp.impl.security.auth;
18
+
19
+ import static org.assertj.core.api.Assertions.assertThat;
20
+ import static org.mockito.Mockito.mockStatic;
21
+
22
+ import java.util.Date;
23
+ import javax.ws.rs.core.Response;
24
+ import javax.ws.rs.core.Response.Status;
25
+ import org.camunda.bpm.engine.AuthorizationService;
26
+ import org.camunda.bpm.engine.IdentityService;
27
+ import org.camunda.bpm.engine.ProcessEngine;
28
+ import org.camunda.bpm.engine.ProcessEngineConfiguration;
29
+ import org.camunda.bpm.engine.authorization.Authorization;
30
+ import org.camunda.bpm.engine.authorization.Permissions;
31
+ import org.camunda.bpm.engine.authorization.Resources;
32
+ import org.camunda.bpm.engine.identity.User;
33
+ import org.camunda.bpm.engine.impl.util.ClockUtil;
34
+ import org.camunda.bpm.engine.test.ProcessEngineRule;
35
+ import org.camunda.bpm.webapp.impl.util.ServletContextUtil;
36
+ import org.junit.After;
37
+ import org.junit.Assert;
38
+ import org.junit.Before;
39
+ import org.junit.Rule;
40
+ import org.junit.Test;
41
+ import org.mockito.MockedStatic;
42
+ import org.springframework.mock.web.MockHttpServletRequest;
43
+
44
+ /**
45
+ * @author Thorben Lindhauer
46
+ *
47
+ */
48
+ public class UserAuthenticationResourceTest {
49
+
50
+ @Rule
51
+ public ProcessEngineRule processEngineRule = new ProcessEngineRule("camunda-test-engine.cfg.xml");
52
+
53
+ protected ProcessEngine processEngine;
54
+ protected ProcessEngineConfiguration processEngineConfiguration;
55
+ protected IdentityService identityService;
56
+ protected AuthorizationService authorizationService;
57
+
58
+ @Before
59
+ public void setUp() {
60
+ this.processEngine = processEngineRule.getProcessEngine();
61
+ this.processEngineConfiguration = processEngine.getProcessEngineConfiguration();
62
+ this.identityService = processEngine.getIdentityService();
63
+ this.authorizationService = processEngine.getAuthorizationService();
64
+ }
65
+
66
+ @After
67
+ public void tearDown() {
68
+ ClockUtil.reset();
69
+ processEngineConfiguration.setAuthorizationEnabled(false);
70
+
71
+ for (User user : identityService.createUserQuery().list()) {
72
+ identityService.deleteUser(user.getId());
73
+ }
74
+ for (Authorization authorization : authorizationService.createAuthorizationQuery().list()) {
75
+ authorizationService.deleteAuthorization(authorization.getId());
76
+ }
77
+
78
+ clearAuthentication();
79
+ }
80
+
81
+ @Test
82
+ public void testAuthorizationCheckGranted() {
83
+ // given
84
+ User jonny = identityService.newUser("jonny");
85
+ jonny.setPassword("jonnyspassword");
86
+ identityService.saveUser(jonny);
87
+
88
+ Authorization authorization = authorizationService.createNewAuthorization(Authorization.AUTH_TYPE_GRANT);
89
+ authorization.setResource(Resources.APPLICATION);
90
+ authorization.setResourceId("tasklist");
91
+ authorization.setPermissions(new Permissions[] {Permissions.ACCESS});
92
+ authorization.setUserId(jonny.getId());
93
+ authorizationService.saveAuthorization(authorization);
94
+
95
+ processEngineConfiguration.setAuthorizationEnabled(true);
96
+ setAuthentication("jonny", "webapps-test-engine");
97
+
98
+ // when
99
+ UserAuthenticationResource authResource = new UserAuthenticationResource();
100
+ authResource.request = new MockHttpServletRequest();
101
+ Response response = authResource.doLogin("webapps-test-engine", "tasklist", "jonny", "jonnyspassword");
102
+
103
+ // then
104
+ Assert.assertEquals(Status.OK.getStatusCode(), response.getStatus());
105
+ }
106
+
107
+ @Test
108
+ public void testSessionRevalidationOnAuthorization() {
109
+ // given
110
+ User jonny = identityService.newUser("jonny");
111
+ jonny.setPassword("jonnyspassword");
112
+ identityService.saveUser(jonny);
113
+
114
+ Authorization authorization = authorizationService.createNewAuthorization(Authorization.AUTH_TYPE_GRANT);
115
+ authorization.setResource(Resources.APPLICATION);
116
+ authorization.setResourceId("tasklist");
117
+ authorization.setPermissions(new Permissions[] {Permissions.ACCESS});
118
+ authorization.setUserId(jonny.getId());
119
+ authorizationService.saveAuthorization(authorization);
120
+
121
+ processEngineConfiguration.setAuthorizationEnabled(true);
122
+ setAuthentication("jonny", "webapps-test-engine");
123
+
124
+ // when
125
+ UserAuthenticationResource authResource = new UserAuthenticationResource();
126
+ authResource.request = new MockHttpServletRequest();
127
+ String oldSessionId = authResource.request.getSession().getId();
128
+
129
+ // first login session
130
+ Response response = authResource.doLogin("webapps-test-engine", "tasklist", "jonny", "jonnyspassword");
131
+ String newSessionId = authResource.request.getSession().getId();
132
+
133
+ authResource.doLogout("webapps-test-engine");
134
+
135
+ // second login session
136
+ response = authResource.doLogin("webapps-test-engine", "tasklist", "jonny", "jonnyspassword");
137
+ String newestSessionId = authResource.request.getSession().getId();
138
+
139
+ // then
140
+ Assert.assertEquals(Status.OK.getStatusCode(), response.getStatus());
141
+ Assert.assertNotEquals(oldSessionId, newSessionId);
142
+ Assert.assertNotEquals(newSessionId, newestSessionId);
143
+ }
144
+
145
+ @Test
146
+ public void testAuthorizationCheckNotGranted() {
147
+ // given
148
+ User jonny = identityService.newUser("jonny");
149
+ jonny.setPassword("jonnyspassword");
150
+ identityService.saveUser(jonny);
151
+
152
+ processEngineConfiguration.setAuthorizationEnabled(true);
153
+ setAuthentication("jonny", "webapps-test-engine");
154
+
155
+ // when
156
+ UserAuthenticationResource authResource = new UserAuthenticationResource();
157
+ authResource.request = new MockHttpServletRequest();
158
+ Response response = authResource.doLogin("webapps-test-engine", "tasklist", "jonny", "jonnyspassword");
159
+
160
+ // then
161
+ Assert.assertEquals(Status.FORBIDDEN.getStatusCode(), response.getStatus());
162
+ }
163
+
164
+ @Test
165
+ public void testAuthorizationCheckDeactivated() {
166
+ // given
167
+ User jonny = identityService.newUser("jonny");
168
+ jonny.setPassword("jonnyspassword");
169
+ identityService.saveUser(jonny);
170
+
171
+ processEngineConfiguration.setAuthorizationEnabled(false);
172
+ setAuthentication("jonny", "webapps-test-engine");
173
+
174
+ // when
175
+ UserAuthenticationResource authResource = new UserAuthenticationResource();
176
+ authResource.request = new MockHttpServletRequest();
177
+ Response response = authResource.doLogin("webapps-test-engine", "tasklist", "jonny", "jonnyspassword");
178
+
179
+ // then
180
+ Assert.assertEquals(Status.OK.getStatusCode(), response.getStatus());
181
+ }
182
+
183
+ @Test
184
+ public void shouldSetAuthCacheValidationTime() {
185
+ // given
186
+ ClockUtil.setCurrentTime(ClockUtil.getCurrentTime());
187
+ User jonny = identityService.newUser("jonny");
188
+ jonny.setPassword("jonnyspassword");
189
+ identityService.saveUser(jonny);
190
+
191
+ MockHttpServletRequest request = new MockHttpServletRequest();
192
+ ServletContextUtil.setCacheTTLForLogin(1000 * 60 * 5, request.getServletContext());
193
+
194
+ // when
195
+ UserAuthenticationResource authResource = new UserAuthenticationResource();
196
+ authResource.request = request;
197
+ authResource.doLogin("webapps-test-engine", "tasklist", "jonny", "jonnyspassword");
198
+
199
+ // then
200
+ UserAuthentication userAuthentication = AuthenticationUtil.getAuthsFromSession(request.getSession())
201
+ .getAuthentications()
202
+ .get(0);
203
+ assertThat(userAuthentication.getCacheValidationTime())
204
+ .isEqualTo(new Date(ClockUtil.getCurrentTime().getTime() + 1000 * 60 * 5));
205
+ }
206
+
207
+ @Test
208
+ public void shouldReturnUnauthorizedOnNullAuthentication() {
209
+ // given
210
+ User jonny = identityService.newUser("jonny");
211
+ jonny.setPassword("jonnyspassword");
212
+ identityService.saveUser(jonny);
213
+ UserAuthenticationResource authResource = new UserAuthenticationResource();
214
+ authResource.request = new MockHttpServletRequest();
215
+
216
+ try (MockedStatic<AuthenticationUtil> authenticationUtilMock = mockStatic(AuthenticationUtil.class)) {
217
+ authenticationUtilMock.when(() -> AuthenticationUtil.createAuthentication("webapps-test-engine", "jonny")).thenReturn(null);
218
+
219
+ // when
220
+ Response response = authResource.doLogin("webapps-test-engine", "tasklist", "jonny", "jonnyspassword");
221
+
222
+ // then
223
+ Assert.assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
224
+ }
225
+ }
226
+
227
+ protected void setAuthentication(String user, String engineName) {
228
+ Authentications authentications = new Authentications();
229
+ authentications.addOrReplace(new UserAuthentication(user, engineName));
230
+ Authentications.setCurrent(authentications);
231
+ }
232
+
233
+ protected void clearAuthentication() {
234
+ Authentications.clearCurrent();
235
+ }
236
+
237
+
238
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/filter/RequestFilterTest.java ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.webapp.impl.security.filter;
18
+
19
+ import static org.assertj.core.api.Assertions.assertThat;
20
+
21
+ import java.util.Arrays;
22
+ import java.util.Collection;
23
+ import java.util.Map;
24
+ import org.junit.Test;
25
+ import org.junit.runner.RunWith;
26
+ import org.junit.runners.Parameterized;
27
+
28
+ /**
29
+ *
30
+ * @author nico.rehwaldt
31
+ */
32
+ @RunWith(Parameterized.class)
33
+ public class RequestFilterTest {
34
+
35
+ protected static final String EMPTY_PATH = "";
36
+ protected static final String CUSTOM_APP_PATH = "/my-custom/application/path";
37
+
38
+ private RequestFilter matcher;
39
+
40
+ private Map<String, String> matchResult;
41
+
42
+ protected String applicationPath;
43
+
44
+ @Parameterized.Parameters
45
+ public static Collection<String> data() {
46
+ return Arrays.asList(EMPTY_PATH, CUSTOM_APP_PATH);
47
+ }
48
+
49
+ public RequestFilterTest(String applicationPath) {
50
+ this.applicationPath = applicationPath;
51
+ }
52
+
53
+ @Test
54
+ public void shouldMatchMethod() {
55
+
56
+ // given
57
+ matcher = newMatcher("/foo/bar", "POST", "PUT");
58
+
59
+ // when
60
+ matchResult = matcher.match("GET", applicationPath + "/foo/bar");
61
+
62
+ // then
63
+ assertThat(matchResult).isNull();
64
+ }
65
+
66
+ @Test
67
+ public void shouldNotMatchUri() {
68
+
69
+ // given
70
+ matcher = newMatcher("/foo/bar", "GET");
71
+
72
+ // when
73
+ matchResult = matcher.match("GET", applicationPath + "/not-matching/");
74
+
75
+ // then
76
+ assertThat(matchResult).isNull();
77
+ }
78
+
79
+ @Test
80
+ public void shouldMatch() {
81
+
82
+ // given
83
+ matcher = newMatcher("/foo/bar", "GET");
84
+
85
+ // when
86
+ matchResult = matcher.match("GET", applicationPath + "/foo/bar");
87
+
88
+ // then
89
+ assertThat(matchResult).isNotNull();
90
+ }
91
+
92
+ @Test
93
+ public void shouldExtractNamedUriParts() {
94
+
95
+ // given
96
+ matcher = newMatcher("/{foo}/{bar}", "GET");
97
+
98
+ // when
99
+ matchResult = matcher.match("GET", applicationPath + "/foo/bar");
100
+
101
+ // then
102
+ assertThat(matchResult)
103
+ .isNotNull()
104
+ .containsEntry("foo", "foo")
105
+ .containsEntry("bar", "bar");
106
+ }
107
+
108
+ @Test
109
+ public void shouldExtractNamedMatchAllUriPart() {
110
+
111
+ // given
112
+ matcher = newMatcher("/{foo}/{bar:.*}", "GET");
113
+
114
+ // when
115
+ matchResult = matcher.match("GET", applicationPath + "/foo/bar/asdf/asd");
116
+
117
+ // then
118
+ assertThat(matchResult)
119
+ .isNotNull()
120
+ .containsEntry("bar", "bar/asdf/asd");
121
+ }
122
+
123
+ private RequestFilter newMatcher(String uri, String ... methods) {
124
+ return new RequestFilter(uri, applicationPath, methods);
125
+ }
126
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/filter/SecurityFilterRulesTest.java ADDED
@@ -0,0 +1,536 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.webapp.impl.security.filter;
18
+
19
+ import static org.assertj.core.api.Assertions.assertThat;
20
+
21
+ import java.io.FileInputStream;
22
+ import java.io.IOException;
23
+ import java.io.InputStream;
24
+ import java.util.Arrays;
25
+ import java.util.Collection;
26
+ import java.util.Collections;
27
+ import java.util.HashSet;
28
+ import java.util.List;
29
+
30
+ import org.camunda.bpm.cockpit.Cockpit;
31
+ import org.camunda.bpm.cockpit.impl.DefaultCockpitRuntimeDelegate;
32
+ import org.camunda.bpm.engine.ProcessEngine;
33
+ import org.camunda.bpm.engine.impl.util.IoUtil;
34
+ import org.camunda.bpm.webapp.impl.security.auth.Authentication;
35
+ import org.camunda.bpm.webapp.impl.security.auth.Authentications;
36
+ import org.camunda.bpm.webapp.impl.security.auth.UserAuthentication;
37
+ import org.camunda.bpm.webapp.impl.security.filter.util.FilterRules;
38
+ import org.junit.After;
39
+ import org.junit.Before;
40
+ import org.junit.Test;
41
+ import org.junit.runner.RunWith;
42
+ import org.junit.runners.Parameterized;
43
+ import org.mockito.Mockito;
44
+
45
+ /**
46
+ *
47
+ * @author nico.rehwaldt
48
+ */
49
+ @RunWith(Parameterized.class)
50
+ public class SecurityFilterRulesTest {
51
+
52
+ public static final String FILTER_RULES_FILE = "src/main/webapp/WEB-INF/securityFilterRules.json";
53
+
54
+ protected static final String EMPTY_PATH = "";
55
+ protected static final String CUSTOM_APP_PATH = "/my-custom/application/path";
56
+
57
+ public static List<SecurityFilterRule> FILTER_RULES;
58
+
59
+ public static Authentication NO_AUTHENTICATION = null;
60
+ public static Authentication LOGGED_IN_USER = new Authentication("user", "default");
61
+
62
+ public static final String TESTUSER_ID = "testuser";
63
+
64
+ protected String applicationPath;
65
+
66
+ @Parameterized.Parameters
67
+ public static Collection<String> data() {
68
+ return Arrays.asList(EMPTY_PATH, CUSTOM_APP_PATH);
69
+ }
70
+
71
+ public SecurityFilterRulesTest(String applicationPath) throws IOException {
72
+ this.applicationPath = applicationPath;
73
+ FILTER_RULES = loadFilterRules(applicationPath);
74
+ }
75
+
76
+ @Before
77
+ public void createEngine()
78
+ {
79
+ final ProcessEngine engine = Mockito.mock(ProcessEngine.class);
80
+
81
+ Cockpit.setCockpitRuntimeDelegate(new DefaultCockpitRuntimeDelegate() {
82
+
83
+ @Override
84
+ public ProcessEngine getProcessEngine(String processEngineName) {
85
+ if ("default".equals(processEngineName)) {
86
+ return engine;
87
+ }
88
+ else {
89
+ return null;
90
+ }
91
+ }
92
+ });
93
+ }
94
+
95
+ @After
96
+ public void after() {
97
+ Authentications.setCurrent(null);
98
+ Cockpit.setCockpitRuntimeDelegate(null);
99
+ }
100
+
101
+ @Test
102
+ public void shouldHaveRulesLoaded() throws Exception {
103
+ assertThat(FILTER_RULES).hasSize(1);
104
+ }
105
+
106
+
107
+ @Test
108
+ public void shouldPassPasswordPolicy() {
109
+ assertThat(isAuthorized("GET",
110
+ applicationPath + "/api/engine/engine/default/identity/password-policy")).isTrue();
111
+ assertThat(isAuthorized("POST",
112
+ applicationPath + "/api/engine/engine/default/identity/password-policy")).isTrue();
113
+ }
114
+
115
+ @Test
116
+ public void shouldPassStaticCockpitPluginResources_GET() throws Exception {
117
+ assertThat(isAuthorized("GET",
118
+ applicationPath + "/api/cockpit/plugin/some-plugin/static/foo.html")).isTrue();
119
+ assertThat(isAuthorized("GET",
120
+ applicationPath + "/api/cockpit/plugin/bar/static/foo.html")).isTrue();
121
+ }
122
+
123
+ @Test
124
+ public void shouldRejectEngineApi_GET() throws Exception {
125
+
126
+ authenticatedForEngine("otherEngine", new Runnable() {
127
+ @Override
128
+ public void run() {
129
+
130
+ Authorization authorization =
131
+ getAuthorization("POST", applicationPath + "/api/engine/engine/default/bar");
132
+
133
+ assertThat(authorization.isGranted()).isFalse();
134
+ assertThat(authorization.isAuthenticated()).isFalse();
135
+ }
136
+ });
137
+ }
138
+
139
+ @Test
140
+ public void shouldGrantEngineApi_GET() throws Exception {
141
+
142
+ authenticatedForEngine("default", new Runnable() {
143
+ @Override
144
+ public void run() {
145
+
146
+ Authorization authorization =
147
+ getAuthorization("POST", applicationPath + "/api/engine/engine/default/bar");
148
+
149
+ assertThat(authorization.isGranted()).isTrue();
150
+ assertThat(authorization.isAuthenticated()).isTrue();
151
+ }
152
+ });
153
+ }
154
+
155
+ @Test
156
+ public void shouldRejectCockpitPluginApi_GET() throws Exception {
157
+
158
+ authenticatedForEngine("otherEngine", new Runnable() {
159
+ @Override
160
+ public void run() {
161
+
162
+ Authorization authorization = getAuthorization("POST",
163
+ applicationPath + "/api/cockpit/plugin/" +
164
+ "reporting-process-count/default/process-instance-count");
165
+
166
+ assertThat(authorization.isGranted()).isFalse();
167
+ assertThat(authorization.isAuthenticated()).isFalse();
168
+ }
169
+ });
170
+ }
171
+
172
+ @Test
173
+ public void shouldPassCockpitPluginApi_GET_LOGGED_IN() throws Exception {
174
+ authenticatedForEngine("default", new Runnable() {
175
+ @Override
176
+ public void run() {
177
+
178
+ Authorization authorization =
179
+ getAuthorization("POST",
180
+ applicationPath + "/api/cockpit/plugin/" +
181
+ "reporting-process-count/default/process-instance-count");
182
+
183
+ assertThat(authorization.isGranted()).isTrue();
184
+ assertThat(authorization.isAuthenticated()).isTrue();
185
+ }
186
+ });
187
+ }
188
+
189
+ @Test
190
+ public void shouldPassCockpit_GET_LOGGED_OUT() throws Exception {
191
+
192
+ Authorization authorization =
193
+ getAuthorization("GET", applicationPath + "/app/cockpit/non-existing-engine/foo");
194
+
195
+ assertThat(authorization.isGranted()).isTrue();
196
+ assertThat(authorization.isAuthenticated()).isFalse();
197
+ }
198
+
199
+ @Test
200
+ public void shouldPassCockpit_GET_LOGGED_IN() throws Exception {
201
+
202
+ authenticatedForApp("default", "cockpit", new Runnable() {
203
+
204
+ @Override
205
+ public void run() {
206
+ Authorization authorization =
207
+ getAuthorization("GET", applicationPath + "/app/cockpit/default/");
208
+
209
+ assertThat(authorization.isGranted()).isTrue();
210
+ assertThat(authorization.isAuthenticated()).isTrue();
211
+ }
212
+ });
213
+ }
214
+
215
+ @Test
216
+ public void shouldPassCockpitNonExistingEngine_GET_LOGGED_IN() throws Exception {
217
+
218
+ authenticatedForApp("default", "cockpit", new Runnable() {
219
+
220
+ @Override
221
+ public void run() {
222
+ Authorization authorization =
223
+ getAuthorization("GET", applicationPath + "/app/cockpit/non-existing-engine/");
224
+
225
+ assertThat(authorization.isGranted()).isTrue();
226
+ assertThat(authorization.isAuthenticated()).isFalse();
227
+ }
228
+ });
229
+ }
230
+
231
+
232
+ @Test
233
+ public void shouldRejectTasklistApi_GET() throws Exception {
234
+
235
+ authenticatedForEngine("otherEngine", new Runnable() {
236
+ @Override
237
+ public void run() {
238
+
239
+ Authorization authorization =
240
+ getAuthorization("POST",
241
+ applicationPath + "/api/tasklist/plugin/example-plugin/default/example-resource");
242
+
243
+ assertThat(authorization.isGranted()).isFalse();
244
+ assertThat(authorization.isAuthenticated()).isFalse();
245
+ }
246
+ });
247
+ }
248
+
249
+ @Test
250
+ public void shouldPassTasklistApi_GET_LOGGED_IN() throws Exception {
251
+ authenticatedForEngine("default", new Runnable() {
252
+ @Override
253
+ public void run() {
254
+
255
+ Authorization authorization =
256
+ getAuthorization("POST",
257
+ applicationPath + "/api/tasklist/plugin/example-plugin/default/example-resource");
258
+
259
+ assertThat(authorization.isGranted()).isTrue();
260
+ assertThat(authorization.isAuthenticated()).isTrue();
261
+ }
262
+ });
263
+ }
264
+
265
+ @Test
266
+ public void shouldRejectTasklistApi_GET_LOGGED_OUT() throws Exception
267
+ {
268
+ Authorization authorization =
269
+ getAuthorization("POST",
270
+ applicationPath + "/api/tasklist/plugin/example-plugin/default/example-resource");
271
+
272
+ assertThat(authorization.isGranted()).isFalse();
273
+ assertThat(authorization.isAuthenticated()).isFalse();
274
+ }
275
+
276
+ @Test
277
+ public void shouldPassTasklistPluginResource_GET_LOGGED_IN() throws Exception {
278
+
279
+ authenticatedForEngine("default", new Runnable() {
280
+ @Override
281
+ public void run() {
282
+
283
+ Authorization authorization =
284
+ getAuthorization("GET",
285
+ applicationPath + "/api/tasklist/plugin/example-plugin/static/example-resource");
286
+
287
+ assertThat(authorization.isGranted()).isTrue();
288
+ assertThat(authorization.isAuthenticated()).isFalse();
289
+ }
290
+ });
291
+ }
292
+
293
+ @Test
294
+ public void shouldPassTasklistPluginResource_GET_LOGGED_OUT() throws Exception {
295
+
296
+ Authorization authorization =
297
+ getAuthorization("GET",
298
+ applicationPath + "/api/tasklist/plugin/example-plugin/static/example-resource");
299
+
300
+ assertThat(authorization.isGranted()).isTrue();
301
+ assertThat(authorization.isAuthenticated()).isFalse();
302
+ }
303
+
304
+
305
+ @Test
306
+ public void shouldPassTasklist_GET_LOGGED_OUT() throws Exception {
307
+
308
+ Authorization authorization =
309
+ getAuthorization("GET", applicationPath + "/app/tasklist/non-existing-engine");
310
+
311
+ assertThat(authorization.isGranted()).isTrue();
312
+ assertThat(authorization.isAuthenticated()).isFalse();
313
+ }
314
+
315
+ @Test
316
+ public void shouldPassTasklist_GET_LOGGED_IN() throws Exception {
317
+
318
+ authenticatedForApp("default", "tasklist", new Runnable() {
319
+
320
+ @Override
321
+ public void run() {
322
+ Authorization authorization =
323
+ getAuthorization("GET", applicationPath + "/app/tasklist/default/");
324
+
325
+ assertThat(authorization.isGranted()).isTrue();
326
+ assertThat(authorization.isAuthenticated()).isTrue();
327
+ }
328
+ });
329
+ }
330
+
331
+ @Test
332
+ public void shouldRejectAdminApi_GET_LOGGED_OUT() throws Exception {
333
+
334
+ Authorization authorization =
335
+ getAuthorization("GET", applicationPath + "/api/admin/auth/user/some-engine/");
336
+
337
+ assertThat(authorization.isGranted()).isFalse();
338
+ assertThat(authorization.isAuthenticated()).isFalse();
339
+
340
+ authorization =
341
+ getAuthorization("GET", applicationPath + "/api/admin/setup/some-engine/");
342
+
343
+ assertThat(authorization.isGranted()).isFalse();
344
+ assertThat(authorization.isAuthenticated()).isFalse();
345
+ }
346
+
347
+ @Test
348
+ public void shouldPassAdminApi_GET_LOGGED_IN() throws Exception {
349
+
350
+ authenticatedForApp("default", "admin", new Runnable() {
351
+
352
+ @Override
353
+ public void run() {
354
+ Authorization authorization =
355
+ getAuthorization("GET", applicationPath + "/api/admin/foo/");
356
+
357
+ assertThat(authorization.isGranted()).isTrue();
358
+ assertThat(authorization.isAuthenticated()).isFalse();
359
+ }
360
+ });
361
+ }
362
+
363
+ @Test
364
+ public void shouldPassAdminApi_AnonymousEndpoints_LOGGED_OUT() throws Exception {
365
+
366
+ Authorization authorization =
367
+ getAuthorization("GET", applicationPath + "/api/admin/auth/user/bar");
368
+
369
+ assertThat(authorization.isGranted()).isTrue();
370
+ assertThat(authorization.isAuthenticated()).isFalse();
371
+
372
+ authorization =
373
+ getAuthorization("POST", applicationPath + "/api/admin/auth/user/bar/logout");
374
+
375
+ assertThat(authorization.isGranted()).isTrue();
376
+ assertThat(authorization.isAuthenticated()).isFalse();
377
+
378
+ authorization =
379
+ getAuthorization("POST", applicationPath + "/api/admin/auth/user/bar/login/some-app");
380
+
381
+ assertThat(authorization.isGranted()).isTrue();
382
+ assertThat(authorization.isAuthenticated()).isFalse();
383
+
384
+ authorization =
385
+ getAuthorization("POST", applicationPath + "/api/admin/setup/some-engine/user/create");
386
+
387
+ assertThat(authorization.isGranted()).isTrue();
388
+ assertThat(authorization.isAuthenticated()).isFalse();
389
+ }
390
+
391
+
392
+ @Test
393
+ public void shouldRejectAdminApiPlugin_GET_LOGGED_OUT() throws Exception {
394
+
395
+ Authorization authorization =
396
+ getAuthorization("GET",
397
+ applicationPath + "/api/admin/plugin/adminPlugins/some-engine/endpoint");
398
+
399
+ assertThat(authorization.isGranted()).isFalse();
400
+ assertThat(authorization.isAuthenticated()).isFalse();
401
+ }
402
+
403
+ @Test
404
+ public void shouldPassAdminApiPlugin_GET_LOGGED_IN() throws Exception {
405
+
406
+ authenticatedForApp("default", "admin", new Runnable() {
407
+
408
+ @Override
409
+ public void run() {
410
+ Authorization authorization =
411
+ getAuthorization("GET",
412
+ applicationPath + "/api/admin/plugin/adminPlugins/some-engine");
413
+
414
+ assertThat(authorization.isGranted()).isTrue();
415
+ assertThat(authorization.isAuthenticated()).isFalse();
416
+ }
417
+ });
418
+ }
419
+
420
+ @Test
421
+ public void shouldPassAdmin_GET_LOGGED_OUT() throws Exception {
422
+
423
+ Authorization authorization =
424
+ getAuthorization("GET", applicationPath + "/app/admin/default");
425
+
426
+ assertThat(authorization.isGranted()).isTrue();
427
+ assertThat(authorization.isAuthenticated()).isFalse();
428
+ }
429
+
430
+ @Test
431
+ public void shouldPassAdmin_GET_LOGGED_IN() throws Exception {
432
+
433
+ authenticatedForApp("default", "admin", new Runnable() {
434
+
435
+ @Override
436
+ public void run() {
437
+ Authorization authorization =
438
+ getAuthorization("GET", applicationPath + "/app/admin/default/");
439
+
440
+ assertThat(authorization.isGranted()).isTrue();
441
+ assertThat(authorization.isAuthenticated()).isTrue();
442
+ }
443
+ });
444
+ }
445
+
446
+
447
+ @Test
448
+ public void shouldPassAdminResources_GET_LOGGED_OUT() throws Exception {
449
+
450
+ Authorization authorization =
451
+ getAuthorization("GET", applicationPath + "/app/admin/scripts");
452
+
453
+ assertThat(authorization.isGranted()).isTrue();
454
+ assertThat(authorization.isAuthenticated()).isFalse();
455
+ }
456
+
457
+ @Test
458
+ public void shouldPassAdminResources_GET_LOGGED_IN() throws Exception {
459
+
460
+ authenticatedForApp("default", "admin", new Runnable() {
461
+
462
+ @Override
463
+ public void run() {
464
+ Authorization authorization =
465
+ getAuthorization("GET", applicationPath + "/app/admin/scripts");
466
+
467
+ assertThat(authorization.isGranted()).isTrue();
468
+ assertThat(authorization.isAuthenticated()).isFalse();
469
+ }
470
+ });
471
+ }
472
+
473
+ @Test
474
+ public void shouldPassAdminLicenseCheck_GET_LOGGED_OUT() {
475
+
476
+ Authorization authorization =
477
+ getAuthorization("GET", applicationPath + "/api/admin/plugin/license/default/check-key");
478
+
479
+ assertThat(authorization.isGranted()).isTrue();
480
+ assertThat(authorization.isAuthenticated()).isFalse();
481
+ }
482
+
483
+ protected Authorization getAuthorization(String method, String uri) {
484
+ return FilterRules.authorize(method, uri, FILTER_RULES);
485
+ }
486
+
487
+ protected boolean isAuthorized(String method, String uri) {
488
+ return getAuthorization(method, uri).isGranted();
489
+ }
490
+
491
+ private static List<SecurityFilterRule> loadFilterRules(String appPath) throws IOException {
492
+ InputStream is = null;
493
+
494
+ try {
495
+ is = new FileInputStream(FILTER_RULES_FILE);
496
+ return FilterRules.load(is, appPath);
497
+ } finally {
498
+ IoUtil.closeSilently(is);
499
+ }
500
+ }
501
+
502
+ private void authenticatedForEngine(String engineName, Runnable codeBlock) {
503
+ UserAuthentication engineAuth = new UserAuthentication(LOGGED_IN_USER.getIdentityId(), engineName);
504
+
505
+ Authentications authentications = new Authentications();
506
+ authentications.addOrReplace(engineAuth);
507
+
508
+ Authentications.setCurrent(authentications);
509
+
510
+ try {
511
+ codeBlock.run();
512
+ } finally {
513
+ Authentications.clearCurrent();
514
+ }
515
+ }
516
+
517
+ private void authenticatedForApp(String engineName, String appName, Runnable codeBlock) {
518
+ HashSet<String> authorizedApps = new HashSet<>(Arrays.asList(appName));
519
+
520
+ UserAuthentication engineAuth = new UserAuthentication(LOGGED_IN_USER.getIdentityId(), engineName);
521
+ engineAuth.setGroupIds(Collections.<String> emptyList());
522
+ engineAuth.setTenantIds(Collections.<String> emptyList());
523
+ engineAuth.setAuthorizedApps(authorizedApps);
524
+
525
+ Authentications authentications = new Authentications();
526
+ authentications.addOrReplace(engineAuth);
527
+
528
+ Authentications.setCurrent(authentications);
529
+
530
+ try {
531
+ codeBlock.run();
532
+ } finally {
533
+ Authentications.clearCurrent();
534
+ }
535
+ }
536
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/filter/SessionCookieTest.java ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.webapp.impl.security.filter;
18
+
19
+ import static org.assertj.core.api.Assertions.assertThat;
20
+
21
+ import org.camunda.bpm.engine.ProcessEngineException;
22
+ import org.camunda.bpm.webapp.impl.util.HeaderRule;
23
+ import org.junit.Rule;
24
+ import org.junit.Test;
25
+
26
+ public class SessionCookieTest {
27
+
28
+ @Rule
29
+ public HeaderRule headerRule = new HeaderRule();
30
+
31
+ @Test
32
+ public void shouldConfigureDefault() {
33
+ // given
34
+ headerRule.startServer("web.xml", "session");
35
+
36
+ // when
37
+ headerRule.performRequest();
38
+
39
+ // then
40
+ assertThat(headerRule.getCookieHeader()).matches(headerRule.getSessionCookieRegex("camunda", "Lax", false));
41
+ }
42
+
43
+ @Test
44
+ public void shouldConfigureRootContextPath() {
45
+ // given
46
+ headerRule.startServer("web.xml", "session", "/");
47
+
48
+ // when
49
+ headerRule.performRequest();
50
+
51
+ // then
52
+ assertThat(headerRule.getCookieHeader()).matches(headerRule.getSessionCookieRegex(null, "Lax", false));
53
+ }
54
+
55
+ @Test
56
+ public void shouldConfigureSecureEnabled() {
57
+ // given
58
+ headerRule.startServer("secure_enabled_web.xml", "session");
59
+
60
+ // when
61
+ headerRule.performRequest();
62
+
63
+ // then
64
+ assertThat(headerRule.getCookieHeader()).matches(headerRule.getSessionCookieRegex("camunda", "Lax", true));
65
+ }
66
+
67
+ @Test
68
+ public void shouldConfigureSameSiteDisabled() {
69
+ // given
70
+ headerRule.startServer("same_site_disabled_web.xml", "session");
71
+
72
+ // when
73
+ headerRule.performRequest();
74
+
75
+ // then
76
+ assertThat(headerRule.getCookieHeader()).matches(headerRule.getSessionCookieRegex("camunda", null, false));
77
+ }
78
+
79
+ @Test
80
+ public void shouldConfigureSameSiteOptionStrict() {
81
+ // given
82
+ headerRule.startServer("same_site_option_strict_web.xml", "session");
83
+
84
+ // when
85
+ headerRule.performRequest();
86
+
87
+ // then
88
+ assertThat(headerRule.getCookieHeader()).matches(headerRule.getSessionCookieRegex("camunda", "Strict", false));
89
+ }
90
+
91
+ @Test
92
+ public void shouldConfigureSameSiteOptionLax() {
93
+ // given
94
+ headerRule.startServer("same_site_option_lax_web.xml", "session");
95
+
96
+ // when
97
+ headerRule.performRequest();
98
+
99
+ // then
100
+ assertThat(headerRule.getCookieHeader()).matches(headerRule.getSessionCookieRegex("camunda", "Lax", false));
101
+ }
102
+
103
+ @Test
104
+ public void shouldConfigureSameSiteCustomValue() {
105
+ // given
106
+ headerRule.startServer("same_site_custom_value_web.xml", "session");
107
+
108
+ // when
109
+ headerRule.performRequest();
110
+
111
+ // then
112
+ assertThat(headerRule.getCookieHeader()).matches(headerRule.getSessionCookieRegex("camunda", "aCustomValue", false));
113
+ }
114
+
115
+ @Test
116
+ public void shouldThrowExceptionWhenConfiguringBothSameSiteOptionAndValue() {
117
+ // given
118
+ headerRule.startServer("same_site_option_value_web.xml", "session");
119
+
120
+ // when
121
+ headerRule.performRequest();
122
+
123
+ Throwable expectedException = headerRule.getException();
124
+
125
+ // then
126
+ assertThat(expectedException)
127
+ .isInstanceOf(ProcessEngineException.class)
128
+ .hasMessage("Please either configure sameSiteCookieOption or sameSiteCookieValue.");
129
+ }
130
+
131
+ @Test
132
+ public void shouldThrowExceptionWhenConfiguringUnknownSameSiteOption() {
133
+ // given
134
+ headerRule.startServer("same_site_option_unknown_web.xml", "session");
135
+
136
+ // when
137
+ headerRule.performRequest();
138
+
139
+ Throwable expectedException = headerRule.getException();
140
+
141
+ // then
142
+ assertThat(expectedException)
143
+ .isInstanceOf(ProcessEngineException.class)
144
+ .hasMessage("For sameSiteCookieOption param, please configure one of the following options: [LAX, STRICT]");
145
+ }
146
+
147
+ @Test
148
+ public void shouldIgnoreCaseOfParamValues() {
149
+ // given
150
+ headerRule.startServer("ignore_case_web.xml", "session");
151
+
152
+ // when
153
+ headerRule.performRequest();
154
+
155
+ // then
156
+ assertThat(headerRule.getCookieHeader()).matches(headerRule.getSessionCookieRegex("camunda", "Lax", true));
157
+ }
158
+
159
+ @Test
160
+ public void shouldConfigureCookieName() {
161
+ // given
162
+ headerRule.startServer("changed_cookie_name_web.xml", "session");
163
+
164
+ // when
165
+ headerRule.performRequest();
166
+
167
+ // then
168
+ assertThat(headerRule.getCookieHeader()).matches(headerRule.getSessionCookieRegex("camunda", "MYCOOKIENAME", "Lax", false));
169
+ }
170
+
171
+ @Test
172
+ public void shouldConfigureWhenCookieIsSent() {
173
+ // given
174
+ headerRule.startServer("web.xml", "session");
175
+
176
+ // when
177
+ headerRule.performRequestWithHeader("Cookie", "JSESSIONID=aToken");
178
+
179
+ // then
180
+ assertThat(headerRule.getCookieHeader()).matches(headerRule.getSessionCookieRegex("camunda", "Lax", false));
181
+ }
182
+
183
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/filter/csrf/CsrfPreventionCookieTest.java ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.webapp.impl.security.filter.csrf;
18
+
19
+ import javax.servlet.http.HttpServletResponse;
20
+
21
+ import org.camunda.bpm.engine.ProcessEngineException;
22
+ import org.camunda.bpm.webapp.impl.util.HeaderRule;
23
+ import org.junit.Rule;
24
+ import org.junit.Test;
25
+
26
+ import static org.assertj.core.api.Assertions.assertThat;
27
+
28
+ public class CsrfPreventionCookieTest {
29
+
30
+ @Rule
31
+ public HeaderRule headerRule = new HeaderRule();
32
+
33
+ @Test
34
+ public void shouldConfigureDefault() {
35
+ // given
36
+ headerRule.startServer("web.xml", "csrf");
37
+
38
+ // when
39
+ headerRule.performRequest();
40
+
41
+ // then
42
+ assertThat(headerRule.getCookieHeader()).matches("XSRF-TOKEN=[A-Z0-9]{32};Path=/camunda;SameSite=Lax");
43
+ }
44
+
45
+ @Test
46
+ public void shouldConfigureRootContextPath() {
47
+ // given
48
+ headerRule.startServer("web.xml", "csrf", "/");
49
+
50
+ // when
51
+ headerRule.performRequest();
52
+
53
+ // then
54
+ assertThat(headerRule.getCookieHeader()).matches("XSRF-TOKEN=[A-Z0-9]{32};Path=/;SameSite=Lax");
55
+ }
56
+
57
+ @Test
58
+ public void shouldConfigureSecureEnabled() {
59
+ // given
60
+ headerRule.startServer("secure_enabled_web.xml", "csrf");
61
+
62
+ // when
63
+ headerRule.performRequest();
64
+
65
+ // then
66
+ assertThat(headerRule.getCookieHeader()).matches("XSRF-TOKEN=[A-Z0-9]{32};Path=/camunda;SameSite=Lax;Secure");
67
+ }
68
+
69
+ @Test
70
+ public void shouldConfigureSameSiteDisabled() {
71
+ // given
72
+ headerRule.startServer("same_site_disabled_web.xml", "csrf");
73
+
74
+ // when
75
+ headerRule.performRequest();
76
+
77
+ // then
78
+ assertThat(headerRule.getCookieHeader()).matches("XSRF-TOKEN=[A-Z0-9]{32};Path=/camunda");
79
+ }
80
+
81
+ @Test
82
+ public void shouldConfigureSameSiteOptionStrict() {
83
+ // given
84
+ headerRule.startServer("same_site_option_strict_web.xml", "csrf");
85
+
86
+ // when
87
+ headerRule.performRequest();
88
+
89
+ // then
90
+ assertThat(headerRule.getCookieHeader()).matches("XSRF-TOKEN=[A-Z0-9]{32};Path=/camunda;SameSite=Strict");
91
+ }
92
+
93
+ @Test
94
+ public void shouldConfigureSameSiteOptionLax() {
95
+ // given
96
+ headerRule.startServer("same_site_option_lax_web.xml", "csrf");
97
+
98
+ // when
99
+ headerRule.performRequest();
100
+
101
+ // then
102
+ assertThat(headerRule.getCookieHeader()).matches("XSRF-TOKEN=[A-Z0-9]{32};Path=/camunda;SameSite=Lax");
103
+ }
104
+
105
+ @Test
106
+ public void shouldConfigureSameSiteCustomValue() {
107
+ // given
108
+ headerRule.startServer("same_site_custom_value_web.xml", "csrf");
109
+
110
+ // when
111
+ headerRule.performRequest();
112
+
113
+ // then
114
+ assertThat(headerRule.getCookieHeader()).matches("XSRF-TOKEN=[A-Z0-9]{32};Path=/camunda;SameSite=aCustomValue");
115
+ }
116
+
117
+ @Test
118
+ public void shouldThrowExceptionWhenConfiguringBothSameSiteOptionAndValue() {
119
+ // given
120
+ headerRule.startServer("same_site_option_value_web.xml", "csrf");
121
+
122
+ // when
123
+ headerRule.performRequest();
124
+
125
+ Throwable expectedException = headerRule.getException();
126
+
127
+ // then
128
+ assertThat(expectedException)
129
+ .isInstanceOf(ProcessEngineException.class)
130
+ .hasMessage("Please either configure sameSiteCookieOption or sameSiteCookieValue.");
131
+ }
132
+
133
+ @Test
134
+ public void shouldThrowExceptionWhenConfiguringUnknownSameSiteOption() {
135
+ // given
136
+ headerRule.startServer("same_site_option_unknown_web.xml", "csrf");
137
+
138
+ // when
139
+ headerRule.performRequest();
140
+
141
+ Throwable expectedException = headerRule.getException();
142
+
143
+ // then
144
+ assertThat(expectedException)
145
+ .isInstanceOf(ProcessEngineException.class)
146
+ .hasMessage("For sameSiteCookieOption param, please configure one of the following options: [LAX, STRICT]");
147
+ }
148
+
149
+ @Test
150
+ public void shouldIgnoreCaseOfParamValues() {
151
+ // given
152
+ headerRule.startServer("ignore_case_web.xml", "csrf");
153
+
154
+ // when
155
+ headerRule.performRequest();
156
+
157
+ // then
158
+ assertThat(headerRule.getCookieHeader()).matches("XSRF-TOKEN=[A-Z0-9]{32};Path=/camunda;SameSite=Lax;Secure");
159
+ }
160
+
161
+ @Test
162
+ public void shouldConfigureWhenCookieIsSent() {
163
+ // given
164
+ headerRule.startServer("web.xml", "csrf");
165
+
166
+ // when
167
+ headerRule.performRequestWithHeader("Cookie", "XSRF-TOKEN=aToken");
168
+
169
+ // then
170
+ assertThat(headerRule.getCookieHeader()).matches("XSRF-TOKEN=[A-Z0-9]{32};Path=/camunda;SameSite=Lax");
171
+ }
172
+
173
+ @Test
174
+ public void shouldConfigureCookieName() {
175
+ // given
176
+ headerRule.startServer("changed_cookie_name_web.xml", "csrf");
177
+
178
+ // when
179
+ headerRule.performRequest();
180
+
181
+ // then
182
+ assertThat(headerRule.getCookieHeader())
183
+ .matches("myCookieName=[A-Z0-9]{32};Path=/camunda;SameSite=Lax");
184
+ }
185
+
186
+ @Test
187
+ public void shouldRejectModifyingRequest() {
188
+ // given
189
+ headerRule.startServer("web.xml", "csrf");
190
+
191
+ // when
192
+ headerRule.performPostRequest("/api/admin/auth/user/default/login/welcome");
193
+
194
+ // then
195
+ assertThat(headerRule.getResponseCode())
196
+ .isEqualTo(HttpServletResponse.SC_FORBIDDEN);
197
+ }
198
+
199
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/filter/csrf/CsrfPreventionFilterAppPathTest.java ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.webapp.impl.security.filter.csrf;
18
+
19
+ import org.camunda.bpm.webapp.impl.util.ServletContextUtil;
20
+ import org.junit.Test;
21
+ import org.springframework.mock.web.MockHttpServletRequest;
22
+ import org.springframework.mock.web.MockHttpServletResponse;
23
+ import org.springframework.mock.web.MockHttpSession;
24
+ import org.springframework.mock.web.MockServletContext;
25
+
26
+ import javax.servlet.ServletException;
27
+ import javax.ws.rs.core.Response;
28
+ import java.io.IOException;
29
+
30
+ import static org.assertj.core.api.Assertions.assertThat;
31
+ import static org.camunda.bpm.webapp.impl.security.filter.util.CsrfConstants.CSRF_PATH_FIELD_NAME;
32
+ import static org.camunda.bpm.webapp.impl.security.filter.util.CookieConstants.SET_COOKIE_HEADER_NAME;
33
+
34
+ public class CsrfPreventionFilterAppPathTest extends CsrfPreventionFilterTest {
35
+
36
+ protected static final String MY_APP_PATH = "/my/application/path";
37
+
38
+ protected MockServletContext mockServletContext;
39
+
40
+ public CsrfPreventionFilterAppPathTest(String nonModifyingRequestUrl,
41
+ String modifyingRequestUrl,
42
+ boolean isModifyingFetchRequest) {
43
+ super(nonModifyingRequestUrl, modifyingRequestUrl, isModifyingFetchRequest);
44
+ }
45
+
46
+ @Override
47
+ public void setup() throws Exception {
48
+ mockServletContext = new MockServletContext();
49
+ ServletContextUtil.setAppPath(MY_APP_PATH, mockServletContext);
50
+ super.setup();
51
+ }
52
+
53
+ @Test
54
+ public void shouldCheckNonModifyingRequestTokenGenerationWithRootContextPathAndEmptyAppPath()
55
+ throws IOException, ServletException {
56
+ // given
57
+ MockServletContext mockServletContext = new MockServletContext();
58
+ ServletContextUtil.setAppPath("", mockServletContext);
59
+
60
+ MockHttpSession session = new MockHttpSession();
61
+ MockHttpServletRequest nonModifyingRequest = new MockHttpServletRequest(mockServletContext);
62
+ nonModifyingRequest.setMethod("GET");
63
+ nonModifyingRequest.setSession(session);
64
+
65
+ // set root context path in request
66
+ nonModifyingRequest.setRequestURI("/" + nonModifyingRequestUrl);
67
+ nonModifyingRequest.setContextPath("");
68
+
69
+ // when
70
+ MockHttpServletResponse response = new MockHttpServletResponse();
71
+ applyFilter(nonModifyingRequest, response);
72
+
73
+ // then
74
+ String cookieToken = response.getHeader(SET_COOKIE_HEADER_NAME);
75
+ String headerToken = response.getHeader(CSRF_HEADER_NAME);
76
+
77
+ assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
78
+
79
+ assertThat(cookieToken).isNotNull().isNotEmpty();
80
+ assertThat(headerToken).isNotNull().isNotEmpty();
81
+
82
+ String regex = CSRF_COOKIE_NAME + "=[A-Z0-9]{32}" + CSRF_PATH_FIELD_NAME + "/;SameSite=Lax";
83
+ assertThat(cookieToken).matches(regex.replace(";", ";\\s*"));
84
+
85
+ assertThat(cookieToken).contains(headerToken);
86
+ }
87
+
88
+ @Override
89
+ protected String getCookiePath(String contextPath) {
90
+ return super.getCookiePath(contextPath + MY_APP_PATH);
91
+ }
92
+
93
+ @Override
94
+ protected MockHttpServletRequest getMockedRequest() {
95
+ return new MockHttpServletRequest(mockServletContext);
96
+ }
97
+
98
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/filter/csrf/CsrfPreventionFilterTest.java ADDED
@@ -0,0 +1,267 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.webapp.impl.security.filter.csrf;
18
+
19
+ import org.camunda.bpm.webapp.impl.security.filter.CsrfPreventionFilter;
20
+ import org.junit.Assert;
21
+ import org.junit.Before;
22
+ import org.junit.Test;
23
+ import org.junit.runner.RunWith;
24
+ import org.junit.runners.Parameterized;
25
+ import org.springframework.mock.web.MockFilterChain;
26
+ import org.springframework.mock.web.MockFilterConfig;
27
+ import org.springframework.mock.web.MockHttpServletRequest;
28
+ import org.springframework.mock.web.MockHttpServletResponse;
29
+ import org.springframework.mock.web.MockHttpSession;
30
+
31
+ import javax.servlet.Filter;
32
+ import javax.servlet.FilterChain;
33
+ import javax.servlet.ServletException;
34
+ import javax.servlet.http.Cookie;
35
+ import javax.servlet.http.HttpServletResponse;
36
+ import javax.ws.rs.core.Response;
37
+ import java.io.IOException;
38
+ import java.util.Arrays;
39
+ import java.util.Collection;
40
+
41
+ import static org.assertj.core.api.Assertions.assertThat;
42
+ import static org.camunda.bpm.webapp.impl.security.filter.util.CsrfConstants.CSRF_PATH_FIELD_NAME;
43
+ import static org.camunda.bpm.webapp.impl.security.filter.util.CookieConstants.SET_COOKIE_HEADER_NAME;
44
+
45
+ /**
46
+ * @author Nikola Koevski
47
+ */
48
+ @RunWith(Parameterized.class)
49
+ public class CsrfPreventionFilterTest {
50
+
51
+ protected static final String SERVICE_PATH = "/camunda";
52
+ protected static final String CSRF_COOKIE_NAME = "XSRF-TOKEN";
53
+ protected static final String CSRF_HEADER_NAME = "X-XSRF-TOKEN";
54
+ protected static final String CSRF_HEADER_REQUIRED = "Required";
55
+
56
+ protected Filter csrfPreventionFilter;
57
+
58
+ protected String nonModifyingRequestUrl;
59
+ protected String modifyingRequestUrl;
60
+
61
+ // flags a modifying request (POST/PUT/DELETE) as a non-modifying one
62
+ protected boolean isModifyingFetchRequest;
63
+
64
+ @Parameterized.Parameters
65
+ public static Collection<Object[]> getRequestUrls() {
66
+ return Arrays.asList(new Object[][]{
67
+ {"/app/cockpit/default/", "/api/admin/auth/user/default/login/cockpit", true},
68
+ {"/app/cockpit/engine1/", "/api/admin/auth/user/engine1/login/cockpit", true},
69
+
70
+ {"/app/cockpit/default/", "/api/engine/engine/default/history/task/count", false},
71
+ {"/app/cockpit/engine1/", "/api/engine/engine/engine1/history/task/count", false},
72
+
73
+ {"/app/tasklist/default/", "/api/admin/auth/user/default/login/tasklist", true},
74
+ {"/app/tasklist/engine1/", "/api/admin/auth/user/engine1/login/tasklist", true},
75
+
76
+ {"/app/tasklist/default/", "api/engine/engine/default/task/task-id/submit-form", false},
77
+ {"/app/tasklist/engine2/", "api/engine/engine/engine2/task/task-id/submit-form", false},
78
+
79
+ {"/app/admin/default/", "/api/admin/auth/user/default/login/admin", true},
80
+ {"/app/admin/engine1/", "/api/admin/auth/user/engine1/login/admin", true},
81
+
82
+ {"/app/admin/default/", "api/admin/setup/default/user/create", false},
83
+ {"/app/admin/engine3/", "api/admin/setup/engine3/user/create", false},
84
+
85
+ {"/app/welcome/default/", "/api/admin/auth/user/default/login/welcome", true},
86
+ {"/app/welcome/engine1/", "/api/admin/auth/user/engine1/login/welcome", true}
87
+ });
88
+ }
89
+
90
+ public CsrfPreventionFilterTest(String nonModifyingRequestUrl, String modifyingRequestUrl, boolean isModifyingFetchRequest) {
91
+ this.nonModifyingRequestUrl = nonModifyingRequestUrl;
92
+ this.modifyingRequestUrl = modifyingRequestUrl;
93
+ this.isModifyingFetchRequest = isModifyingFetchRequest;
94
+ }
95
+
96
+ @Before
97
+ public void setup() throws Exception {
98
+ setupFilter();
99
+ }
100
+
101
+ protected void setupFilter() throws ServletException {
102
+ MockFilterConfig config = new MockFilterConfig();
103
+ csrfPreventionFilter = new CsrfPreventionFilter();
104
+ csrfPreventionFilter.init(config);
105
+ }
106
+
107
+ protected void applyFilter(MockHttpServletRequest request, MockHttpServletResponse response) throws IOException, ServletException {
108
+ FilterChain filterChain = new MockFilterChain();
109
+ csrfPreventionFilter.doFilter(request, response, filterChain);
110
+ }
111
+
112
+ @Test
113
+ public void testNonModifyingRequestTokenGeneration() throws IOException, ServletException {
114
+ MockHttpServletResponse response = performNonModifyingRequest(nonModifyingRequestUrl, new MockHttpSession());
115
+
116
+ String cookieToken = (String) response.getHeader(SET_COOKIE_HEADER_NAME);
117
+ String headerToken = (String) response.getHeader(CSRF_HEADER_NAME);
118
+
119
+ Assert.assertNotNull(cookieToken);
120
+ Assert.assertNotNull(headerToken);
121
+
122
+ String regex = CSRF_COOKIE_NAME + "=[A-Z0-9]{32}" + CSRF_PATH_FIELD_NAME + getCookiePath(SERVICE_PATH) + ";SameSite=Lax";
123
+ assertThat(cookieToken).matches(regex.replace(";", ";\\s*"));
124
+
125
+ Assert.assertEquals("No HTTP Header Token!",false, headerToken.isEmpty());
126
+ assertThat(cookieToken).contains(headerToken);
127
+ }
128
+
129
+ @Test
130
+ public void testNonModifyingRequestTokenGenerationWithRootContextPath() throws IOException, ServletException {
131
+ // given
132
+ MockHttpSession session = new MockHttpSession();
133
+ MockHttpServletRequest nonModifyingRequest = getMockedRequest();
134
+ nonModifyingRequest.setMethod("GET");
135
+ nonModifyingRequest.setSession(session);
136
+
137
+ // set root context path in request
138
+ nonModifyingRequest.setRequestURI("/" + nonModifyingRequestUrl);
139
+ nonModifyingRequest.setContextPath("");
140
+
141
+ // when
142
+ MockHttpServletResponse response = new MockHttpServletResponse();
143
+ applyFilter(nonModifyingRequest, response);
144
+
145
+ // then
146
+ String cookieToken = (String) response.getHeader(SET_COOKIE_HEADER_NAME);
147
+ String headerToken = (String) response.getHeader(CSRF_HEADER_NAME);
148
+
149
+ Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
150
+
151
+ Assert.assertNotNull(cookieToken);
152
+ Assert.assertNotNull(headerToken);
153
+
154
+ String regex = CSRF_COOKIE_NAME + "=[A-Z0-9]{32}" + CSRF_PATH_FIELD_NAME + getCookiePath("") + ";SameSite=Lax";
155
+ assertThat(cookieToken).matches(regex.replace(";", ";\\s*"));
156
+
157
+ Assert.assertEquals("No HTTP Header Token!",false, headerToken.isEmpty());
158
+ assertThat(cookieToken).contains(headerToken);
159
+ }
160
+
161
+ @Test
162
+ public void testConsecutiveNonModifyingRequestTokens() throws IOException, ServletException {
163
+ MockHttpSession session = new MockHttpSession();
164
+
165
+ // first non-modifying request
166
+ MockHttpServletResponse firstResponse = performNonModifyingRequest(nonModifyingRequestUrl, session);
167
+ // second non-modifying request
168
+ MockHttpServletResponse secondResponse = performNonModifyingRequest(nonModifyingRequestUrl, session);
169
+
170
+ String headerToken1 = (String) firstResponse.getHeader(CSRF_HEADER_NAME);
171
+ String headerToken2 = (String) secondResponse.getHeader(CSRF_HEADER_NAME);
172
+
173
+ Assert.assertNotNull(headerToken1);
174
+ Assert.assertNull(headerToken2);
175
+ }
176
+
177
+ @Test
178
+ public void testModifyingRequestTokenValidation() throws IOException, ServletException {
179
+ MockHttpSession session = new MockHttpSession();
180
+
181
+ // first a non-modifying request to obtain a token
182
+ MockHttpServletResponse nonModifyingResponse = performNonModifyingRequest(nonModifyingRequestUrl, session);
183
+
184
+ if (!isModifyingFetchRequest) {
185
+ String token = (String) nonModifyingResponse.getHeader(CSRF_HEADER_NAME);
186
+ HttpServletResponse modifyingResponse = performModifyingRequest(token, session);
187
+ Assert.assertEquals(Response.Status.OK.getStatusCode(), modifyingResponse.getStatus());
188
+ }
189
+ }
190
+
191
+ @Test
192
+ public void testModifyingRequestInvalidToken() throws IOException, ServletException {
193
+ MockHttpSession session = new MockHttpSession();
194
+ performNonModifyingRequest(nonModifyingRequestUrl, session);
195
+
196
+ if (!isModifyingFetchRequest) {
197
+ // invalid header token
198
+ MockHttpServletResponse response = performModifyingRequest("invalid header token", session);
199
+ Assert.assertEquals(Response.Status.FORBIDDEN.getStatusCode(), response.getStatus());
200
+ Assert.assertEquals("CSRFPreventionFilter: Invalid HTTP Header Token.", response.getErrorMessage());
201
+
202
+ // no token in header
203
+ MockHttpServletResponse response2 = new MockHttpServletResponse();
204
+ MockHttpServletRequest modifyingRequest = getMockedRequest();
205
+ modifyingRequest.setMethod("POST");
206
+ modifyingRequest.setSession(session);
207
+ modifyingRequest.setRequestURI(SERVICE_PATH + modifyingRequestUrl);
208
+ modifyingRequest.setContextPath(SERVICE_PATH);
209
+
210
+ applyFilter(modifyingRequest, response2);
211
+ Assert.assertEquals(CSRF_HEADER_REQUIRED, response2.getHeader(CSRF_HEADER_NAME));
212
+ Assert.assertEquals(Response.Status.FORBIDDEN.getStatusCode(), response2.getStatus());
213
+ Assert.assertEquals("CSRFPreventionFilter: Token provided via HTTP Header is absent/empty.", response2.getErrorMessage());
214
+ Assert.assertNotEquals(modifyingRequest.getSession().getId(), session.getId());
215
+ }
216
+ }
217
+
218
+ protected MockHttpServletResponse performNonModifyingRequest(String requestUrl, MockHttpSession session) throws IOException, ServletException {
219
+ MockHttpServletResponse response = new MockHttpServletResponse();
220
+
221
+ MockHttpServletRequest nonModifyingRequest = getMockedRequest();
222
+ nonModifyingRequest.setMethod("GET");
223
+ nonModifyingRequest.setSession(session);
224
+ nonModifyingRequest.setRequestURI(SERVICE_PATH + requestUrl);
225
+ nonModifyingRequest.setContextPath(SERVICE_PATH);
226
+
227
+ applyFilter(nonModifyingRequest, response);
228
+
229
+ Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
230
+
231
+ return response;
232
+ }
233
+
234
+ protected MockHttpServletResponse performModifyingRequest(String token, MockHttpSession session) throws IOException, ServletException {
235
+ MockHttpServletResponse response = new MockHttpServletResponse();
236
+
237
+ MockHttpServletRequest modifyingRequest = getMockedRequest();
238
+
239
+ modifyingRequest.setMethod("POST");
240
+ modifyingRequest.setSession(session);
241
+ modifyingRequest.setRequestURI(SERVICE_PATH + modifyingRequestUrl);
242
+ modifyingRequest.setContextPath(SERVICE_PATH);
243
+
244
+ modifyingRequest.addHeader(CSRF_HEADER_NAME, token);
245
+ Cookie[] cookies = {new Cookie(CSRF_COOKIE_NAME, token)};
246
+ modifyingRequest.setCookies(cookies);
247
+
248
+ applyFilter(modifyingRequest, response);
249
+
250
+ return response;
251
+ }
252
+
253
+ protected MockHttpServletRequest getMockedRequest() {
254
+ return new MockHttpServletRequest();
255
+ }
256
+
257
+ protected String getCookiePath(String contextPath) {
258
+ if (contextPath.isEmpty()) {
259
+ return "/";
260
+
261
+ } else {
262
+ return contextPath;
263
+
264
+ }
265
+ }
266
+
267
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/filter/headersec/ContentSecurityPolicyTest.java ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.webapp.impl.security.filter.headersec;
18
+
19
+ import org.camunda.bpm.webapp.impl.util.HeaderRule;
20
+ import org.junit.Rule;
21
+ import org.junit.Test;
22
+
23
+ import static org.assertj.core.api.Assertions.assertThat;
24
+ import static org.camunda.bpm.webapp.impl.security.filter.headersec.provider.impl.ContentSecurityPolicyProvider.HEADER_DEFAULT_VALUE;
25
+ import static org.camunda.bpm.webapp.impl.security.filter.headersec.provider.impl.ContentSecurityPolicyProvider.HEADER_NAME;
26
+ import static org.camunda.bpm.webapp.impl.security.filter.headersec.provider.impl.ContentSecurityPolicyProvider.HEADER_NONCE_PLACEHOLDER;
27
+
28
+ public class ContentSecurityPolicyTest {
29
+
30
+ @Rule
31
+ public HeaderRule headerRule = new HeaderRule();
32
+
33
+ @Test
34
+ public void shouldConfigureEnabledByDefault() {
35
+ // given
36
+ headerRule.startServer("web.xml", "headersec");
37
+
38
+ // when
39
+ headerRule.performRequest();
40
+
41
+ // then
42
+ String expectedHeaderPattern = HEADER_DEFAULT_VALUE.replace(HEADER_NONCE_PLACEHOLDER, "'nonce-([-_a-zA-Z\\d]*)'");
43
+ assertThat(headerRule.getHeader(HEADER_NAME)).matches(expectedHeaderPattern);
44
+ }
45
+
46
+ @Test
47
+ public void shouldConfigureDisabled() {
48
+ // given
49
+ headerRule.startServer("csp/disabled_web.xml", "headersec");
50
+
51
+ // when
52
+ headerRule.performRequest();
53
+
54
+ // then
55
+ assertThat(headerRule.headerExists(HEADER_NAME)).isFalse();
56
+ }
57
+
58
+ @Test
59
+ public void shouldConfigureDisabledIgnoreCase() {
60
+ // given
61
+ headerRule.startServer("csp/disabled_ignore_case_web.xml", "headersec");
62
+
63
+ // when
64
+ headerRule.performRequest();
65
+
66
+ // then
67
+ assertThat(headerRule.headerExists(HEADER_NAME)).isFalse();
68
+ }
69
+
70
+ @Test
71
+ public void shouldConfigureCustomValue() {
72
+ // given
73
+ headerRule.startServer("csp/custom_value_web.xml", "headersec");
74
+
75
+ // when
76
+ headerRule.performRequest();
77
+
78
+ // then
79
+ assertThat(headerRule.getHeader(HEADER_NAME))
80
+ .isEqualTo("base-uri 'self'; default-src 'self' 'unsafe-inline'; img-src 'self' data:; block-all-mixed-content");
81
+ }
82
+
83
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/filter/headersec/ContentTypeOptionsTest.java ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.webapp.impl.security.filter.headersec;
18
+
19
+ import org.camunda.bpm.webapp.impl.util.HeaderRule;
20
+ import org.junit.Rule;
21
+ import org.junit.Test;
22
+
23
+ import static org.hamcrest.core.Is.is;
24
+ import static org.junit.Assert.assertThat;
25
+
26
+ public class ContentTypeOptionsTest {
27
+
28
+ public static final String HEADER_NAME = "X-Content-Type-Options";
29
+ public static final String HEADER_DEFAULT_VALUE = "nosniff";
30
+
31
+ @Rule
32
+ public HeaderRule headerRule = new HeaderRule();
33
+
34
+ @Test
35
+ public void shouldConfigureEnabledByDefault() {
36
+ // given
37
+ headerRule.startServer("web.xml", "headersec");
38
+
39
+ // when
40
+ headerRule.performRequest();
41
+
42
+ // then
43
+ assertThat(headerRule.getHeader(HEADER_NAME), is(HEADER_DEFAULT_VALUE));
44
+ }
45
+
46
+ @Test
47
+ public void shouldConfigureDisabled() {
48
+ // given
49
+ headerRule.startServer("cto/disabled_web.xml", "headersec");
50
+
51
+ // when
52
+ headerRule.performRequest();
53
+
54
+ // then
55
+ assertThat(headerRule.headerExists(HEADER_NAME), is(false));
56
+ }
57
+
58
+ @Test
59
+ public void shouldConfigureDisabledIgnoreCase() {
60
+ // given
61
+ headerRule.startServer("cto/disabled_ignore_case_web.xml", "headersec");
62
+
63
+ // when
64
+ headerRule.performRequest();
65
+
66
+ // then
67
+ assertThat(headerRule.headerExists(HEADER_NAME), is(false));
68
+ }
69
+
70
+ @Test
71
+ public void shouldConfigureCustomValue() {
72
+ // given
73
+ headerRule.startServer("cto/custom_value_web.xml", "headersec");
74
+
75
+ // when
76
+ headerRule.performRequest();
77
+
78
+ // then
79
+ assertThat(headerRule.getHeader(HEADER_NAME), is("aCustomValue"));
80
+ }
81
+
82
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/filter/headersec/StrictTransportSecurityTest.java ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.webapp.impl.security.filter.headersec;
18
+
19
+ import org.camunda.bpm.engine.ProcessEngineException;
20
+ import org.camunda.bpm.webapp.impl.util.HeaderRule;
21
+ import org.junit.Rule;
22
+ import org.junit.Test;
23
+
24
+ import static org.assertj.core.api.Assertions.assertThat;
25
+ import static org.camunda.bpm.webapp.impl.security.filter.headersec.provider.impl.StrictTransportSecurityProvider.HEADER_NAME;
26
+
27
+ public class StrictTransportSecurityTest {
28
+
29
+ @Rule
30
+ public HeaderRule headerRule = new HeaderRule();
31
+
32
+ @Test
33
+ public void shouldConfigureDisabledByDefault() {
34
+ // given
35
+ headerRule.startServer("web.xml", "headersec");
36
+
37
+ // when
38
+ headerRule.performRequest();
39
+
40
+ // then
41
+ assertThat(headerRule.getHeader(HEADER_NAME)).isNull();
42
+ }
43
+
44
+ @Test
45
+ public void shouldConfigureEnabled() {
46
+ // given
47
+ headerRule.startServer("hsts/enabled_web.xml", "headersec");
48
+
49
+ // when
50
+ headerRule.performRequest();
51
+
52
+ // then
53
+ assertThat(headerRule.headerExists(HEADER_NAME)).isTrue();
54
+ }
55
+
56
+ @Test
57
+ public void shouldConfigureEnabledIgnoreCase() {
58
+ // given
59
+ headerRule.startServer("hsts/enabled_ignore_case_web.xml", "headersec");
60
+
61
+ // when
62
+ headerRule.performRequest();
63
+
64
+ // then
65
+ assertThat(headerRule.headerExists(HEADER_NAME)).isTrue();
66
+ }
67
+
68
+ @Test
69
+ public void shouldConfigureCustomValue() {
70
+ // given
71
+ headerRule.startServer("hsts/custom_value_web.xml", "headersec");
72
+
73
+ // when
74
+ headerRule.performRequest();
75
+
76
+ // then
77
+ assertThat(headerRule.getHeader(HEADER_NAME)).isEqualTo("aCustomValue");
78
+ }
79
+
80
+ @Test
81
+ public void shouldThrowExceptionWhenConfiguringCustomValueAndMaxAge() {
82
+ // given
83
+ headerRule.startServer("hsts/max_age_and_value_web.xml", "headersec");
84
+
85
+ // when
86
+ headerRule.performRequest();
87
+
88
+ Throwable expectedException = headerRule.getException();
89
+
90
+ // then
91
+ assertThat(expectedException)
92
+ .isInstanceOf(ProcessEngineException.class)
93
+ .hasMessage("StrictTransportSecurityProvider: cannot set hstsValue " +
94
+ "in conjunction with hstsMaxAge or hstsIncludeSubdomainsDisabled.");
95
+ }
96
+
97
+ @Test
98
+ public void shouldConfigureIncludeSubdomains() {
99
+ // given
100
+ headerRule.startServer("hsts/include_subdomains_web.xml", "headersec");
101
+
102
+ // when
103
+ headerRule.performRequest();
104
+
105
+ // then
106
+ assertThat(headerRule.getHeader(HEADER_NAME)).isEqualTo("max-age=31536000; includeSubDomains");
107
+ }
108
+
109
+ @Test
110
+ public void shouldConfigureIncludeSubdomainsAndMaxAge() {
111
+ // given
112
+ headerRule.startServer("hsts/include_subdomains_max_age_web.xml", "headersec");
113
+
114
+ // when
115
+ headerRule.performRequest();
116
+
117
+ // then
118
+ assertThat(headerRule.getHeader(HEADER_NAME)).isEqualTo("max-age=47; includeSubDomains");
119
+ }
120
+
121
+ @Test
122
+ public void shouldConfigureMaxAge() {
123
+ // given
124
+ headerRule.startServer("hsts/max_age_web.xml", "headersec");
125
+
126
+ // when
127
+ headerRule.performRequest();
128
+
129
+ // then
130
+ assertThat(headerRule.getHeader(HEADER_NAME)).isEqualTo("max-age=47");
131
+ }
132
+
133
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/security/filter/headersec/XssProtectionTest.java ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.webapp.impl.security.filter.headersec;
18
+
19
+ import org.camunda.bpm.engine.ProcessEngineException;
20
+ import org.camunda.bpm.webapp.impl.util.HeaderRule;
21
+ import org.junit.Rule;
22
+ import org.junit.Test;
23
+
24
+ import static org.camunda.bpm.webapp.impl.security.filter.headersec.provider.impl.XssProtectionOption.BLOCK;
25
+ import static org.camunda.bpm.webapp.impl.security.filter.headersec.provider.impl.XssProtectionOption.SANITIZE;
26
+ import static org.camunda.bpm.webapp.impl.security.filter.headersec.provider.impl.XssProtectionProvider.HEADER_NAME;
27
+ import static org.hamcrest.core.Is.is;
28
+ import static org.hamcrest.core.IsInstanceOf.instanceOf;
29
+ import static org.junit.Assert.assertThat;
30
+
31
+ /**
32
+ * @author Tassilo Weidner
33
+ */
34
+ public class XssProtectionTest {
35
+
36
+ @Rule
37
+ public HeaderRule headerRule = new HeaderRule();
38
+
39
+ @Test
40
+ public void shouldConfigureEnabledByDefault() {
41
+ // given
42
+ headerRule.startServer("web.xml", "headersec");
43
+
44
+ // when
45
+ headerRule.performRequest();
46
+
47
+ // then
48
+ assertThat(headerRule.getHeader(HEADER_NAME), is(BLOCK.getHeaderValue()));
49
+ }
50
+
51
+ @Test
52
+ public void shouldConfigureDisabled() {
53
+ // given
54
+ headerRule.startServer("xss/disabled_web.xml", "headersec");
55
+
56
+ // when
57
+ headerRule.performRequest();
58
+
59
+ // then
60
+ assertThat(headerRule.headerExists(HEADER_NAME), is(false));
61
+ }
62
+
63
+ @Test
64
+ public void shouldConfigureDisabledIgnoreCase() {
65
+ // given
66
+ headerRule.startServer("xss/disabled_ignore_case_web.xml", "headersec");
67
+
68
+ // when
69
+ headerRule.performRequest();
70
+
71
+ // then
72
+ assertThat(headerRule.headerExists(HEADER_NAME), is(false));
73
+ }
74
+
75
+ @Test
76
+ public void shouldConfigureCustomValue() {
77
+ // given
78
+ headerRule.startServer("xss/custom_value_web.xml", "headersec");
79
+
80
+ // when
81
+ headerRule.performRequest();
82
+
83
+ // then
84
+ assertThat(headerRule.getHeader(HEADER_NAME), is("aCustomValue"));
85
+ }
86
+
87
+ @Test
88
+ public void shouldConfigureOptionSanitize() {
89
+ // given
90
+ headerRule.startServer("xss/option_sanitize_web.xml", "headersec");
91
+
92
+ // when
93
+ headerRule.performRequest();
94
+
95
+ // then
96
+ assertThat(headerRule.getHeader(HEADER_NAME), is(SANITIZE.getHeaderValue()));
97
+ }
98
+
99
+ @Test
100
+ public void shouldConfigureOptionSanitizeIgnoreCase() {
101
+ // given
102
+ headerRule.startServer("xss/option_sanitize_ignore_case_web.xml", "headersec");
103
+
104
+ // when
105
+ headerRule.performRequest();
106
+
107
+ // then
108
+ assertThat(headerRule.getHeader(HEADER_NAME), is(SANITIZE.getHeaderValue()));
109
+ }
110
+
111
+ @Test
112
+ public void shouldConfigureOptionBlock() {
113
+ // given
114
+ headerRule.startServer("xss/option_block_web.xml", "headersec");
115
+
116
+ // when
117
+ headerRule.performRequest();
118
+
119
+ // then
120
+ assertThat(headerRule.getHeader(HEADER_NAME), is(BLOCK.getHeaderValue()));
121
+ }
122
+
123
+ @Test
124
+ public void shouldThrowExceptionOnSetBothParamsOptionAndValue() {
125
+ // given
126
+ headerRule.startServer("xss/option_and_value_web.xml", "headersec");
127
+
128
+ // when
129
+ headerRule.performRequest();
130
+
131
+ Throwable expectedException = headerRule.getException();
132
+
133
+ // then
134
+ assertThat(expectedException, instanceOf(ProcessEngineException.class));
135
+ assertThat(expectedException.getMessage(), is("XssProtectionProvider: cannot set both xssProtectionValue and xssProtectionOption."));
136
+ }
137
+
138
+ @Test
139
+ public void shouldThrowExceptionOnNonExistingOption() {
140
+ // given
141
+ headerRule.startServer("xss/option_non_existing_web.xml", "headersec");
142
+
143
+ Throwable expectedException = headerRule.getException();
144
+
145
+ // then
146
+ assertThat(expectedException, instanceOf(ProcessEngineException.class));
147
+ assertThat(expectedException.getMessage(), is("XssProtectionProvider: cannot set non-existing option foo for xssProtectionOption."));
148
+ }
149
+
150
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/impl/util/HeaderRule.java ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.webapp.impl.util;
18
+
19
+ import java.io.IOException;
20
+ import java.net.BindException;
21
+ import java.net.HttpURLConnection;
22
+ import java.net.ProtocolException;
23
+ import java.net.URL;
24
+ import org.eclipse.jetty.server.Server;
25
+ import org.eclipse.jetty.webapp.WebAppContext;
26
+ import org.junit.rules.ExternalResource;
27
+
28
+ /**
29
+ * @author Tassilo Weidner
30
+ */
31
+ public class HeaderRule extends ExternalResource {
32
+
33
+ protected static final int SERVER_PORT = 8085;
34
+ protected static final int RETRIES = 3;
35
+
36
+ protected Server server = new Server(SERVER_PORT);
37
+ protected WebAppContext webAppContext = new WebAppContext();
38
+ protected HttpURLConnection connection = null;
39
+
40
+ @Override
41
+ protected void before() {
42
+ try {
43
+ server.stop();
44
+ } catch (Exception e) {
45
+ throw new RuntimeException(e);
46
+ }
47
+ }
48
+
49
+ @Override
50
+ protected void after() {
51
+ try {
52
+ server.stop();
53
+ } catch (Exception e) {
54
+ throw new RuntimeException(e);
55
+ }
56
+ }
57
+
58
+ public void startServer(String webDescriptor, String scope) {
59
+ startServer(webDescriptor, scope, "/camunda");
60
+ }
61
+
62
+ public void startServer(String webDescriptor, String scope, String contextPath) {
63
+ startServer(webDescriptor, scope, contextPath, RETRIES);
64
+ }
65
+
66
+ protected void startServer(String webDescriptor, String scope, String contextPath, int startUpRetries) {
67
+ webAppContext.setContextPath(contextPath);
68
+ webAppContext.setResourceBase("/");
69
+ webAppContext.setDescriptor("src/test/resources/WEB-INF/" + scope + "/" + webDescriptor);
70
+
71
+ server.setHandler(webAppContext);
72
+
73
+ try {
74
+ server.start();
75
+ } catch (Exception e) {
76
+ if (e.getCause() instanceof BindException && startUpRetries > 0) {
77
+ try {
78
+ Thread.sleep(500L);
79
+ } catch (Exception ex) {
80
+ }
81
+ startServer(webDescriptor, scope, contextPath, --startUpRetries);
82
+ } else {
83
+ throw new RuntimeException(e);
84
+ }
85
+ }
86
+ }
87
+
88
+ public void performRequest() {
89
+ performRequestWithHeader(null, null, "", null);
90
+ }
91
+
92
+ public void performPostRequest(String path) {
93
+ performRequestWithHeader(null, null, path, "POST");
94
+ }
95
+
96
+ public void performRequestWithHeader(String name, String value) {
97
+ performRequestWithHeader(name, value, "", null);
98
+ }
99
+
100
+ public void performRequestWithHeader(String name, String value, String path, String method) {
101
+ try {
102
+ connection =
103
+ (HttpURLConnection) new URL("http://localhost:" + SERVER_PORT + "/camunda" + path)
104
+ .openConnection();
105
+ } catch (IOException e) {
106
+ throw new RuntimeException(e);
107
+ }
108
+
109
+ if ("POST".equals(method)) {
110
+ try {
111
+ connection.setRequestMethod("POST");
112
+ } catch (ProtocolException e) {
113
+ throw new RuntimeException(e);
114
+ }
115
+ }
116
+
117
+ if (name != null && value != null) {
118
+ connection.setRequestProperty(name, value);
119
+ }
120
+
121
+ try {
122
+ connection.connect();
123
+ } catch (IOException e) {
124
+ throw new RuntimeException(e);
125
+ }
126
+ }
127
+
128
+ public String getHeader(String headerName) {
129
+ return connection.getHeaderField(headerName);
130
+ }
131
+
132
+ public String getCookieHeader() {
133
+ return connection.getHeaderField("Set-Cookie");
134
+ }
135
+
136
+ public Throwable getException() {
137
+ return webAppContext.getUnavailableException();
138
+ }
139
+
140
+ public boolean headerExists(String name) {
141
+ for (String key : connection.getHeaderFields().keySet()) {
142
+ if (name.equals(key)) {
143
+ return true;
144
+ }
145
+ }
146
+
147
+ return false;
148
+ }
149
+
150
+ public String getResponseBody() {
151
+ try {
152
+ return connection.getResponseMessage();
153
+ } catch (IOException e) {
154
+ throw new RuntimeException(e);
155
+ }
156
+ }
157
+
158
+ public int getResponseCode() {
159
+ try {
160
+ return connection.getResponseCode();
161
+ } catch (IOException e) {
162
+ throw new RuntimeException(e);
163
+ }
164
+ }
165
+
166
+ public String getSessionCookieRegex(String path, String sameSite, boolean secure) {
167
+ return getSessionCookieRegex(path, "JSESSIONID", sameSite, secure);
168
+ }
169
+
170
+ public String getSessionCookieRegex(String path, String cookieName, String sameSite, boolean secure) {
171
+ StringBuilder regex = new StringBuilder(cookieName + "=.*;\\W*Path=/");
172
+ if (path != null) {
173
+ regex.append(path);
174
+ }
175
+ if (sameSite != null) {
176
+ regex.append(";\\W*SameSite=").append(sameSite);
177
+ }
178
+ if (secure) {
179
+ regex.append(";\\W*Secure");
180
+ }
181
+ return regex.toString();
182
+ }
183
+
184
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/java/org/camunda/bpm/webapp/plugin/resource/AbstractAppPluginRootResourceTest.java ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3
+ * under one or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information regarding copyright
5
+ * ownership. Camunda licenses this file to you under the Apache License,
6
+ * Version 2.0; you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org.camunda.bpm.webapp.plugin.resource;
18
+
19
+ import org.camunda.bpm.engine.rest.exception.RestException;
20
+ import org.camunda.bpm.webapp.AppRuntimeDelegate;
21
+ import org.camunda.bpm.webapp.plugin.AppPluginRegistry;
22
+ import org.camunda.bpm.webapp.plugin.spi.AppPlugin;
23
+ import org.junit.Before;
24
+ import org.junit.Test;
25
+ import org.junit.runner.RunWith;
26
+ import org.junit.runners.Parameterized;
27
+ import org.junit.runners.Parameterized.Parameters;
28
+ import org.mockito.Mockito;
29
+
30
+ import javax.servlet.ServletContext;
31
+ import javax.servlet.ServletException;
32
+ import javax.ws.rs.core.HttpHeaders;
33
+ import javax.ws.rs.core.Response;
34
+ import javax.ws.rs.core.StreamingOutput;
35
+ import java.io.ByteArrayInputStream;
36
+ import java.io.ByteArrayOutputStream;
37
+ import java.io.IOException;
38
+ import java.util.Arrays;
39
+ import java.util.Collection;
40
+
41
+ import static org.assertj.core.api.Assertions.assertThat;
42
+ import static org.assertj.core.api.Assertions.fail;
43
+ import static org.camunda.bpm.webapp.plugin.resource.AbstractAppPluginRootResource.MIME_TYPE_TEXT_CSS;
44
+ import static org.camunda.bpm.webapp.plugin.resource.AbstractAppPluginRootResource.MIME_TYPE_TEXT_JAVASCRIPT;
45
+
46
+ @RunWith(Parameterized.class)
47
+ public class AbstractAppPluginRootResourceTest {
48
+
49
+ public static final String PLUGIN_NAME = "test-plugin";
50
+ public static final String ASSET_DIR = "plugin/asset-dir";
51
+ public static final String ASSET_CONTENT = "content";
52
+
53
+ private final String assetName;
54
+ private final String assetMediaType;
55
+ private final boolean assetAllowed;
56
+
57
+ private AppRuntimeDelegate<AppPlugin> runtimeDelegate;
58
+ private AppPluginRegistry<AppPlugin> pluginRegistry;
59
+ private AbstractAppPluginRootResource<AppPlugin> pluginRootResource;
60
+ private ServletContext mockServletContext;
61
+
62
+ public AbstractAppPluginRootResourceTest(String assetName, String assetMediaType, boolean assetAllowed) {
63
+ this.assetName = assetName;
64
+ this.assetMediaType = assetMediaType;
65
+ this.assetAllowed = assetAllowed;
66
+ }
67
+
68
+ @Parameters
69
+ public static Collection<Object[]> getAssets() {
70
+ return Arrays.asList(new Object[][]{
71
+ {"app/plugin.js", MIME_TYPE_TEXT_JAVASCRIPT, true},
72
+ {"app/plugin.css", MIME_TYPE_TEXT_CSS, true},
73
+ {"app/asset.js", MIME_TYPE_TEXT_JAVASCRIPT, true},
74
+ {null, null, false},
75
+ {"", null, false},
76
+ {"app/plugin.cs", null, false},
77
+ {"../..", null, false},
78
+ {"../../annotations-api.jar", null, false},
79
+ });
80
+ }
81
+
82
+ @Before
83
+ public void setup() throws ServletException {
84
+ runtimeDelegate = Mockito.mock(AppRuntimeDelegate.class);
85
+ pluginRegistry = Mockito.mock(AppPluginRegistry.class);
86
+ AppPlugin plugin = Mockito.mock(AppPlugin.class);
87
+
88
+ Mockito.doReturn(pluginRegistry).when(runtimeDelegate).getAppPluginRegistry();
89
+ Mockito.doReturn(plugin).when(pluginRegistry).getPlugin(PLUGIN_NAME);
90
+ Mockito.doReturn(ASSET_DIR).when(plugin).getAssetDirectory();
91
+
92
+ pluginRootResource = new AbstractAppPluginRootResource<>(PLUGIN_NAME, runtimeDelegate);
93
+ mockServletContext = Mockito.mock(ServletContext.class);
94
+ pluginRootResource.servletContext = mockServletContext;
95
+ pluginRootResource.allowedAssets.add("app/asset.js");
96
+ pluginRootResource.allowedAssets.add("app/asset.css");
97
+ }
98
+
99
+ @Test
100
+ public void shouldGetAssetIfAllowed() throws IOException {
101
+ // given
102
+ String resourceName = "/" + ASSET_DIR + "/" + assetName;
103
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(ASSET_CONTENT.getBytes());
104
+ Mockito.doReturn(inputStream).when(mockServletContext).getResourceAsStream(resourceName);
105
+
106
+ try {
107
+ // when
108
+ final Response actual = pluginRootResource.getAsset(assetName);
109
+
110
+ // then
111
+ if (assetAllowed) {
112
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
113
+ ((StreamingOutput) actual.getEntity()).write(output);
114
+
115
+ assertThat(output.toString()).isEqualTo(ASSET_CONTENT);
116
+ assertThat(actual.getHeaders()).containsKey(HttpHeaders.CONTENT_TYPE).hasSize(1);
117
+ assertThat(actual.getHeaders().get(HttpHeaders.CONTENT_TYPE)).hasSize(1);
118
+ // In IDE it's String, with maven it's MediaType class
119
+ assertThat(actual.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0).toString()).isEqualTo(assetMediaType);
120
+
121
+ Mockito.verify(runtimeDelegate).getAppPluginRegistry();
122
+ Mockito.verify(pluginRegistry).getPlugin(PLUGIN_NAME);
123
+ Mockito.verify(mockServletContext).getResourceAsStream(resourceName);
124
+ } else {
125
+ fail("should throw RestException for '%s'", assetName);
126
+ }
127
+
128
+ } catch (RestException e) {
129
+ // then
130
+ if (assetAllowed) {
131
+ e.printStackTrace();
132
+ fail("should not throw RestException for '%s'", assetName);
133
+ } else {
134
+ assertThat(e).isInstanceOf(RestException.class);
135
+ assertThat(e).hasMessage("Not allowed to load the following file '" + assetName + "'.");
136
+
137
+ Mockito.verify(runtimeDelegate, Mockito.never()).getAppPluginRegistry();
138
+ Mockito.verify(pluginRegistry, Mockito.never()).getPlugin(PLUGIN_NAME);
139
+ Mockito.verify(mockServletContext, Mockito.never()).getResourceAsStream(assetName);
140
+ }
141
+ }
142
+ }
143
+
144
+ }
source_data/pinned/camunda-dmn-examples/commit-ee4826e5e76c/webapps/assembly/src/test/resources/META-INF/services/org.camunda.bpm.engine.rest.spi.ProcessEngineProvider ADDED
@@ -0,0 +1 @@
 
 
1
+ org.camunda.bpm.engine.rest.impl.application.ContainerManagedProcessEngineProvider