Search in sources :

Example 21 with UserService

use of org.graylog2.shared.users.UserService in project graylog2-server by Graylog2.

the class ViewOwnerShipToGrantsMigration method upgrade.

public void upgrade() {
    viewService.streamAll().forEach(view -> {
        final Optional<User> user = view.owner().map(userService::load);
        if (user.isPresent() && !user.get().isLocalAdmin()) {
            final GRNType grnType = ViewDTO.Type.DASHBOARD.equals(view.type()) ? GRNTypes.DASHBOARD : GRNTypes.SEARCH;
            final GRN target = grnType.toGRN(view.id());
            ensureGrant(user.get(), target);
        }
    });
}
Also used : GRN(org.graylog.grn.GRN) User(org.graylog2.plugin.database.users.User) GRNType(org.graylog.grn.GRNType)

Example 22 with UserService

use of org.graylog2.shared.users.UserService in project graylog2-server by Graylog2.

the class ViewSharingToGrantsMigration method migrateUsers.

private void migrateUsers(String viewId, Collection<String> userNames) {
    final Set<User> users = userNames.stream().map(userService::load).filter(Objects::nonNull).collect(Collectors.toSet());
    final GRN target = getTarget(viewId);
    LOG.info("Migrate users for view <{}> to grants: {}", target, users.stream().map(u -> u.getId() + "/" + u.getName()).collect(Collectors.toSet()));
    for (final User user : users) {
        ensureGrant(user, target);
    }
}
Also used : GRN(org.graylog.grn.GRN) User(org.graylog2.plugin.database.users.User)

Example 23 with UserService

use of org.graylog2.shared.users.UserService in project graylog2-server by Graylog2.

the class EventDefinitionFacadeTest method setUp.

@Before
@SuppressForbidden("Using Executors.newSingleThreadExecutor() is okay in tests")
public void setUp() throws Exception {
    objectMapper.registerSubtypes(AggregationEventProcessorConfig.class, PersistToStreamsStorageHandler.Config.class, TemplateFieldValueProvider.Config.class, AggregationEventProcessorConfigEntity.class);
    stateService = mock(DBEventProcessorStateService.class);
    jobDefinitionService = mock(DBJobDefinitionService.class);
    jobTriggerService = mock(DBJobTriggerService.class);
    jobSchedulerClock = mock(JobSchedulerClock.class);
    eventDefinitionService = new DBEventDefinitionService(mongodb.mongoConnection(), mapperProvider, stateService, entityOwnershipService);
    eventDefinitionHandler = new EventDefinitionHandler(eventDefinitionService, jobDefinitionService, jobTriggerService, jobSchedulerClock);
    Set<PluginMetaData> pluginMetaData = new HashSet<>();
    facade = new EventDefinitionFacade(objectMapper, eventDefinitionHandler, pluginMetaData, jobDefinitionService, eventDefinitionService, userService);
}
Also used : PersistToStreamsStorageHandler(org.graylog.events.processor.storage.PersistToStreamsStorageHandler) TemplateFieldValueProvider(org.graylog.events.fields.providers.TemplateFieldValueProvider) DBJobTriggerService(org.graylog.scheduler.DBJobTriggerService) JobSchedulerClock(org.graylog.scheduler.clock.JobSchedulerClock) PluginMetaData(org.graylog2.plugin.PluginMetaData) DBJobDefinitionService(org.graylog.scheduler.DBJobDefinitionService) DBEventDefinitionService(org.graylog.events.processor.DBEventDefinitionService) EventDefinitionHandler(org.graylog.events.processor.EventDefinitionHandler) DBEventProcessorStateService(org.graylog.events.processor.DBEventProcessorStateService) HashSet(java.util.HashSet) Before(org.junit.Before) SuppressForbidden(org.graylog2.shared.SuppressForbidden)

Aggregations

User (org.graylog2.plugin.database.users.User)11 Before (org.junit.Before)10 Permissions (org.graylog2.shared.security.Permissions)8 Test (org.junit.Test)8 MongoConnection (org.graylog2.database.MongoConnection)5 UserService (org.graylog2.shared.users.UserService)5 UserImpl (org.graylog2.users.UserImpl)4 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)3 HashMap (java.util.HashMap)3 GRN (org.graylog.grn.GRN)3 MongoJackObjectMapperProvider (org.graylog2.bindings.providers.MongoJackObjectMapperProvider)3 PasswordAlgorithmFactory (org.graylog2.security.PasswordAlgorithmFactory)3 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)2 DBNotificationService (org.graylog.events.notifications.DBNotificationService)2 NotificationResourceHandler (org.graylog.events.notifications.NotificationResourceHandler)2 DBEventDefinitionService (org.graylog.events.processor.DBEventDefinitionService)2 OrFilter (org.graylog.plugins.views.search.filter.OrFilter)2 QueryStringFilter (org.graylog.plugins.views.search.filter.QueryStringFilter)2 StreamFilter (org.graylog.plugins.views.search.filter.StreamFilter)2 AggregationConfigDTO (org.graylog.plugins.views.search.views.widgets.aggregation.AggregationConfigDTO)2