use of javax.annotation.security.RolesAllowed in project iaf by ibissource.
the class ShowMonitors method updateTrigger.
@PUT
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/{monitorName}/triggers/{trigger}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateTrigger(@PathParam("configuration") String configName, @PathParam("monitorName") String monitorName, @PathParam("trigger") int index, Map<String, Object> json) throws ApiException {
MonitorManager mm = getMonitorManager(configName);
Monitor monitor = mm.findMonitor(monitorName);
if (monitor == null) {
throw new ApiException("Monitor not found!", Status.NOT_FOUND);
}
ITrigger trigger = monitor.getTrigger(index);
if (trigger == null) {
throw new ApiException("Trigger not found!", Status.NOT_FOUND);
}
handleTrigger(trigger, json);
return Response.status(Status.OK).build();
}
use of javax.annotation.security.RolesAllowed in project iaf by ibissource.
the class ShowMonitors method getTriggers.
@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/{monitorName}/triggers/{triggerId}")
@Produces(MediaType.APPLICATION_JSON)
public Response getTriggers(@PathParam("configuration") String configName, @PathParam("monitorName") String monitorName, @PathParam("triggerId") Integer id) throws ApiException {
MonitorManager mm = getMonitorManager(configName);
Monitor monitor = mm.findMonitor(monitorName);
if (monitor == null) {
throw new ApiException("Monitor not found!", Status.NOT_FOUND);
}
Map<String, Object> returnMap = new HashMap<>();
if (id != null) {
ITrigger trigger = monitor.getTrigger(id);
if (trigger == null) {
throw new ApiException("Trigger not found!", Status.NOT_FOUND);
} else {
returnMap.put("trigger", mapTrigger(trigger));
}
}
returnMap.put("severities", EnumUtils.getEnumList(SeverityEnum.class));
returnMap.put("events", mm.getEvents());
EntityTag etag = new EntityTag(returnMap.hashCode() + "");
Response.ResponseBuilder response = null;
// Verify if it matched with etag available in http request
response = request.evaluatePreconditions(etag);
// If ETag matches the response will be non-null;
if (response != null) {
return response.tag(etag).build();
}
return Response.status(Status.OK).entity(returnMap).tag(etag).build();
}
use of javax.annotation.security.RolesAllowed in project iaf by ibissource.
the class ShowMonitors method getMonitors.
@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/")
public Response getMonitors(@PathParam("configuration") String configurationName, @QueryParam("xml") boolean showConfigXml) throws ApiException {
Map<String, Object> returnMap = new HashMap<>();
MonitorManager mm = getMonitorManager(configurationName);
if (showConfigXml) {
String xml = mm.toXml().toXML();
return Response.status(Status.OK).type(MediaType.APPLICATION_XML).entity(xml).build();
}
List<Map<String, Object>> monitors = new ArrayList<Map<String, Object>>();
for (int i = 0; i < mm.getMonitors().size(); i++) {
Monitor monitor = mm.getMonitor(i);
monitors.add(mapMonitor(monitor));
}
returnMap.put("monitors", monitors);
returnMap.put("enabled", new Boolean(mm.isEnabled()));
returnMap.put("eventTypes", EnumUtils.getEnumList(EventTypeEnum.class));
returnMap.put("destinations", mm.getDestinations().keySet());
return Response.status(Status.OK).type(MediaType.APPLICATION_JSON).entity(returnMap).build();
}
use of javax.annotation.security.RolesAllowed in project iaf by ibissource.
the class ShowMonitors method updateTrigger.
@POST
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/{monitorName}/triggers")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateTrigger(@PathParam("configuration") String configName, @PathParam("monitorName") String monitorName, Map<String, Object> json) {
MonitorManager mm = getMonitorManager(configName);
Monitor monitor = mm.findMonitor(monitorName);
if (monitor == null) {
throw new ApiException("Monitor not found!", Status.NOT_FOUND);
}
ITrigger trigger = SpringUtils.createBean(mm.getApplicationContext(), Trigger.class);
handleTrigger(trigger, json);
monitor.registerTrigger(trigger);
monitor.configure();
return Response.status(Status.OK).build();
}
use of javax.annotation.security.RolesAllowed in project iaf by ibissource.
the class TestServiceListener method postServiceListeners.
@POST
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/test-servicelistener")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response postServiceListeners(MultipartBody inputDataMap) throws ApiException {
Map<String, Object> result = new HashMap<String, Object>();
String message = null, serviceName = null, dispatchResult = null;
InputStream file = null;
String fileEncoding = resolveTypeFromMap(inputDataMap, "encoding", String.class, Misc.DEFAULT_INPUT_STREAM_ENCODING);
try {
if (inputDataMap.getAttachment("service") != null) {
serviceName = resolveStringFromMap(inputDataMap, "service");
}
if (inputDataMap.getAttachment("file") != null) {
file = inputDataMap.getAttachment("file").getObject(InputStream.class);
message = XmlUtils.readXml(IOUtils.toByteArray(file), fileEncoding, false);
} else {
message = resolveStringWithEncoding(inputDataMap, "message", fileEncoding);
}
if (message == null && file == null) {
throw new ApiException("must provide either a message or file", 400);
}
if (!ServiceDispatcher.getInstance().isRegisteredServiceListener(serviceName)) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
try {
@SuppressWarnings("rawtypes") Map context = new HashMap();
dispatchResult = ServiceDispatcher.getInstance().dispatchRequest(serviceName, null, message, context);
} catch (ListenerException e) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
result.put("state", ExitState.SUCCESS);
result.put("result", dispatchResult);
} catch (IOException e) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
return Response.status(Response.Status.CREATED).entity(result).build();
}
Aggregations