Skip to content

Commit e85d6e6

Browse files
committed
[Fix #737] Adding test module
Signed-off-by: fjtirado <[email protected]>
1 parent 3f1a2f6 commit e85d6e6

File tree

60 files changed

+93
-148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+93
-148
lines changed

impl/http/pom.xml

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,58 +16,5 @@
1616
<groupId>io.serverlessworkflow</groupId>
1717
<artifactId>serverlessworkflow-impl-core</artifactId>
1818
</dependency>
19-
<dependency>
20-
<groupId>io.serverlessworkflow</groupId>
21-
<artifactId>serverlessworkflow-jwt</artifactId>
22-
</dependency>
23-
<dependency>
24-
<groupId>org.glassfish.jersey.media</groupId>
25-
<artifactId>jersey-media-json-jackson</artifactId>
26-
</dependency>
27-
<dependency>
28-
<groupId>org.glassfish.jersey.core</groupId>
29-
<artifactId>jersey-client</artifactId>
30-
</dependency>
31-
<dependency>
32-
<groupId>io.serverlessworkflow</groupId>
33-
<artifactId>serverlessworkflow-api</artifactId>
34-
<scope>test</scope>
35-
</dependency>
36-
<dependency>
37-
<groupId>io.serverlessworkflow</groupId>
38-
<artifactId>serverlessworkflow-impl-jackson</artifactId>
39-
<scope>test</scope>
40-
</dependency>
41-
<dependency>
42-
<groupId>io.serverlessworkflow</groupId>
43-
<artifactId>serverlessworkflow-impl-jackson-jwt</artifactId>
44-
<scope>test</scope>
45-
</dependency>
46-
<dependency>
47-
<groupId>org.junit.jupiter</groupId>
48-
<artifactId>junit-jupiter-api</artifactId>
49-
</dependency>
50-
<dependency>
51-
<groupId>org.junit.jupiter</groupId>
52-
<artifactId>junit-jupiter-engine</artifactId>
53-
</dependency>
54-
<dependency>
55-
<groupId>org.junit.jupiter</groupId>
56-
<artifactId>junit-jupiter-params</artifactId>
57-
</dependency>
58-
<dependency>
59-
<groupId>org.assertj</groupId>
60-
<artifactId>assertj-core</artifactId>
61-
</dependency>
62-
<dependency>
63-
<groupId>ch.qos.logback</groupId>
64-
<artifactId>logback-classic</artifactId>
65-
<scope>test</scope>
66-
</dependency>
67-
<dependency>
68-
<groupId>com.squareup.okhttp3</groupId>
69-
<artifactId>mockwebserver</artifactId>
70-
<scope>test</scope>
71-
</dependency>
7219
</dependencies>
7320
</project>

impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/OAuth2AuthProvider.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
import io.serverlessworkflow.api.types.OAuth2AuthenticationPolicy;
1919
import io.serverlessworkflow.api.types.Oauth2;
2020
import io.serverlessworkflow.api.types.Workflow;
21-
import io.serverlessworkflow.http.jwt.JWT;
2221
import io.serverlessworkflow.impl.TaskContext;
2322
import io.serverlessworkflow.impl.WorkflowApplication;
2423
import io.serverlessworkflow.impl.WorkflowContext;
2524
import io.serverlessworkflow.impl.WorkflowModel;
25+
import io.serverlessworkflow.impl.executors.http.oauth.JWT;
2626
import io.serverlessworkflow.impl.executors.http.oauth.OAuthRequestBuilder;
2727
import jakarta.ws.rs.client.Invocation;
2828
import jakarta.ws.rs.client.Invocation.Builder;
@@ -54,11 +54,7 @@ public void preRequest(
5454
Invocation.Builder builder, WorkflowContext workflow, TaskContext task, WorkflowModel model) {
5555
JWT jwt = requestBuilder.build(workflow, task, model).validateAndGet();
5656
String type =
57-
jwt.claim("typ", String.class)
58-
.map(String::trim)
59-
.filter(t -> !t.isEmpty())
60-
.orElseThrow(() -> new IllegalStateException("Token type is not present"));
61-
57+
jwt.type().orElseThrow(() -> new IllegalStateException("Token type is not present"));
6258
builder.header(
6359
AuthProviderFactory.AUTH_HEADER_NAME, String.format(BEARER_TOKEN, type, jwt.token()));
6460
}

impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/oauth/AccessTokenProvider.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package io.serverlessworkflow.impl.executors.http.oauth;
1717

18-
import io.serverlessworkflow.http.jwt.JWT;
19-
import io.serverlessworkflow.http.jwt.JWTConverter;
2018
import io.serverlessworkflow.impl.TaskContext;
2119
import java.util.List;
2220
import java.util.Map;

impl/jwt/src/main/java/io/serverlessworkflow/http/jwt/JWT.java renamed to impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/oauth/JWT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.serverlessworkflow.http.jwt;
16+
package io.serverlessworkflow.impl.executors.http.oauth;
1717

1818
import java.time.Instant;
1919
import java.util.List;

impl/jwt/src/main/java/io/serverlessworkflow/http/jwt/JWTConverter.java renamed to impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/oauth/JWTConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.serverlessworkflow.http.jwt;
16+
package io.serverlessworkflow.impl.executors.http.oauth;
1717

1818
public interface JWTConverter {
1919

impl/jackson/pom.xml

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,5 @@
2828
<groupId>net.thisptr</groupId>
2929
<artifactId>jackson-jq</artifactId>
3030
</dependency>
31-
<dependency>
32-
<groupId>org.junit.jupiter</groupId>
33-
<artifactId>junit-jupiter-api</artifactId>
34-
<scope>test</scope>
35-
</dependency>
36-
<dependency>
37-
<groupId>org.junit.jupiter</groupId>
38-
<artifactId>junit-jupiter-engine</artifactId>
39-
<scope>test</scope>
40-
</dependency>
41-
<dependency>
42-
<groupId>org.junit.jupiter</groupId>
43-
<artifactId>junit-jupiter-params</artifactId>
44-
<scope>test</scope>
45-
</dependency>
46-
<dependency>
47-
<groupId>org.assertj</groupId>
48-
<artifactId>assertj-core</artifactId>
49-
<scope>test</scope>
50-
</dependency>
51-
<dependency>
52-
<groupId>ch.qos.logback</groupId>
53-
<artifactId>logback-classic</artifactId>
54-
<scope>test</scope>
55-
</dependency>
56-
<dependency>
57-
<groupId>org.mockito</groupId>
58-
<artifactId>mockito-core</artifactId>
59-
</dependency>
6031
</dependencies>
6132
</project>

impl/jwt-impl/pom.xml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,24 @@
1010
</parent>
1111

1212
<artifactId>serverlessworkflow-impl-jackson-jwt</artifactId>
13-
<name>Serverless Workflow :: Impl :: JWT</name>
13+
<name>Serverless Workflow :: Impl :: JWT :: Jackson</name>
1414

1515
<dependencies>
1616
<dependency>
1717
<groupId>io.serverlessworkflow</groupId>
18-
<artifactId>serverlessworkflow-jwt</artifactId>
18+
<artifactId>serverlessworkflow-impl-http</artifactId>
1919
</dependency>
2020
<dependency>
21-
<groupId>com.fasterxml.jackson.core</groupId>
22-
<artifactId>jackson-databind</artifactId>
21+
<groupId>io.serverlessworkflow</groupId>
22+
<artifactId>serverlessworkflow-impl-jackson</artifactId>
2323
</dependency>
2424
<dependency>
2525
<groupId>org.junit.jupiter</groupId>
2626
<artifactId>junit-jupiter-api</artifactId>
27-
<scope>test</scope>
28-
</dependency>
29-
<dependency>
30-
<groupId>org.junit.jupiter</groupId>
31-
<artifactId>junit-jupiter-engine</artifactId>
32-
<scope>test</scope>
33-
</dependency>
34-
<dependency>
35-
<groupId>org.junit.jupiter</groupId>
36-
<artifactId>junit-jupiter-params</artifactId>
37-
<scope>test</scope>
3827
</dependency>
3928
<dependency>
4029
<groupId>org.assertj</groupId>
4130
<artifactId>assertj-core</artifactId>
42-
<scope>test</scope>
4331
</dependency>
4432
</dependencies>
4533

impl/jwt-impl/src/main/java/io/serverlessworkflow/impl/http/jwt/JacksonJWTConverter.java renamed to impl/jwt-impl/src/main/java/io/serverlessworkflow/impl/executors/http/oauth/jackson/JacksonJWTConverter.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,39 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.serverlessworkflow.impl.http.jwt;
16+
package io.serverlessworkflow.impl.executors.http.oauth.jackson;
1717

18-
import com.fasterxml.jackson.core.JsonProcessingException;
19-
import com.fasterxml.jackson.databind.ObjectMapper;
20-
import io.serverlessworkflow.http.jwt.JWT;
21-
import io.serverlessworkflow.http.jwt.JWTConverter;
18+
import com.fasterxml.jackson.core.type.TypeReference;
19+
import io.serverlessworkflow.impl.executors.http.oauth.JWT;
20+
import io.serverlessworkflow.impl.executors.http.oauth.JWTConverter;
21+
import io.serverlessworkflow.impl.jackson.JsonUtils;
22+
import java.io.IOException;
2223
import java.nio.charset.StandardCharsets;
2324
import java.util.Base64;
2425
import java.util.Map;
2526

2627
public class JacksonJWTConverter implements JWTConverter {
2728

28-
private static final ObjectMapper MAPPER = new ObjectMapper();
29-
3029
@Override
3130
public JWT fromToken(String token) throws IllegalArgumentException {
3231
if (token == null || token.isBlank()) {
3332
throw new IllegalArgumentException("JWT token must not be null or blank");
3433
}
35-
3634
String[] parts = token.split("\\.");
3735
if (parts.length < 2) {
38-
throw new IllegalArgumentException("Invalid JWT token format");
36+
throw new IllegalArgumentException(
37+
"Invalid JWT token format. There should at least two parts separated by :");
3938
}
40-
try {
41-
String headerJson =
42-
new String(Base64.getUrlDecoder().decode(parts[0]), StandardCharsets.UTF_8);
43-
String payloadJson =
44-
new String(Base64.getUrlDecoder().decode(parts[1]), StandardCharsets.UTF_8);
45-
46-
Map<String, Object> header = MAPPER.readValue(headerJson, Map.class);
47-
Map<String, Object> claims = MAPPER.readValue(payloadJson, Map.class);
39+
return new JacksonJWTImpl(token, fromPart2Map(parts[0]), fromPart2Map(parts[1]));
40+
}
4841

49-
return new JacksonJWTImpl(token, header, claims);
50-
} catch (JsonProcessingException e) {
51-
throw new IllegalArgumentException("Failed to parse JWT token payload: " + e.getMessage(), e);
42+
private static final Map<String, Object> fromPart2Map(String part) {
43+
String decoded = new String(Base64.getUrlDecoder().decode(part), StandardCharsets.UTF_8);
44+
try {
45+
return JsonUtils.mapper().readValue(decoded, new TypeReference<Map<String, Object>>() {});
46+
} catch (IOException e) {
47+
throw new IllegalArgumentException(
48+
"Invalid JTW token format. " + decoded + " is not a valid json", e);
5249
}
5350
}
5451
}

impl/jwt-impl/src/main/java/io/serverlessworkflow/impl/http/jwt/JacksonJWTImpl.java renamed to impl/jwt-impl/src/main/java/io/serverlessworkflow/impl/executors/http/oauth/jackson/JacksonJWTImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.serverlessworkflow.impl.http.jwt;
16+
package io.serverlessworkflow.impl.executors.http.oauth.jackson;
1717

18-
import io.serverlessworkflow.http.jwt.JWT;
18+
import io.serverlessworkflow.impl.executors.http.oauth.JWT;
1919
import java.time.Instant;
2020
import java.util.Arrays;
2121
import java.util.Collection;

impl/jwt-impl/src/main/resources/META-INF/services/io.serverlessworkflow.http.jwt.JWTConverter

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)