Skip to content

Commit 6f56995

Browse files
committed
post review
Signed-off-by: Dmitrii Tikhomirov <[email protected]>
1 parent 26c32d8 commit 6f56995

File tree

12 files changed

+26
-40
lines changed

12 files changed

+26
-40
lines changed

impl/http/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</dependency>
4141
<dependency>
4242
<groupId>io.serverlessworkflow</groupId>
43-
<artifactId>serverlessworkflow-impl-jwt</artifactId>
43+
<artifactId>serverlessworkflow-impl-jackson-jwt</artifactId>
4444
<scope>test</scope>
4545
</dependency>
4646
<dependency>

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,15 @@
2929

3030
public class OAuth2AuthProvider implements AuthProvider {
3131

32-
private Oauth2 oauth2;
33-
34-
private final WorkflowApplication workflowApplication;
32+
private OAuthRequestBuilder requestBuilder;
3533

3634
private static final String BEARER_TOKEN = "%s %s";
3735

3836
public OAuth2AuthProvider(
3937
WorkflowApplication application, Workflow workflow, OAuth2AuthenticationPolicy authPolicy) {
40-
this.workflowApplication = application;
4138
Oauth2 oauth2 = authPolicy.getOauth2();
4239
if (oauth2.getOAuth2ConnectAuthenticationProperties() != null) {
43-
this.oauth2 = oauth2;
40+
this.requestBuilder = new OAuthRequestBuilder(application, oauth2);
4441
} else if (oauth2.getOAuth2AuthenticationPolicySecret() != null) {
4542
throw new UnsupportedOperationException("Secrets are still not supported");
4643
}
@@ -55,11 +52,7 @@ public Builder build(
5552
@Override
5653
public void preRequest(
5754
Invocation.Builder builder, WorkflowContext workflow, TaskContext task, WorkflowModel model) {
58-
JWT token =
59-
new OAuthRequestBuilder(workflowApplication, oauth2)
60-
.build(workflow, task, model)
61-
.validateAndGet();
62-
55+
JWT token = requestBuilder.build(workflow, task, model).validateAndGet();
6356
String tokenType = (String) token.getClaim("typ");
6457
builder.header(
6558
AuthProviderFactory.AUTH_HEADER_NAME,

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,10 @@ public class AccessTokenProvider {
3838
this.issuers = issuers;
3939
this.context = context;
4040

41-
ServiceLoader<JWTConverter> jwtConverters =
42-
ServiceLoader.load(JWTConverter.class, AccessTokenProvider.class.getClassLoader());
43-
44-
if (jwtConverters.iterator().hasNext()) {
45-
this.jwtConverter = jwtConverters.iterator().next();
46-
} else {
47-
throw new RuntimeException("No JWTConverter implementation found");
48-
}
41+
this.jwtConverter =
42+
ServiceLoader.load(JWTConverter.class)
43+
.findFirst()
44+
.orElseThrow(() -> new IllegalStateException("No JWTConverter implementation found"));
4945
}
5046

5147
public JWT validateAndGet() {
@@ -54,12 +50,12 @@ public JWT validateAndGet() {
5450
try {
5551
jwt = jwtConverter.fromToken((String) token.get("access_token"));
5652
} catch (IllegalArgumentException e) {
57-
throw new RuntimeException("Failed to parse JWT token: " + e.getMessage(), e);
53+
throw new IllegalStateException("Failed to parse JWT token: " + e.getMessage(), e);
5854
}
5955
if (!(issuers == null || issuers.isEmpty())) {
6056
String tokenIssuer = (String) jwt.getClaim("iss");
6157
if (tokenIssuer == null || tokenIssuer.isEmpty() || !issuers.contains(tokenIssuer)) {
62-
throw new RuntimeException("Token issuer is not valid: " + tokenIssuer);
58+
throw new IllegalStateException("Token issuer is not valid: " + tokenIssuer);
6359
}
6460
}
6561
return jwt;

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.nio.charset.StandardCharsets;
4040
import java.util.HashMap;
4141
import java.util.Map;
42+
import java.util.Objects;
4243

4344
class HttpRequestBuilder {
4445

@@ -137,12 +138,7 @@ InvocationHolder build(WorkflowContext workflow, TaskContext task, WorkflowModel
137138
}
138139

139140
private void validate() {
140-
if (uri == null) {
141-
throw new IllegalStateException("URI must be set before building the request");
142-
}
143-
144-
if (grantType == null) {
145-
throw new IllegalStateException("Grant type must be set before building the request");
146-
}
141+
Objects.requireNonNull(uri, "URI must be set before building the request");
142+
Objects.requireNonNull(grantType, "Grant type must be set before building the request");
147143
}
148144
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818

1919
import jakarta.ws.rs.client.Client;
2020
import jakarta.ws.rs.core.Response;
21+
import java.io.Closeable;
22+
import java.util.concurrent.Callable;
2123
import java.util.function.Supplier;
2224

23-
class InvocationHolder {
25+
class InvocationHolder implements Callable<Response>, Closeable {
2426

2527
private final Client client;
2628
private final Supplier<Response> call;
@@ -30,11 +32,11 @@ class InvocationHolder {
3032
this.call = call;
3133
}
3234

33-
Response invoke() {
35+
public Response call() {
3436
return call.get();
3537
}
3638

37-
void close() {
39+
public void close() {
3840
if (client != null) {
3941
client.close();
4042
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class TokenResponseHandler
3030

3131
@Override
3232
public Map<String, Object> apply(InvocationHolder invocation, TaskContext context) {
33-
try (Response response = invocation.invoke()) {
33+
try (Response response = invocation.call()) {
3434
if (response.getStatus() < 200 || response.getStatus() >= 300) {
3535
throw new WorkflowException(
3636
WorkflowError.communication(

impl/jwt-impl/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<version>8.0.0-SNAPSHOT</version>
1010
</parent>
1111

12-
<artifactId>serverlessworkflow-impl-jwt</artifactId>
12+
<artifactId>serverlessworkflow-impl-jackson-jwt</artifactId>
1313
<name>Serverless Workflow :: Impl :: JWT</name>
1414

1515
<dependencies>

impl/jwt-impl/src/main/java/io/serverlessworkflow/impl/http/jwt/DefaultJWTConverter.java renamed to impl/jwt-impl/src/main/java/io/serverlessworkflow/impl/http/jwt/JacksonJWTConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import java.util.Base64;
2525
import java.util.Map;
2626

27-
public class DefaultJWTConverter implements JWTConverter {
27+
public class JacksonJWTConverter implements JWTConverter {
2828

2929
private static final ObjectMapper MAPPER = new ObjectMapper();
3030

@@ -37,7 +37,7 @@ public JWT fromToken(String token) throws IllegalArgumentException {
3737
try {
3838
String payloadJson =
3939
new String(Base64.getUrlDecoder().decode(parts[1]), StandardCharsets.UTF_8);
40-
return new DefaultJWTImpl(token, MAPPER.readValue(payloadJson, Map.class));
40+
return new JacksonJWTImpl(token, MAPPER.readValue(payloadJson, Map.class));
4141
} catch (JsonProcessingException e) {
4242
throw new IllegalArgumentException("Failed to parse JWT token payload: " + e.getMessage(), e);
4343
}

impl/jwt-impl/src/main/java/io/serverlessworkflow/impl/http/jwt/DefaultJWTImpl.java renamed to impl/jwt-impl/src/main/java/io/serverlessworkflow/impl/http/jwt/JacksonJWTImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
import io.serverlessworkflow.http.jwt.JWT;
2020
import java.util.Map;
2121

22-
public class DefaultJWTImpl implements JWT {
22+
public class JacksonJWTImpl implements JWT {
2323

2424
private final Map<String, Object> claims;
2525
private final String token;
2626

27-
DefaultJWTImpl(String token, Map<String, Object> claims) {
27+
JacksonJWTImpl(String token, Map<String, Object> claims) {
2828
this.token = token;
2929
this.claims = claims;
3030
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
io.serverlessworkflow.impl.http.jwt.DefaultJWTConverter
1+
io.serverlessworkflow.impl.http.jwt.JacksonJWTConverter

0 commit comments

Comments
 (0)