use of org.graylog.grn.GRN in project graylog2-server by Graylog2.
the class DBGrantServiceTest method getForGranteeWithCapability.
@Test
@MongoDBFixtures("grants.json")
public void getForGranteeWithCapability() {
final GRN jane = grnRegistry.newGRN("user", "jane");
final GRN john = grnRegistry.newGRN("user", "john");
assertThat(dbService.getForGranteeWithCapability(jane, Capability.MANAGE)).hasSize(1);
assertThat(dbService.getForGranteeWithCapability(jane, Capability.OWN)).hasSize(1);
assertThat(dbService.getForGranteeWithCapability(john, Capability.VIEW)).hasSize(1);
}
use of org.graylog.grn.GRN in project graylog2-server by Graylog2.
the class DBGrantServiceTest method ensure.
@Test
@MongoDBFixtures("grants.json")
public void ensure() {
final GRN jane = grnRegistry.parse("grn::::user:jane");
final GRN stream1 = grnRegistry.parse("grn::::stream:54e3deadbeefdeadbeef0000");
final GRN newStream = grnRegistry.parse("grn::::stream:54e3deadbeefdeadbeef0888");
// Matches existing grant. Returns original
final GrantDTO stream1Grant = dbService.getForTargetAndGrantee(stream1, jane).get(0);
GrantDTO result = dbService.ensure(jane, Capability.VIEW, stream1, "admin");
assertThat(result).isEqualTo(stream1Grant);
// Updates to a higher capability
result = dbService.ensure(jane, Capability.MANAGE, stream1, "admin");
assertThat(result.capability()).isEqualTo(Capability.MANAGE);
// Don't downgrade to a lower capability
result = dbService.ensure(jane, Capability.VIEW, stream1, "admin");
assertThat(result.capability()).isEqualTo(Capability.MANAGE);
// Create a new grant
assertThat(dbService.ensure(jane, Capability.MANAGE, newStream, "admin")).isNotNull();
assertThat(dbService.getForTarget(newStream)).satisfies(grantDTOS -> {
assertThat(grantDTOS.size()).isEqualTo(1);
assertThat(grantDTOS.get(0).grantee()).isEqualTo(jane);
assertThat(grantDTOS.get(0).capability()).isEqualTo(Capability.MANAGE);
assertThat(grantDTOS.get(0).target()).isEqualTo(newStream);
});
}
use of org.graylog.grn.GRN in project graylog2-server by Graylog2.
the class DBGrantServiceTest method createWithGrantDTOAndUserObject.
@Test
public void createWithGrantDTOAndUserObject() {
final ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
final GRN grantee = GRNTypes.USER.toGRN("jane");
final GRN target = GRNTypes.DASHBOARD.toGRN("54e3deadbeefdeadbeef0000");
final User user = mock(User.class);
when(user.getName()).thenReturn("john");
final GrantDTO grantDTO = GrantDTO.of(grantee, Capability.OWN, target).toBuilder().createdAt(now.minusHours(1)).updatedAt(now.minusHours(1)).build();
final GrantDTO grant = dbService.create(grantDTO, user);
assertThat(grant.id()).isNotBlank();
assertThat(grant.grantee()).isEqualTo(grantee);
assertThat(grant.capability()).isEqualTo(Capability.OWN);
assertThat(grant.target()).isEqualTo(target);
assertThat(grant.createdBy()).isEqualTo("john");
assertThat(grant.createdAt()).isAfter(grantDTO.createdAt());
assertThat(grant.updatedBy()).isEqualTo("john");
assertThat(grant.updatedAt()).isAfter(grantDTO.updatedAt());
}
use of org.graylog.grn.GRN in project graylog2-server by Graylog2.
the class DBGrantServiceTest method getForGrantee.
@Test
@MongoDBFixtures("grants.json")
public void getForGrantee() {
final GRN jane = grnRegistry.newGRN("user", "jane");
final GRN john = grnRegistry.newGRN("user", "john");
assertThat(dbService.getForGrantee(jane)).hasSize(3);
assertThat(dbService.getForGrantee(john)).hasSize(2);
}
use of org.graylog.grn.GRN in project graylog2-server by Graylog2.
the class EntitySharesResource method updateEntityShares.
@POST
@ApiOperation(value = "Create / update shares for an entity or collection")
@Path("entities/{entityGRN}")
@NoAuditEvent("Audit events are created within EntitySharesService")
public Response updateEntityShares(@ApiParam(name = "entityGRN", required = true) @PathParam("entityGRN") @NotBlank String entityGRN, @ApiParam(name = "JSON Body", required = true) @NotNull @Valid EntityShareRequest request) {
final GRN entity = grnRegistry.parse(entityGRN);
checkOwnership(entity);
final EntityShareResponse entityShareResponse = entitySharesService.updateEntityShares(entity, request, requireNonNull(getCurrentUser()));
if (entityShareResponse.validationResult().failed()) {
return Response.status(Response.Status.BAD_REQUEST).entity(entityShareResponse).build();
} else {
return Response.ok(entityShareResponse).build();
}
}
Aggregations