use of org.graylog.security.GrantDTO in project graylog2-server by Graylog2.
the class EntitySharesServiceTest method ignoreInvisibleOwners.
@DisplayName("The validation should ignore invisble owners")
@Test
void ignoreInvisibleOwners() {
final GRN entity = grnRegistry.newGRN(GRNTypes.STREAM, "54e3deadbeefdeadbeefaffe");
final EntityShareRequest shareRequest = EntityShareRequest.create(ImmutableMap.of());
final Set<GRN> allGrantees = dbGrantService.getAll().stream().map(GrantDTO::grantee).collect(Collectors.toSet());
lenient().when(granteeService.getAvailableGrantees(any())).thenReturn(allGrantees.stream().filter(g -> g.toString().equals("grn::::user:invisible")).map(g -> Grantee.createUser(g, g.entity())).collect(Collectors.toSet()));
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();
});
}
use of org.graylog.security.GrantDTO in project graylog2-server by Graylog2.
the class EntityOwnershipServiceTest method registerNewEventDefinition.
@Test
void registerNewEventDefinition() {
final User mockUser = mock(User.class);
when(mockUser.getName()).thenReturn("mockuser");
when(mockUser.getId()).thenReturn("mockuser");
entityOwnershipService.registerNewEventDefinition("1234", mockUser);
ArgumentCaptor<GrantDTO> grant = ArgumentCaptor.forClass(GrantDTO.class);
ArgumentCaptor<User> user = ArgumentCaptor.forClass(User.class);
verify(dbGrantService).create(grant.capture(), user.capture());
assertThat(grant.getValue()).satisfies(g -> {
assertThat(g.capability()).isEqualTo(Capability.OWN);
assertThat(g.target().type()).isEqualTo(GRNTypes.EVENT_DEFINITION.type());
assertThat(g.target().entity()).isEqualTo("1234");
assertThat(g.grantee().type()).isEqualTo(GRNTypes.USER.type());
assertThat(g.grantee().entity()).isEqualTo("mockuser");
});
}
use of org.graylog.security.GrantDTO in project graylog2-server by Graylog2.
the class RolesToGrantsMigrationTest method migrateSimpleRole.
@Test
void migrateSimpleRole() throws NotFoundException {
final User testuser1 = userService.load("testuser1");
assertThat(testuser1).isNotNull();
final User testuser2 = userService.load("testuser2");
assertThat(testuser2).isNotNull();
assertThat(roleService.load("mig-test")).isNotNull();
assertThat(dbGrantService.getForGranteesOrGlobal(ImmutableSet.of(grnRegistry.ofUser(testuser1)))).isEmpty();
migration.upgrade();
// check created grants for testuser1
final ImmutableSet<GrantDTO> grants = dbGrantService.getForGranteesOrGlobal(ImmutableSet.of(grnRegistry.ofUser(testuser1)));
assertGrantInSet(grants, "grn::::dashboard:5e2afc66cd19517ec2dabadd", Capability.VIEW);
assertGrantInSet(grants, "grn::::dashboard:5e2afc66cd19517ec2dabadf", Capability.MANAGE);
assertGrantInSet(grants, "grn::::stream:5c40ad603c034441a56942bd", Capability.VIEW);
assertGrantInSet(grants, "grn::::stream:5e2f5cfb4868e67ad4da562d", Capability.VIEW);
assertGrantInSet(grants, "grn::::stream:000000000000000000000002", Capability.MANAGE);
assertThat(grants.size()).isEqualTo(5);
// testuser2 gets the same grants. a simple check should suffice
assertThat(dbGrantService.getForGranteesOrGlobal(ImmutableSet.of(grnRegistry.ofUser(testuser2)))).satisfies(grantDTOS -> {
assertThat(Iterables.size(grantDTOS)).isEqualTo(5);
});
// empty role should be dropped
assertThatThrownBy(() -> roleService.load("mig-test")).isInstanceOf(NotFoundException.class);
}
use of org.graylog.security.GrantDTO in project graylog2-server by Graylog2.
the class UserPermissionsToGrantsMigrationTest method migrateAllUserPermissions.
@Test
void migrateAllUserPermissions() {
final ViewDTO view1 = mock(ViewDTO.class);
final ViewDTO view2 = mock(ViewDTO.class);
when(view1.type()).thenReturn(ViewDTO.Type.DASHBOARD);
when(view2.type()).thenReturn(ViewDTO.Type.SEARCH);
when(viewService.get("5c40ad603c034441a56943be")).thenReturn(Optional.of(view1));
when(viewService.get("5c40ad603c034441a56943c0")).thenReturn(Optional.of(view2));
User testuser1 = userService.load("testuser1");
assertThat(testuser1).isNotNull();
assertThat(testuser1.getPermissions().size()).isEqualTo(11 + userSelfEditPermissionCount);
assertThat(dbGrantService.getForGranteesOrGlobal(ImmutableSet.of(grnRegistry.ofUser(testuser1)))).isEmpty();
migration.upgrade();
// check created grants for testuser1
final ImmutableSet<GrantDTO> grants = dbGrantService.getForGranteesOrGlobal(ImmutableSet.of(grnRegistry.ofUser(testuser1)));
assertGrantInSet(grants, "grn::::dashboard:5e2afc66cd19517ec2dabadd", Capability.VIEW);
assertGrantInSet(grants, "grn::::dashboard:5e2afc66cd19517ec2dabadf", Capability.MANAGE);
assertGrantInSet(grants, "grn::::stream:5c40ad603c034441a56942bd", Capability.VIEW);
assertGrantInSet(grants, "grn::::stream:5e2f5cfb4868e67ad4da562d", Capability.VIEW);
assertGrantInSet(grants, "grn::::dashboard:5c40ad603c034441a56943be", Capability.MANAGE);
assertGrantInSet(grants, "grn::::search:5c40ad603c034441a56943c0", Capability.VIEW);
assertGrantInSet(grants, "grn::::event_definition:5c40ad603c034441a56942bf", Capability.MANAGE);
assertGrantInSet(grants, "grn::::event_definition:5c40ad603c034441a56942c0", Capability.VIEW);
assertThat(grants.size()).isEqualTo(8);
// reload user and check that all migrated permissions have been removed
testuser1 = userService.load("testuser1");
assertThat(testuser1).isNotNull();
assertThat(testuser1.getPermissions().size()).isEqualTo(userSelfEditPermissionCount);
}
use of org.graylog.security.GrantDTO in project graylog2-server by Graylog2.
the class UserPermissionsToGrantsMigrationTest method migrateSomeUserPermissions.
@Test
void migrateSomeUserPermissions() {
User testuser2 = userService.load("testuser2");
assertThat(testuser2).isNotNull();
assertThat(testuser2.getPermissions().size()).isEqualTo(6 + userSelfEditPermissionCount);
assertThat(dbGrantService.getForGranteesOrGlobal(ImmutableSet.of(grnRegistry.ofUser(testuser2)))).isEmpty();
migration.upgrade();
// check created grants for testuser2
final ImmutableSet<GrantDTO> grants = dbGrantService.getForGranteesOrGlobal(ImmutableSet.of(grnRegistry.ofUser(testuser2)));
assertGrantInSet(grants, "grn::::dashboard:5e2afc66cd19517ec2dabadf", Capability.MANAGE);
assertThat(grants.size()).isEqualTo(1);
// reload user and check that all migrated permissions have been removed. (should be only two less)
testuser2 = userService.load("testuser2");
assertThat(testuser2).isNotNull();
assertThat(testuser2.getPermissions().size()).isEqualTo(4 + userSelfEditPermissionCount);
}
Aggregations