use of org.graylog2.plugin.database.validators.ValidationResult in project graylog2-server by Graylog2.
the class EntitySharesServiceTest method validateOwnerless.
@DisplayName("Validates we can modify ownerless entitites")
@Test
void validateOwnerless() {
final GRN entity = grnRegistry.newGRN(GRNTypes.DASHBOARD, "54e3deadbeefdeadbeefaffe");
final GRN horst = grnRegistry.newGRN(GRNTypes.USER, "horst");
final EntityShareRequest shareRequest = EntityShareRequest.create(ImmutableMap.of(horst, Capability.MANAGE));
final User user = createMockUser("hans");
final Subject subject = mock(Subject.class);
final EntityShareResponse entityShareResponse = entitySharesService.prepareShare(entity, shareRequest, user, subject);
assertThat(entityShareResponse.validationResult()).satisfies(validationResult -> {
assertThat(validationResult.failed()).isFalse();
assertThat(validationResult.getErrors()).isEmpty();
});
}
use of org.graylog2.plugin.database.validators.ValidationResult in project graylog2-server by Graylog2.
the class EntitySharesServiceTest method validateLastOwnerCannotBeRemovedByChangingCapability.
@DisplayName("Validates we cannot remove the last owner by changing the own capability")
@Test
void validateLastOwnerCannotBeRemovedByChangingCapability() {
final GRN entity = grnRegistry.newGRN(GRNTypes.EVENT_DEFINITION, "54e3deadbeefdeadbeefaffe");
final GRN bob = grnRegistry.newGRN(GRNTypes.USER, "bob");
final EntityShareRequest shareRequest = EntityShareRequest.create(ImmutableMap.of(bob, Capability.VIEW));
final User user = createMockUser("requestingUser");
when(granteeService.getAvailableGrantees(user)).thenReturn(ImmutableSet.of(Grantee.createUser(bob, "bob")));
final Subject subject = mock(Subject.class);
final EntityShareResponse entityShareResponse = entitySharesService.prepareShare(entity, shareRequest, user, subject);
assertThat(entityShareResponse.validationResult()).satisfies(validationResult -> {
assertThat(validationResult.failed()).isTrue();
assertThat(validationResult.getErrors()).isNotEmpty();
assertThat(validationResult.getErrors().get(EntityShareRequest.SELECTED_GRANTEE_CAPABILITIES)).contains("Removing the following owners <[grn::::user:bob]> will leave the entity ownerless.");
});
}
use of org.graylog2.plugin.database.validators.ValidationResult in project graylog2-server by Graylog2.
the class EntitySharesServiceTest method noValidationOnEmptyRequest.
@DisplayName("Don't run validation on initial empty request")
@Test
void noValidationOnEmptyRequest() {
final GRN entity = grnRegistry.newGRN(GRNTypes.DASHBOARD, "54e3deadbeefdeadbeefaffe");
final EntityShareRequest shareRequest = EntityShareRequest.create(null);
final User user = createMockUser("hans");
final Subject subject = mock(Subject.class);
final EntityShareResponse entityShareResponse = entitySharesService.prepareShare(entity, shareRequest, user, subject);
assertThat(entityShareResponse.validationResult()).satisfies(validationResult -> {
assertThat(validationResult.failed()).isFalse();
assertThat(validationResult.getErrors()).isEmpty();
});
}
use of org.graylog2.plugin.database.validators.ValidationResult in project graylog2-server by Graylog2.
the class CollectorResource method updateCollector.
@PUT
@Path("/{id}")
@RequiresPermissions(SidecarRestPermissions.COLLECTORS_UPDATE)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a collector")
@AuditEvent(type = SidecarAuditEventTypes.COLLECTOR_UPDATE)
public Response updateCollector(@ApiParam(name = "id", required = true) @PathParam("id") String id, @ApiParam(name = "JSON body", required = true) @Valid @NotNull Collector request) throws BadRequestException {
Collector collector = collectorService.fromRequest(id, request);
final ValidationResult validationResult = validate(collector);
if (validationResult.failed()) {
return Response.status(Response.Status.BAD_REQUEST).entity(validationResult).build();
}
etagService.invalidateAll();
return Response.ok().entity(collectorService.save(collector)).build();
}
use of org.graylog2.plugin.database.validators.ValidationResult in project graylog2-server by Graylog2.
the class ConfigurationVariableResource method updateConfigurationVariable.
@PUT
@Path("/{id}")
@RequiresPermissions(SidecarRestPermissions.CONFIGURATIONS_UPDATE)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a configuration variable")
@AuditEvent(type = SidecarAuditEventTypes.CONFIGURATION_VARIABLE_UPDATE)
public Response updateConfigurationVariable(@ApiParam(name = "id", required = true) @PathParam("id") String id, @ApiParam(name = "JSON body", required = true) @Valid @NotNull ConfigurationVariable request) {
final ConfigurationVariable previousConfigurationVariable = findVariableOrFail(id);
ValidationResult validationResult = validateConfigurationVariableHelper(request);
if (validationResult.failed()) {
return Response.status(Response.Status.BAD_REQUEST).entity(validationResult).build();
}
if (!previousConfigurationVariable.name().equals(request.name())) {
configurationService.replaceVariableNames(previousConfigurationVariable.fullName(), request.fullName());
}
final ConfigurationVariable updatedConfigurationVariable = persistConfigurationVariable(id, request);
etagService.invalidateAll();
return Response.ok().entity(updatedConfigurationVariable).build();
}
Aggregations