Search in sources :

Example 41 with RequiresPermissions

use of org.apache.shiro.authz.annotation.RequiresPermissions in project graylog2-server by Graylog2.

the class ClusterConfigResource method update.

@PUT
@Timed
@Path("{configClass}")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update configuration in database")
@RequiresPermissions({ RestPermissions.CLUSTER_CONFIG_ENTRY_CREATE, RestPermissions.CLUSTER_CONFIG_ENTRY_EDIT })
@AuditEvent(type = AuditEventTypes.CLUSTER_CONFIGURATION_UPDATE)
public Response update(@ApiParam(name = "configClass", value = "The name of the cluster configuration class", required = true) @PathParam("configClass") @NotBlank String configClass, @ApiParam(name = "body", value = "The payload of the cluster configuration", required = true) @NotNull InputStream body) throws IOException {
    final Class<?> cls = classFromName(configClass);
    if (cls == null) {
        throw new NotFoundException("Couldn't find configuration class \"" + configClass + "\"");
    }
    final Object o;
    try {
        o = objectMapper.readValue(body, cls);
    } catch (Exception e) {
        final String msg = "Couldn't parse cluster configuration \"" + configClass + "\".";
        LOG.error(msg, e);
        throw new BadRequestException(msg);
    }
    try {
        clusterConfigService.write(o);
    } catch (Exception e) {
        final String msg = "Couldn't write cluster config \"" + configClass + "\".";
        LOG.error(msg, e);
        throw new InternalServerErrorException(msg, e);
    }
    return Response.accepted(o).build();
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) IOException(java.io.IOException) NotFoundException(javax.ws.rs.NotFoundException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Example 42 with RequiresPermissions

use of org.apache.shiro.authz.annotation.RequiresPermissions in project graylog2-server by Graylog2.

the class DeflectorResource method deprecatedCycle.

@POST
@Timed
@ApiOperation(value = "Cycle deflector to new/next index")
@RequiresPermissions(RestPermissions.DEFLECTOR_CYCLE)
@Path("/cycle")
@RestrictToMaster
@AuditEvent(type = AuditEventTypes.ES_WRITE_INDEX_UPDATE_JOB_START)
@Deprecated
public void deprecatedCycle() {
    final IndexSet indexSet = indexSetRegistry.getDefault();
    checkCycle(indexSet);
    final String msg = "Cycling deflector for default index set <" + indexSet.getConfig().id() + ">. Reason: REST request.";
    LOG.info(msg);
    activityWriter.write(new Activity(msg, DeflectorResource.class));
    indexSet.cycle();
}
Also used : Activity(org.graylog2.shared.system.activities.Activity) IndexSet(org.graylog2.indexer.IndexSet) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) RestrictToMaster(org.graylog2.shared.security.RestrictToMaster)

Example 43 with RequiresPermissions

use of org.apache.shiro.authz.annotation.RequiresPermissions in project graylog2-server by Graylog2.

the class OutputResource method get.

@GET
@Timed
@ApiOperation(value = "Get a list of all outputs")
@RequiresPermissions(RestPermissions.STREAM_OUTPUTS_CREATE)
@Produces(MediaType.APPLICATION_JSON)
public OutputListResponse get() {
    checkPermission(RestPermissions.OUTPUTS_READ);
    final Set<OutputSummary> outputs = new HashSet<>();
    for (Output output : outputService.loadAll()) outputs.add(OutputSummary.create(output.getId(), output.getTitle(), output.getType(), output.getCreatorUserId(), new DateTime(output.getCreatedAt()), new HashMap<>(output.getConfiguration()), output.getContentPack()));
    return OutputListResponse.create(outputs);
}
Also used : AvailableOutputSummary(org.graylog2.rest.resources.streams.outputs.AvailableOutputSummary) OutputSummary(org.graylog2.rest.models.system.outputs.responses.OutputSummary) Output(org.graylog2.plugin.streams.Output) DateTime(org.joda.time.DateTime) HashSet(java.util.HashSet) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 44 with RequiresPermissions

use of org.apache.shiro.authz.annotation.RequiresPermissions in project graylog2-server by Graylog2.

the class OutputResource method update.

@PUT
@Path("/{outputId}")
@Timed
@ApiOperation(value = "Update output")
@RequiresPermissions(RestPermissions.OUTPUTS_EDIT)
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such output on this node.") })
@AuditEvent(type = AuditEventTypes.MESSAGE_OUTPUT_UPDATE)
public Output update(@ApiParam(name = "outputId", value = "The id of the output that should be deleted", required = true) @PathParam("outputId") String outputId, @ApiParam(name = "JSON body", required = true) Map<String, Object> deltas) throws ValidationException, NotFoundException {
    checkPermission(RestPermissions.OUTPUTS_EDIT, outputId);
    final Output oldOutput = outputService.load(outputId);
    final AvailableOutputSummary outputSummary = messageOutputFactory.getAvailableOutputs().get(oldOutput.getType());
    if (outputSummary == null) {
        throw new ValidationException("type", "Invalid output type");
    }
    deltas.remove("streams");
    if (deltas.containsKey("configuration")) {
        @SuppressWarnings("unchecked") final Map<String, Object> configuration = (Map<String, Object>) deltas.get("configuration");
        deltas.put("configuration", ConfigurationMapConverter.convertValues(configuration, outputSummary.requestedConfiguration()));
    }
    final Output output = this.outputService.update(outputId, deltas);
    this.outputRegistry.removeOutput(oldOutput);
    return output;
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) Output(org.graylog2.plugin.streams.Output) AvailableOutputSummary(org.graylog2.rest.resources.streams.outputs.AvailableOutputSummary) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 45 with RequiresPermissions

use of org.apache.shiro.authz.annotation.RequiresPermissions in project graylog2-server by Graylog2.

the class OutputResource method get.

@GET
@Path("/{outputId}")
@Timed
@ApiOperation(value = "Get specific output")
@RequiresPermissions(RestPermissions.OUTPUTS_CREATE)
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such output on this node.") })
public OutputSummary get(@ApiParam(name = "outputId", value = "The id of the output we want.", required = true) @PathParam("outputId") String outputId) throws NotFoundException {
    checkPermission(RestPermissions.OUTPUTS_READ, outputId);
    final Output output = outputService.load(outputId);
    return OutputSummary.create(output.getId(), output.getTitle(), output.getType(), output.getCreatorUserId(), new DateTime(output.getCreatedAt()), output.getConfiguration(), output.getContentPack());
}
Also used : Output(org.graylog2.plugin.streams.Output) DateTime(org.joda.time.DateTime) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)45 ApiOperation (io.swagger.annotations.ApiOperation)42 Timed (com.codahale.metrics.annotation.Timed)30 Path (javax.ws.rs.Path)27 AuditEvent (org.graylog2.audit.jersey.AuditEvent)24 Produces (javax.ws.rs.Produces)23 GET (javax.ws.rs.GET)19 ApiResponses (io.swagger.annotations.ApiResponses)16 POST (javax.ws.rs.POST)16 BadRequestException (javax.ws.rs.BadRequestException)13 Consumes (javax.ws.rs.Consumes)12 URI (java.net.URI)9 NotFoundException (javax.ws.rs.NotFoundException)9 PUT (javax.ws.rs.PUT)8 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)7 User (org.graylog2.plugin.database.users.User)7 Output (org.graylog2.plugin.streams.Output)7 DELETE (javax.ws.rs.DELETE)6 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)5 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)5