Search in sources :

Example 1 with UserService

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

the class V20161125142400_EmailAlarmCallbackMigrationTest method setUp.

@Before
public void setUp() throws Exception {
    final User localAdmin = mock(User.class);
    when(localAdmin.getId()).thenReturn(localAdminId);
    when(userService.getAdminUser()).thenReturn(localAdmin);
    this.emailAlarmCallbackMigrationPeriodical = new V20161125142400_EmailAlarmCallbackMigration(clusterConfigService, streamService, alarmCallbackConfigurationService, emailAlarmCallback, userService);
}
Also used : User(org.graylog2.plugin.database.users.User) Before(org.junit.Before)

Example 2 with UserService

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

the class UserContextFactory method provide.

@Override
public UserContext provide() {
    final SecurityContext securityContext = containerRequestProvider.get().getSecurityContext();
    if (securityContext instanceof ShiroSecurityContext) {
        final ShiroSecurityContext context = (ShiroSecurityContext) securityContext;
        final Subject subject = context.getSubject();
        return new UserContext.Factory(userService).create(subject);
    }
    throw new IllegalStateException("Failed to create UserContext");
}
Also used : ShiroSecurityContext(org.graylog2.shared.security.ShiroSecurityContext) SecurityContext(javax.ws.rs.core.SecurityContext) Subject(org.apache.shiro.subject.Subject) ShiroSecurityContext(org.graylog2.shared.security.ShiroSecurityContext)

Example 3 with UserService

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

the class LegacyAlertConditionMigratorTest method setUp.

@Before
public void setUp() throws Exception {
    final ObjectMapper objectMapper = new ObjectMapperProvider().get();
    objectMapper.registerSubtypes(new NamedType(AggregationEventProcessorConfig.class, AggregationEventProcessorConfig.TYPE_NAME));
    objectMapper.registerSubtypes(new NamedType(AggregationEventProcessorParameters.class, AggregationEventProcessorConfig.TYPE_NAME));
    objectMapper.registerSubtypes(new NamedType(EventProcessorExecutionJob.Config.class, EventProcessorExecutionJob.TYPE_NAME));
    objectMapper.registerSubtypes(new NamedType(EventProcessorExecutionJob.Data.class, EventProcessorExecutionJob.TYPE_NAME));
    objectMapper.registerSubtypes(new NamedType(IntervalJobSchedule.class, IntervalJobSchedule.TYPE_NAME));
    objectMapper.registerSubtypes(new NamedType(PersistToStreamsStorageHandler.Config.class, PersistToStreamsStorageHandler.Config.TYPE_NAME));
    objectMapper.registerSubtypes(new NamedType(PersistToStreamsStorageHandler.Config.class, PersistToStreamsStorageHandler.Config.TYPE_NAME));
    objectMapper.registerSubtypes(new NamedType(LegacyAlarmCallbackEventNotificationConfig.class, LegacyAlarmCallbackEventNotificationConfig.TYPE_NAME));
    objectMapper.registerSubtypes(new NamedType(EventNotificationExecutionJob.Config.class, EventNotificationExecutionJob.TYPE_NAME));
    final MongoJackObjectMapperProvider mongoJackObjectMapperProvider = new MongoJackObjectMapperProvider(objectMapper);
    final MongoConnection mongoConnection = mongodb.mongoConnection();
    final JobSchedulerTestClock clock = new JobSchedulerTestClock(DateTime.now(DateTimeZone.UTC));
    final DBJobDefinitionService jobDefinitionService = new DBJobDefinitionService(mongoConnection, mongoJackObjectMapperProvider);
    final DBJobTriggerService jobTriggerService = new DBJobTriggerService(mongoConnection, mongoJackObjectMapperProvider, mock(NodeId.class), clock, Duration.minutes(5));
    notificationService = new DBNotificationService(mongoConnection, mongoJackObjectMapperProvider, mock(EntityOwnershipService.class));
    this.eventDefinitionService = new DBEventDefinitionService(mongoConnection, mongoJackObjectMapperProvider, mock(DBEventProcessorStateService.class), mock(EntityOwnershipService.class));
    this.eventDefinitionHandler = spy(new EventDefinitionHandler(eventDefinitionService, jobDefinitionService, jobTriggerService, clock));
    this.notificationResourceHandler = spy(new NotificationResourceHandler(notificationService, jobDefinitionService, eventDefinitionService, eventNotificationFactories));
    this.userService = mock(UserService.class);
    when(userService.getRootUser()).thenReturn(Optional.empty());
    this.migrator = new LegacyAlertConditionMigrator(mongoConnection, eventDefinitionHandler, notificationResourceHandler, notificationService, userService, CHECK_INTERVAL);
}
Also used : JobSchedulerTestClock(org.graylog.events.JobSchedulerTestClock) UserService(org.graylog2.shared.users.UserService) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) AggregationEventProcessorConfig(org.graylog.events.processor.aggregation.AggregationEventProcessorConfig) MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) DBEventDefinitionService(org.graylog.events.processor.DBEventDefinitionService) AggregationEventProcessorConfig(org.graylog.events.processor.aggregation.AggregationEventProcessorConfig) NotificationResourceHandler(org.graylog.events.notifications.NotificationResourceHandler) MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) AggregationEventProcessorParameters(org.graylog.events.processor.aggregation.AggregationEventProcessorParameters) IntervalJobSchedule(org.graylog.scheduler.schedule.IntervalJobSchedule) DBNotificationService(org.graylog.events.notifications.DBNotificationService) DBJobTriggerService(org.graylog.scheduler.DBJobTriggerService) NodeId(org.graylog2.plugin.system.NodeId) DBJobDefinitionService(org.graylog.scheduler.DBJobDefinitionService) EventDefinitionHandler(org.graylog.events.processor.EventDefinitionHandler) MongoConnection(org.graylog2.database.MongoConnection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 4 with UserService

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

the class NotificationFacadeTest method setUp.

@Before
@SuppressForbidden("Using Executors.newSingleThreadExecutor() is okay in tests")
public void setUp() throws Exception {
    objectMapper.registerSubtypes(EmailEventNotificationConfig.class, EmailEventNotificationConfigEntity.class, HttpEventNotificationConfigEntity.class, HTTPEventNotificationConfig.class);
    jobDefinitionService = mock(DBJobDefinitionService.class);
    stateService = mock(DBEventProcessorStateService.class);
    eventDefinitionService = new DBEventDefinitionService(mongodb.mongoConnection(), mapperProvider, stateService, mock(EntityOwnershipService.class));
    notificationService = new DBNotificationService(mongodb.mongoConnection(), mapperProvider, mock(EntityOwnershipService.class));
    notificationResourceHandler = new NotificationResourceHandler(notificationService, jobDefinitionService, eventDefinitionService, Maps.newHashMap());
    facade = new NotificationFacade(objectMapper, notificationResourceHandler, notificationService, userService);
}
Also used : DBNotificationService(org.graylog.events.notifications.DBNotificationService) DBJobDefinitionService(org.graylog.scheduler.DBJobDefinitionService) DBEventDefinitionService(org.graylog.events.processor.DBEventDefinitionService) DBEventProcessorStateService(org.graylog.events.processor.DBEventProcessorStateService) NotificationResourceHandler(org.graylog.events.notifications.NotificationResourceHandler) Before(org.junit.Before) SuppressForbidden(org.graylog2.shared.SuppressForbidden)

Example 5 with UserService

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

the class ProvisionerServiceTest method testFirstLastNameOnlySuccess.

@Test
public void testFirstLastNameOnlySuccess() throws ValidationException {
    when(authServiceBackend.backendId()).thenReturn(BACKEND_ID);
    when(authServiceBackend.backendType()).thenReturn(BACKEND_TYPE);
    final UserDetails.Builder detailsBuilder = provisionerService.newDetails(authServiceBackend);
    assertNotNull(detailsBuilder);
    detailsBuilder.firstName(FIRST_NAME).lastName(LAST_NAME).base64AuthServiceUid("id").username(USERNAME).accountIsEnabled(true).email(EMAIL).defaultRoles(Collections.emptySet());
    final UserDetails userDetails = detailsBuilder.build();
    assertEquals(BACKEND_ID, userDetails.authServiceId());
    assertEquals(BACKEND_TYPE, userDetails.authServiceType());
    final User user = mock(User.class);
    when(userService.create()).thenReturn(user);
    when(userService.save(isA(User.class))).thenReturn(USER_ID);
    provisionerService.provision(userDetails);
    verify(userService, times(1)).save(isA(User.class));
    verify(user, times(1)).setFirstLastFullNames(eq(FIRST_NAME), eq(LAST_NAME));
}
Also used : User(org.graylog2.plugin.database.users.User) Test(org.junit.Test)

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