Skip to content

Commit

Permalink
Return location for execution and flow creation in admin interface. A…
Browse files Browse the repository at this point in the history
…lso allow for retrieval of execution by ID
  • Loading branch information
Josh Cain authored and mposolda committed Feb 26, 2018
1 parent fe1c447 commit 24132c8
Showing 1 changed file with 29 additions and 2 deletions.
Expand Up @@ -64,12 +64,14 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import static javax.ws.rs.core.Response.Status.NOT_FOUND;

Expand Down Expand Up @@ -384,7 +386,8 @@ public Response addExecutionFlow(@PathParam("flowAlias") String flowAlias, Map<S
data.put("id", execution.getId());
adminEvent.operation(OperationType.CREATE).resource(ResourceType.AUTH_EXECUTION_FLOW).resourcePath(uriInfo).representation(data).success();

return Response.status(Response.Status.CREATED).build();
String addExecutionPathSegment = UriBuilder.fromMethod(AuthenticationManagementResource.class, "addExecutionFlow").build(parentFlow.getAlias()).getPath();
return Response.created(uriInfo.getBaseUriBuilder().path(uriInfo.getPath().replace(addExecutionPathSegment, "")).path("flows").path(newFlow.getId()).build()).build();
}

private int getNextPriority(AuthenticationFlowModel parentFlow) {
Expand All @@ -402,7 +405,7 @@ private int getNextPriority(AuthenticationFlowModel parentFlow) {
@POST
@NoCache
@Consumes(MediaType.APPLICATION_JSON)
public void addExecution(@PathParam("flowAlias") String flowAlias, Map<String, String> data) {
public Response addExecutionToFlow(@PathParam("flowAlias") String flowAlias, Map<String, String> data) {
auth.realm().requireManageRealm();

AuthenticationFlowModel parentFlow = realm.getFlowByAlias(flowAlias);
Expand Down Expand Up @@ -438,6 +441,9 @@ public void addExecution(@PathParam("flowAlias") String flowAlias, Map<String, S

data.put("id", execution.getId());
adminEvent.operation(OperationType.CREATE).resource(ResourceType.AUTH_EXECUTION).resourcePath(uriInfo).representation(data).success();

String addExecutionPathSegment = UriBuilder.fromMethod(AuthenticationManagementResource.class, "addExecutionToFlow").build(parentFlow.getAlias()).getPath();
return Response.created(uriInfo.getBaseUriBuilder().path(uriInfo.getPath().replace(addExecutionPathSegment, "")).path("executions").path(execution.getId()).build()).build();
}

/**
Expand Down Expand Up @@ -559,6 +565,26 @@ public void updateExecutions(@PathParam("flowAlias") String flowAlias, Authentic
}
}

/**
* Get Single Execution
*/
@Path("/executions/{executionId}")
@GET
@NoCache
@Produces(MediaType.APPLICATION_JSON)
public Response getExecution(final @PathParam("executionId") String executionId) {
//http://localhost:8080/auth/admin/realms/master/authentication/executions/cf26211b-9e68-4788-b754-1afd02e59d7f
auth.realm().requireManageRealm();

final Optional<AuthenticationExecutionModel> model = Optional.ofNullable(realm.getAuthenticationExecutionById(executionId));
if (!model.isPresent()) {
logger.debugv("Could not find execution by Id: {}", executionId);
throw new NotFoundException("Illegal execution");
}

return Response.ok(model.get()).build();
}

/**
* Add new authentication execution
*
Expand Down Expand Up @@ -595,6 +621,7 @@ public AuthenticationFlowModel getParentFlow(AuthenticationExecutionModel model)
return parentFlow;
}


/**
* Raise execution's priority
*
Expand Down

0 comments on commit 24132c8

Please sign in to comment.