Return location for execution and flow creation in admin interface. Also allow for retrieval of execution by ID

This commit is contained in:
Josh Cain 2018-02-07 14:34:23 -06:00 committed by Marek Posolda
parent fe1c447d9a
commit 24132c8f5b

View file

@ -64,12 +64,14 @@ import javax.ws.rs.Produces;
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;
@ -384,7 +386,8 @@ public class AuthenticationManagementResource {
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) {
@ -402,7 +405,7 @@ public class AuthenticationManagementResource {
@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);
@ -438,6 +441,9 @@ public class AuthenticationManagementResource {
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();
}
/**
@ -559,6 +565,26 @@ public class AuthenticationManagementResource {
}
}
/**
* 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
*
@ -595,6 +621,7 @@ public class AuthenticationManagementResource {
return parentFlow;
}
/**
* Raise execution's priority
*