Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public SchemaValidator getValidator(SchemaInline inline) {
private WorkflowPositionFactory positionFactory = () -> new QueueWorkflowPosition();
private WorkflowIdFactory idFactory = () -> UlidCreator.getMonotonicUlid().toString();
private ExecutorServiceFactory executorFactory = new DefaultExecutorServiceFactory();
private EventConsumer<?, ?> eventConsumer = InMemoryEvents.get();
private EventPublisher eventPublisher = InMemoryEvents.get();
private EventConsumer<?, ?> eventConsumer;
private EventPublisher eventPublisher;
private RuntimeDescriptorFactory descriptorFactory =
() -> new RuntimeDescriptor("reference impl", "1.0.0_alpha", Collections.emptyMap());

Expand Down Expand Up @@ -193,12 +193,9 @@ public Builder withDescriptorFactory(RuntimeDescriptorFactory factory) {
return this;
}

public Builder withEventConsumer(EventConsumer<?, ?> eventConsumer) {
public Builder withEventHandler(
EventPublisher eventPublisher, EventConsumer<?, ?> eventConsumer) {
this.eventConsumer = eventConsumer;
return this;
}

public Builder withEventPublisher(EventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
return this;
}
Expand All @@ -222,6 +219,11 @@ public WorkflowApplication build() {
.findFirst()
.orElseGet(() -> DefaultTaskExecutorFactory.get());
}
if (eventConsumer == null && eventPublisher == null) {
InMemoryEvents inMemory = new InMemoryEvents(executorFactory);
eventPublisher = inMemory;
eventConsumer = inMemory;
}
return new WorkflowApplication(this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package io.serverlessworkflow.impl.events;

import io.cloudevents.CloudEvent;
import io.serverlessworkflow.impl.DefaultExecutorServiceFactory;
import io.serverlessworkflow.impl.ExecutorServiceFactory;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
Expand All @@ -30,15 +29,11 @@
*/
public class InMemoryEvents extends AbstractTypeConsumer implements EventPublisher {

private static InMemoryEvents instance = new InMemoryEvents();

private InMemoryEvents() {}

public static InMemoryEvents get() {
return instance;
public InMemoryEvents(ExecutorServiceFactory serviceFactory) {
this.serviceFactory = serviceFactory;
}

private ExecutorServiceFactory serviceFactory = new DefaultExecutorServiceFactory();
private ExecutorServiceFactory serviceFactory;

private Map<String, Consumer<CloudEvent>> topicMap = new ConcurrentHashMap<>();

Expand Down
53 changes: 0 additions & 53 deletions impl/http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,58 +16,5 @@
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-impl-core</artifactId>
</dependency>
<dependency>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-jwt</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
</dependency>
<dependency>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-impl-jackson</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-impl-jackson-jwt</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import io.serverlessworkflow.api.types.OAuth2AuthenticationPolicy;
import io.serverlessworkflow.api.types.Oauth2;
import io.serverlessworkflow.api.types.Workflow;
import io.serverlessworkflow.http.jwt.JWT;
import io.serverlessworkflow.impl.TaskContext;
import io.serverlessworkflow.impl.WorkflowApplication;
import io.serverlessworkflow.impl.WorkflowContext;
import io.serverlessworkflow.impl.WorkflowModel;
import io.serverlessworkflow.impl.executors.http.oauth.JWT;
import io.serverlessworkflow.impl.executors.http.oauth.OAuthRequestBuilder;
import jakarta.ws.rs.client.Invocation;
import jakarta.ws.rs.client.Invocation.Builder;
Expand Down Expand Up @@ -54,11 +54,7 @@ public void preRequest(
Invocation.Builder builder, WorkflowContext workflow, TaskContext task, WorkflowModel model) {
JWT jwt = requestBuilder.build(workflow, task, model).validateAndGet();
String type =
jwt.claim("typ", String.class)
.map(String::trim)
.filter(t -> !t.isEmpty())
.orElseThrow(() -> new IllegalStateException("Token type is not present"));

jwt.type().orElseThrow(() -> new IllegalStateException("Token type is not present"));
builder.header(
AuthProviderFactory.AUTH_HEADER_NAME, String.format(BEARER_TOKEN, type, jwt.token()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package io.serverlessworkflow.impl.executors.http.oauth;

import io.serverlessworkflow.http.jwt.JWT;
import io.serverlessworkflow.http.jwt.JWTConverter;
import io.serverlessworkflow.impl.TaskContext;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.http.jwt;
package io.serverlessworkflow.impl.executors.http.oauth;

import java.time.Instant;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.http.jwt;
package io.serverlessworkflow.impl.executors.http.oauth;

public interface JWTConverter {

Expand Down
29 changes: 0 additions & 29 deletions impl/jackson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,5 @@
<groupId>net.thisptr</groupId>
<artifactId>jackson-jq</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import io.serverlessworkflow.impl.WorkflowModel;
import io.serverlessworkflow.impl.WorkflowModelCollection;
import io.serverlessworkflow.impl.WorkflowModelFactory;
import io.serverlessworkflow.impl.events.json.JacksonCloudEventUtils;
import io.serverlessworkflow.impl.jackson.JsonUtils;
import io.serverlessworkflow.impl.jackson.events.JacksonCloudEventUtils;
import java.math.BigDecimal;
import java.time.OffsetDateTime;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.impl.events.json;
package io.serverlessworkflow.impl.jackson.events;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.NullNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.impl.events.json;
package io.serverlessworkflow.impl.jackson.events;

import com.fasterxml.jackson.core.JsonProcessingException;
import io.serverlessworkflow.impl.jackson.JsonUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.impl.schema.json;
package io.serverlessworkflow.impl.jackson.schema;

import com.fasterxml.jackson.databind.JsonNode;
import com.networknt.schema.JsonSchema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.impl.schema.json;
package io.serverlessworkflow.impl.jackson.schema;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.serverlessworkflow.api.WorkflowFormat;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
io.serverlessworkflow.impl.events.json.JacksonLifeCyclePublisher
io.serverlessworkflow.impl.jackson.events.JacksonLifeCyclePublisher
Original file line number Diff line number Diff line change
@@ -1 +1 @@
io.serverlessworkflow.impl.schema.json.JsonSchemaValidatorFactory
io.serverlessworkflow.impl.jackson.schema.JsonSchemaValidatorFactory
20 changes: 4 additions & 16 deletions impl/jwt-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,24 @@
</parent>

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

<dependencies>
<dependency>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-jwt</artifactId>
<artifactId>serverlessworkflow-impl-http</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<groupId>io.serverlessworkflow</groupId>
<artifactId>serverlessworkflow-impl-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,39 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.impl.http.jwt;
package io.serverlessworkflow.impl.executors.http.oauth.jackson;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.serverlessworkflow.http.jwt.JWT;
import io.serverlessworkflow.http.jwt.JWTConverter;
import com.fasterxml.jackson.core.type.TypeReference;
import io.serverlessworkflow.impl.executors.http.oauth.JWT;
import io.serverlessworkflow.impl.executors.http.oauth.JWTConverter;
import io.serverlessworkflow.impl.jackson.JsonUtils;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Map;

public class JacksonJWTConverter implements JWTConverter {

private static final ObjectMapper MAPPER = new ObjectMapper();

@Override
public JWT fromToken(String token) throws IllegalArgumentException {
if (token == null || token.isBlank()) {
throw new IllegalArgumentException("JWT token must not be null or blank");
}

String[] parts = token.split("\\.");
if (parts.length < 2) {
throw new IllegalArgumentException("Invalid JWT token format");
throw new IllegalArgumentException(
"Invalid JWT token format. There should at least two parts separated by :");
}
try {
String headerJson =
new String(Base64.getUrlDecoder().decode(parts[0]), StandardCharsets.UTF_8);
String payloadJson =
new String(Base64.getUrlDecoder().decode(parts[1]), StandardCharsets.UTF_8);

Map<String, Object> header = MAPPER.readValue(headerJson, Map.class);
Map<String, Object> claims = MAPPER.readValue(payloadJson, Map.class);
return new JacksonJWTImpl(token, fromPart2Map(parts[0]), fromPart2Map(parts[1]));
}

return new JacksonJWTImpl(token, header, claims);
} catch (JsonProcessingException e) {
throw new IllegalArgumentException("Failed to parse JWT token payload: " + e.getMessage(), e);
private static final Map<String, Object> fromPart2Map(String part) {
String decoded = new String(Base64.getUrlDecoder().decode(part), StandardCharsets.UTF_8);
try {
return JsonUtils.mapper().readValue(decoded, new TypeReference<Map<String, Object>>() {});
} catch (IOException e) {
throw new IllegalArgumentException(
"Invalid JTW token format. " + decoded + " is not a valid json", e);
}
}
}
Loading