Search in sources :

Example 91 with RolesAllowed

use of javax.annotation.security.RolesAllowed in project iaf by ibissource.

the class TransactionalStorage method downloadPipeMessage.

@GET
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/adapters/{adapterName}/pipes/{pipeName}/messages/{messageId}/download")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response downloadPipeMessage(@PathParam("adapterName") String adapterName, @PathParam("pipeName") String pipeName, @PathParam("messageId") String messageId) throws ApiException {
    Adapter adapter = getIbisManager().getRegisteredAdapter(adapterName);
    if (adapter == null) {
        throw new ApiException("Adapter not found!");
    }
    MessageSendingPipe pipe = (MessageSendingPipe) adapter.getPipeLine().getPipe(pipeName);
    if (pipe == null) {
        throw new ApiException("Pipe [" + pipeName + "] not found!");
    }
    // messageId is double URLEncoded, because it can contain '/' in ExchangeMailListener
    messageId = Misc.urlDecode(messageId);
    String message = getMessage(pipe.getMessageLog(), messageId);
    MediaType mediaType = getMediaType(message);
    String contentDispositionHeader = getContentDispositionHeader(mediaType, messageId);
    return Response.status(Response.Status.OK).type(mediaType).entity(message).header("Content-Disposition", contentDispositionHeader).build();
}
Also used : MessageSendingPipe(nl.nn.adapterframework.pipes.MessageSendingPipe) MediaType(javax.ws.rs.core.MediaType) Adapter(nl.nn.adapterframework.core.Adapter) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 92 with RolesAllowed

use of javax.annotation.security.RolesAllowed in project iaf by ibissource.

the class TransactionalStorage method browsePipeMessage.

@GET
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/adapters/{adapterName}/pipes/{pipeName}/messages/{messageId}")
@Produces(MediaType.APPLICATION_JSON)
public Response browsePipeMessage(@PathParam("adapterName") String adapterName, @PathParam("pipeName") String pipeName, @PathParam("messageId") String messageId) throws ApiException {
    Adapter adapter = getIbisManager().getRegisteredAdapter(adapterName);
    if (adapter == null) {
        throw new ApiException("Adapter not found!");
    }
    MessageSendingPipe pipe = (MessageSendingPipe) adapter.getPipeLine().getPipe(pipeName);
    if (pipe == null) {
        throw new ApiException("Pipe [" + pipeName + "] not found!");
    }
    IMessageBrowser<?> storage = pipe.getMessageLog();
    // messageId is double URLEncoded, because it can contain '/' in ExchangeMailListener
    messageId = Misc.urlDecode(messageId);
    try {
        String message = getMessage(storage, messageId);
        StorageItemDTO entity = getMessageMetadata(storage, messageId, message);
        return Response.status(Response.Status.OK).entity(entity).build();
    } catch (ListenerException e) {
        throw new ApiException("Could not get message metadata", e);
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) MessageSendingPipe(nl.nn.adapterframework.pipes.MessageSendingPipe) Adapter(nl.nn.adapterframework.core.Adapter) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 93 with RolesAllowed

use of javax.annotation.security.RolesAllowed in project iaf by ibissource.

the class TransactionalStorage method deleteReceiverMessages.

@DELETE
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/adapters/{adapterName}/receivers/{receiverName}/stores/Error")
@Relation("pipeline")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response deleteReceiverMessages(@PathParam("adapterName") String adapterName, @PathParam("receiverName") String receiverName, MultipartBody input) throws ApiException {
    Adapter adapter = getIbisManager().getRegisteredAdapter(adapterName);
    if (adapter == null) {
        throw new ApiException("Adapter not found!");
    }
    Receiver<?> receiver = adapter.getReceiverByName(receiverName);
    if (receiver == null) {
        throw new ApiException("Receiver [" + receiverName + "] not found!");
    }
    String[] messageIds = getMessages(input);
    List<String> errorMessages = new ArrayList<>();
    for (int i = 0; i < messageIds.length; i++) {
        try {
            deleteMessage(receiver.getMessageBrowser(ProcessState.ERROR), messageIds[i]);
        } catch (ApiException e) {
            // The message of an ApiException is wrapped in HTML, try to get the original message instead!
            errorMessages.add(e.getCause().getMessage());
        } catch (Exception e) {
            errorMessages.add(e.getMessage());
        }
    }
    if (errorMessages.isEmpty()) {
        return Response.status(Response.Status.OK).build();
    }
    return Response.status(Response.Status.ACCEPTED).entity(errorMessages).build();
}
Also used : ArrayList(java.util.ArrayList) Adapter(nl.nn.adapterframework.core.Adapter) ListenerException(nl.nn.adapterframework.core.ListenerException) IOException(java.io.IOException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 94 with RolesAllowed

use of javax.annotation.security.RolesAllowed in project jersey by jersey.

the class AircraftsResource method delete.

@DELETE
@Path("{id}")
@Produces(TEXT_PLAIN)
@RolesAllowed("admin")
public String delete(@ValidAircraftId @PathParam("id") Integer id) {
    Flight flight = DataStore.selectFlightByAircraft(id);
    if (flight != null) {
        throw new BadRequestException("Aircraft assigned to a flight.");
    }
    Aircraft aircraft = DataStore.removeAircraft(id);
    return String.format("%03d", aircraft.getId());
}
Also used : Flight(org.glassfish.jersey.examples.flight.model.Flight) BadRequestException(javax.ws.rs.BadRequestException) Aircraft(org.glassfish.jersey.examples.flight.model.Aircraft) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces)

Example 95 with RolesAllowed

use of javax.annotation.security.RolesAllowed in project jersey by jersey.

the class AircraftsResource method create.

@POST
@Consumes(APPLICATION_FORM_URLENCODED)
@RolesAllowed("admin")
@Detail
public Aircraft create(@FormParam("manufacturer") String manufacturer, @FormParam("type") String type, @FormParam("capacity") Integer capacity, @DefaultValue("0") @FormParam("x-pos") Integer x, @DefaultValue("0") @FormParam("y-pos") Integer y) {
    if (manufacturer == null || type == null || capacity == null) {
        throw new BadRequestException("Incomplete data.");
    }
    Aircraft aircraft = new Aircraft();
    aircraft.setType(new AircraftType(manufacturer, type, capacity));
    aircraft.setLocation(SimEngine.bound(new Location(x, y)));
    if (!DataStore.addAircraft(aircraft)) {
        throw new InternalServerErrorException("Unable to add new aircraft.");
    }
    return aircraft;
}
Also used : BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Aircraft(org.glassfish.jersey.examples.flight.model.Aircraft) AircraftType(org.glassfish.jersey.examples.flight.model.AircraftType) Location(org.glassfish.jersey.examples.flight.model.Location) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Detail(org.glassfish.jersey.examples.flight.filtering.Detail)

Aggregations

RolesAllowed (javax.annotation.security.RolesAllowed)191 Path (javax.ws.rs.Path)127 Produces (javax.ws.rs.Produces)110 Consumes (javax.ws.rs.Consumes)55 GET (javax.ws.rs.GET)54 POST (javax.ws.rs.POST)40 PUT (javax.ws.rs.PUT)35 HashMap (java.util.HashMap)34 ArrayList (java.util.ArrayList)32 IOException (java.io.IOException)30 ApiOperation (io.swagger.annotations.ApiOperation)29 ApiResponses (io.swagger.annotations.ApiResponses)29 Response (javax.ws.rs.core.Response)28 Adapter (nl.nn.adapterframework.core.Adapter)21 DELETE (javax.ws.rs.DELETE)19 WebApplicationException (org.rembx.jeeshop.rest.WebApplicationException)19 LinkedHashMap (java.util.LinkedHashMap)16 Locale (java.util.Locale)16 Map (java.util.Map)12 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)12