Search in sources :

Example 6 with GRN

use of org.graylog.grn.GRN in project graylog2-server by Graylog2.

the class EntityOwnershipService method registerNewSearch.

public void registerNewSearch(String id, User user) {
    final GRN grn = grnRegistry.newGRN(GRNTypes.SEARCH, id);
    registerNewEntity(grn, user);
}
Also used : GRN(org.graylog.grn.GRN)

Example 7 with GRN

use of org.graylog.grn.GRN 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();
    });
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) EntityDependencyPermissionChecker(org.graylog.security.entities.EntityDependencyPermissionChecker) BeforeEach(org.junit.jupiter.api.BeforeEach) Mock(org.mockito.Mock) BuiltinCapabilities(org.graylog.security.BuiltinCapabilities) Capability(org.graylog.security.Capability) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mockito.lenient(org.mockito.Mockito.lenient) GRNRegistry(org.graylog.grn.GRNRegistry) EventBus(com.google.common.eventbus.EventBus) MongoDBTestService(org.graylog.testing.mongodb.MongoDBTestService) DBGrantService(org.graylog.security.DBGrantService) GrantDTO(org.graylog.security.GrantDTO) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Subject(org.apache.shiro.subject.Subject) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ImmutableSet(com.google.common.collect.ImmutableSet) EntityDependencyResolver(org.graylog.security.entities.EntityDependencyResolver) ImmutableMap(com.google.common.collect.ImmutableMap) GRNTypes(org.graylog.grn.GRNTypes) MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) MongoJackExtension(org.graylog.testing.mongodb.MongoJackExtension) GRN(org.graylog.grn.GRN) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) MongoDBExtension(org.graylog.testing.mongodb.MongoDBExtension) GRNExtension(org.graylog.testing.GRNExtension) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) User(org.graylog2.plugin.database.users.User) Mockito.mock(org.mockito.Mockito.mock) GRN(org.graylog.grn.GRN) User(org.graylog2.plugin.database.users.User) Subject(org.apache.shiro.subject.Subject) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 8 with GRN

use of org.graylog.grn.GRN in project graylog2-server by Graylog2.

the class EntitySharesServiceTest method validateLastOwnerCannotBeRemoved.

// TODO Test more EntitySharesService functionality
@DisplayName("Validates we cannot remove the last owner")
@Test
void validateLastOwnerCannotBeRemoved() {
    final GRN entity = grnRegistry.newGRN(GRNTypes.STREAM, "54e3deadbeefdeadbeefaffe");
    final EntityShareRequest shareRequest = EntityShareRequest.create(ImmutableMap.of());
    // This test can also see the "invisible user"
    final Set<GRN> allGrantees = dbGrantService.getAll().stream().map(GrantDTO::grantee).collect(Collectors.toSet());
    lenient().when(granteeService.getAvailableGrantees(any())).thenReturn(allGrantees.stream().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()).isTrue();
        assertThat(validationResult.getErrors()).isNotEmpty();
        assertThat(validationResult.getErrors().get(EntityShareRequest.SELECTED_GRANTEE_CAPABILITIES).toString()).contains("Removing the following owners").contains("grn::::user:jane").contains("grn::::user:invisible");
    });
}
Also used : GRN(org.graylog.grn.GRN) User(org.graylog2.plugin.database.users.User) Subject(org.apache.shiro.subject.Subject) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 9 with GRN

use of org.graylog.grn.GRN in project graylog2-server by Graylog2.

the class EntitySharesServiceTest method validateOwnerSwitch.

@DisplayName("Validates we can switch owners")
@Test
void validateOwnerSwitch() {
    final GRN entity = grnRegistry.newGRN(GRNTypes.STREAM, "54e3deadbeefdeadbeefaffe");
    final GRN horst = grnRegistry.newGRN(GRNTypes.USER, "horst");
    final EntityShareRequest shareRequest = EntityShareRequest.create(ImmutableMap.of(horst, Capability.OWN));
    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();
    });
}
Also used : GRN(org.graylog.grn.GRN) User(org.graylog2.plugin.database.users.User) Subject(org.apache.shiro.subject.Subject) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 10 with GRN

use of org.graylog.grn.GRN in project graylog2-server by Graylog2.

the class DBGrantServiceTest method createWithGranteeCapabilityAndTarget.

@Test
public void createWithGranteeCapabilityAndTarget() {
    final GRN grantee = GRNTypes.USER.toGRN("jane");
    final GRN target = GRNTypes.DASHBOARD.toGRN("54e3deadbeefdeadbeef0000");
    final GrantDTO grant = dbService.create(grantee, Capability.MANAGE, target, "admin");
    assertThat(grant.id()).isNotBlank();
    assertThat(grant.grantee()).isEqualTo(grantee);
    assertThat(grant.capability()).isEqualTo(Capability.MANAGE);
    assertThat(grant.target()).isEqualTo(target);
    assertThat(grant.createdBy()).isEqualTo("admin");
    assertThat(grant.createdAt()).isBefore(ZonedDateTime.now(ZoneOffset.UTC));
    assertThat(grant.updatedBy()).isEqualTo("admin");
    assertThat(grant.updatedAt()).isBefore(ZonedDateTime.now(ZoneOffset.UTC));
}
Also used : GRN(org.graylog.grn.GRN) Test(org.junit.Test)

Aggregations

GRN (org.graylog.grn.GRN)51 User (org.graylog2.plugin.database.users.User)19 DisplayName (org.junit.jupiter.api.DisplayName)16 Test (org.junit.jupiter.api.Test)16 Test (org.junit.Test)13 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)11 Subject (org.apache.shiro.subject.Subject)10 ImmutableSet (com.google.common.collect.ImmutableSet)7 Collectors (java.util.stream.Collectors)5 GRNRegistry (org.graylog.grn.GRNRegistry)5 Capability (org.graylog.security.Capability)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 EventBus (com.google.common.eventbus.EventBus)4 Set (java.util.Set)4 DBGrantService (org.graylog.security.DBGrantService)4 ZonedDateTime (java.time.ZonedDateTime)3 Collection (java.util.Collection)3 List (java.util.List)3 Map (java.util.Map)3 Objects (java.util.Objects)3