mirror of
https://github.com/keycloak/keycloak.git
synced 2025-12-17 20:44:50 -06:00
Support for YAML payloads for Admin client for creation of workflows
Closes #43666 Signed-off-by: vramik <vramik@redhat.com>
This commit is contained in:
@@ -124,6 +124,9 @@ public abstract class AbstractWorkflowComponentRepresentation {
|
||||
}
|
||||
|
||||
protected void setConfigValue(String key, List<String> values) {
|
||||
if (values == null) {
|
||||
return;
|
||||
}
|
||||
if (this.config == null) {
|
||||
this.config = new MultivaluedHashMap<>();
|
||||
}
|
||||
@@ -131,6 +134,9 @@ public abstract class AbstractWorkflowComponentRepresentation {
|
||||
}
|
||||
|
||||
protected void addConfigValue(String key, String value) {
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
if (this.config == null) {
|
||||
this.config = new MultivaluedHashMap<>();
|
||||
}
|
||||
|
||||
@@ -79,6 +79,10 @@
|
||||
<artifactId>resteasy-jaxb-provider</artifactId>
|
||||
<version>${resteasy.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.jakarta.rs</groupId>
|
||||
<artifactId>jackson-jakarta-rs-yaml-provider</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.keycloak.admin.client.resource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.jakarta.rs.yaml.YAMLMediaTypes;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.POST;
|
||||
@@ -22,12 +23,12 @@ import org.keycloak.representations.workflows.WorkflowSetRepresentation;
|
||||
public interface WorkflowsResource {
|
||||
|
||||
@POST
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Consumes({MediaType.APPLICATION_JSON, YAMLMediaTypes.APPLICATION_JACKSON_YAML})
|
||||
Response create(WorkflowRepresentation representation);
|
||||
|
||||
@Path("set")
|
||||
@POST
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Consumes({MediaType.APPLICATION_JSON, YAMLMediaTypes.APPLICATION_JACKSON_YAML})
|
||||
Response create(WorkflowSetRepresentation representation);
|
||||
|
||||
@GET
|
||||
|
||||
@@ -33,6 +33,8 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.fasterxml.jackson.jakarta.rs.yaml.JacksonYAMLProvider;
|
||||
import com.fasterxml.jackson.jakarta.rs.yaml.YAMLMediaTypes;
|
||||
import jakarta.ws.rs.client.Client;
|
||||
import jakarta.ws.rs.client.Entity;
|
||||
import jakarta.ws.rs.client.WebTarget;
|
||||
@@ -86,7 +88,6 @@ import org.keycloak.testframework.remote.runonserver.InjectRunOnServer;
|
||||
import org.keycloak.testframework.remote.runonserver.RunOnServerClient;
|
||||
import org.keycloak.testframework.server.KeycloakUrls;
|
||||
import org.keycloak.tests.utils.MailUtils;
|
||||
import org.keycloak.util.JsonSerialization;
|
||||
|
||||
@KeycloakIntegrationTest(config = WorkflowsServerConfig.class)
|
||||
public class WorkflowManagementTest {
|
||||
@@ -884,9 +885,10 @@ public class WorkflowManagementTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateUsingYaml() throws IOException {
|
||||
public void testCreateWorkflowsUsingYaml() throws IOException {
|
||||
WorkflowSetRepresentation expectedWorkflows = WorkflowRepresentation.create()
|
||||
.of(UserCreationTimeWorkflowProviderFactory.ID)
|
||||
.name(UserCreationTimeWorkflowProviderFactory.ID)
|
||||
.withSteps(
|
||||
WorkflowStepRepresentation.create().of(NotifyUserStepProviderFactory.ID)
|
||||
.after(Duration.ofDays(5))
|
||||
@@ -896,17 +898,35 @@ public class WorkflowManagementTest {
|
||||
.build()
|
||||
).build();
|
||||
|
||||
Client httpClient = Keycloak.getClientProvider().newRestEasyClient(null, null, true);
|
||||
WebTarget target = httpClient.target(keycloakUrls.getBaseUrl().toString())
|
||||
.path("admin")
|
||||
.path("realms")
|
||||
.path(managedRealm.getName())
|
||||
.path("workflows")
|
||||
.path("set")
|
||||
.register(new BearerAuthFilter(adminClient.tokenManager()));
|
||||
try (Client httpClient = Keycloak.getClientProvider().newRestEasyClient(null, null, true)) {
|
||||
httpClient.register(JacksonYAMLProvider.class);
|
||||
// multiple workflows
|
||||
WebTarget target = httpClient.target(keycloakUrls.getBaseUrl().toString())
|
||||
.path("admin")
|
||||
.path("realms")
|
||||
.path(managedRealm.getName())
|
||||
.path("workflows")
|
||||
.path("set")
|
||||
.register(new BearerAuthFilter(adminClient.tokenManager()));
|
||||
|
||||
Response response = target.request().post(Entity.entity(JsonSerialization.writeValueAsString(expectedWorkflows), "application/yaml"));
|
||||
response.close();
|
||||
Entity<WorkflowSetRepresentation> entitySet = Entity.entity(expectedWorkflows, YAMLMediaTypes.APPLICATION_JACKSON_YAML_TYPE);
|
||||
try (Response response = target.request().post(entitySet)) {
|
||||
assertThat(response.getStatus(), is(Response.Status.CREATED.getStatusCode()));
|
||||
}
|
||||
|
||||
// single workflow
|
||||
target = httpClient.target(keycloakUrls.getBaseUrl().toString())
|
||||
.path("admin")
|
||||
.path("realms")
|
||||
.path(managedRealm.getName())
|
||||
.path("workflows")
|
||||
.register(new BearerAuthFilter(adminClient.tokenManager()));
|
||||
|
||||
Entity<WorkflowRepresentation> entity = Entity.entity(expectedWorkflows.getWorkflows().get(0), YAMLMediaTypes.APPLICATION_JACKSON_YAML_TYPE);
|
||||
try (Response response = target.request().post(entity)) {
|
||||
assertThat(response.getStatus(), is(Response.Status.CREATED.getStatusCode()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<MimeMessage> findEmailsByRecipient(MailServer mailServer, String expectedRecipient) {
|
||||
|
||||
Reference in New Issue
Block a user