/**
   * Copy existing authentication flow under a new name
   *
   * <p>The new name is given as 'newName' attribute of the passed JSON object
   *
   * @param flowAlias Name of the existing authentication flow
   * @param data JSON containing 'newName' attribute
   */
  @Path("/flows/{flowAlias}/copy")
  @POST
  @NoCache
  @Consumes(MediaType.APPLICATION_JSON)
  public Response copy(@PathParam("flowAlias") String flowAlias, Map<String, String> data) {
    auth.requireManage();

    String newName = data.get("newName");
    if (realm.getFlowByAlias(newName) != null) {
      return Response.status(Response.Status.CONFLICT).build();
    }

    AuthenticationFlowModel flow = realm.getFlowByAlias(flowAlias);
    if (flow == null) {
      logger.debug("flow not found: " + flowAlias);
      return Response.status(NOT_FOUND).build();
    }
    AuthenticationFlowModel copy = new AuthenticationFlowModel();
    copy.setAlias(newName);
    copy.setDescription(flow.getDescription());
    copy.setProviderId(flow.getProviderId());
    copy.setBuiltIn(false);
    copy.setTopLevel(flow.isTopLevel());
    copy = realm.addAuthenticationFlow(copy);
    copy(newName, flow, copy);

    data.put("id", copy.getId());
    adminEvent.operation(OperationType.CREATE).resourcePath(uriInfo).representation(data).success();

    return Response.status(201).build();
  }
  /**
   * Get authentication flows
   *
   * <p>Returns a list of authentication flows.
   */
  @Path("/flows")
  @GET
  @NoCache
  @Produces(MediaType.APPLICATION_JSON)
  public List<AuthenticationFlowRepresentation> getFlows() {
    auth.requireAny();

    List<AuthenticationFlowRepresentation> flows = new LinkedList<>();
    for (AuthenticationFlowModel flow : realm.getAuthenticationFlows()) {
      if (flow.isTopLevel()) {
        flows.add(ModelToRepresentation.toRepresentation(realm, flow));
      }
    }
    return flows;
  }