Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
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 @@ -639,7 +639,7 @@ public OrganizationsResource organizations() {

@Path("workflows")
public WorkflowsResource workflows() {
return new WorkflowsResource(session);
return new WorkflowsResource(session, auth);
}

@Path("{extension}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,28 @@
import org.keycloak.representations.workflows.WorkflowRepresentation;
import org.keycloak.representations.workflows.WorkflowSetRepresentation;
import org.keycloak.services.ErrorResponse;
import org.keycloak.services.resources.admin.fgap.AdminPermissionEvaluator;

public class WorkflowsResource {

private final KeycloakSession session;
private final WorkflowsManager manager;
private final AdminPermissionEvaluator auth;

public WorkflowsResource(KeycloakSession session) {
public WorkflowsResource(KeycloakSession session, AdminPermissionEvaluator auth) {
if (!Profile.isFeatureEnabled(Feature.WORKFLOWS)) {
throw new NotFoundException();
}
this.session = session;
this.manager = new WorkflowsManager(session);
this.auth = auth;
}

@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response create(WorkflowRepresentation rep) {
auth.realm().requireManageRealm();

try {
Workflow workflow = manager.toModel(rep);
return Response.created(session.getContext().getUri().getRequestUriBuilder().path(workflow.getId()).build()).build();
Expand All @@ -51,6 +56,8 @@ public Response create(WorkflowRepresentation rep) {
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response createAll(WorkflowSetRepresentation workflows) {
auth.realm().requireManageRealm();

for (WorkflowRepresentation workflow : Optional.ofNullable(workflows.getWorkflows()).orElse(List.of())) {
create(workflow).close();
}
Expand All @@ -59,6 +66,8 @@ public Response createAll(WorkflowSetRepresentation workflows) {

@Path("{id}")
public WorkflowResource get(@PathParam("id") String id) {
auth.realm().requireManageRealm();

Workflow workflow = manager.getWorkflow(id);

if (workflow == null) {
Expand All @@ -71,6 +80,8 @@ public WorkflowResource get(@PathParam("id") String id) {
@GET
@Produces(MediaType.APPLICATION_JSON)
public Stream<WorkflowRepresentation> list() {
auth.realm().requireManageRealm();

return manager.getWorkflows().map(manager::toRepresentation);
}
}
Loading