use of org.graylog2.users.UserImpl in project graylog2-server by Graylog2.
the class LdapUserAuthenticatorTest method testSyncFromLdapEntry.
@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void testSyncFromLdapEntry() {
final LdapUserAuthenticator authenticator = spy(new LdapUserAuthenticator(ldapConnector, ldapSettingsService, userService, mock(RoleService.class), DateTimeZone.UTC));
final LdapEntry userEntry = new LdapEntry();
final LdapSettings ldapSettings = mock(LdapSettings.class);
when(ldapSettings.getDisplayNameAttribute()).thenReturn("displayName");
when(ldapSettings.getDefaultGroupId()).thenReturn("54e3deadbeefdeadbeef0001");
when(ldapSettings.getAdditionalDefaultGroupIds()).thenReturn(Collections.emptySet());
when(userService.create()).thenReturn(new UserImpl(null, new Permissions(Collections.emptySet()), Maps.newHashMap()));
final User ldapUser = authenticator.syncFromLdapEntry(userEntry, ldapSettings, "user");
assertThat(ldapUser).isNotNull();
assertThat(ldapUser.isExternalUser()).isTrue();
assertThat(ldapUser.getName()).isEqualTo("user");
assertThat(ldapUser.getEmail()).isEqualTo("user@localhost");
assertThat(ldapUser.getHashedPassword()).isEqualTo("User synced from LDAP.");
assertThat(ldapUser.getTimeZone()).isEqualTo(DateTimeZone.UTC);
assertThat(ldapUser.getRoleIds()).containsOnly("54e3deadbeefdeadbeef0001");
assertThat(ldapUser.getPermissions()).isNotEmpty();
}
use of org.graylog2.users.UserImpl in project graylog2-server by Graylog2.
the class NotificationFacadeTest method createNativeEntity.
@Test
public void createNativeEntity() {
final EntityV1 entityV1 = createTestEntity();
final JobDefinitionDto jobDefinitionDto = mock(JobDefinitionDto.class);
when(jobDefinitionService.save(any(JobDefinitionDto.class))).thenReturn(jobDefinitionDto);
final UserImpl kmerzUser = new UserImpl(mock(PasswordAlgorithmFactory.class), new Permissions(ImmutableSet.of()), ImmutableMap.of("username", "kmerz"));
when(userService.load("kmerz")).thenReturn(kmerzUser);
final NativeEntity<NotificationDto> nativeEntity = facade.createNativeEntity(entityV1, ImmutableMap.of(), ImmutableMap.of(), "kmerz");
assertThat(nativeEntity).isNotNull();
final NotificationDto notificationDto = nativeEntity.entity();
assertThat(notificationDto.title()).isEqualTo("title");
assertThat(notificationDto.description()).isEqualTo("descriptions");
assertThat(notificationDto.config().type()).isEqualTo("http-notification-v1");
}
use of org.graylog2.users.UserImpl in project graylog2-server by Graylog2.
the class ViewsResourceTest method creatingViewAddsCurrentUserAsOwner.
@Test
public void creatingViewAddsCurrentUserAsOwner() throws Exception {
final ViewDTO.Builder builder = mock(ViewDTO.Builder.class);
when(view.toBuilder()).thenReturn(builder);
when(view.type()).thenReturn(ViewDTO.Type.DASHBOARD);
when(view.searchId()).thenReturn("6141d457d3a6b9d73c8ac55a");
when(builder.owner(any())).thenReturn(builder);
when(builder.build()).thenReturn(view);
final UserImpl testUser = new UserImpl(mock(PasswordAlgorithmFactory.class), new Permissions(ImmutableSet.of()), ImmutableMap.of("username", "testuser"));
final UserContext userContext = mock(UserContext.class);
when(userContext.getUser()).thenReturn(testUser);
when(userContext.getUserId()).thenReturn("testuser");
when(currentUser.isLocalAdmin()).thenReturn(true);
when(searchUser.username()).thenReturn("testuser");
this.viewsResource.create(view, userContext, searchUser);
final ArgumentCaptor<String> ownerCaptor = ArgumentCaptor.forClass(String.class);
verify(builder, times(1)).owner(ownerCaptor.capture());
assertThat(ownerCaptor.getValue()).isEqualTo("testuser");
}
use of org.graylog2.users.UserImpl in project graylog2-server by Graylog2.
the class DashboardV1FacadeTest method setUp.
@Before
public void setUp() throws IOException {
objectMapper.registerSubtypes(new NamedType(AggregationConfigDTO.class, AggregationConfigDTO.NAME));
objectMapper.registerSubtypes(new NamedType(MessageListConfigDTO.class, MessageListConfigDTO.NAME));
objectMapper.registerSubtypes(new NamedType(LineVisualizationConfigDTO.class, LineVisualizationConfigDTO.NAME));
objectMapper.registerSubtypes(new NamedType(BarVisualizationConfigDTO.class, BarVisualizationConfigDTO.NAME));
objectMapper.registerSubtypes(new NamedType(NumberVisualizationConfigDTO.class, NumberVisualizationConfigDTO.NAME));
objectMapper.registerSubtypes(new NamedType(TimeHistogramConfigDTO.class, TimeHistogramConfigDTO.NAME));
objectMapper.registerSubtypes(new NamedType(ValueConfigDTO.class, ValueConfigDTO.NAME));
objectMapper.registerSubtypes(new NamedType(PivotSortConfig.class, PivotSortConfig.Type));
objectMapper.registerSubtypes(new NamedType(PivotEntity.class, PivotEntity.NAME));
objectMapper.registerSubtypes(new NamedType(PivotSort.class, PivotSort.Type));
objectMapper.registerSubtypes(new NamedType(OrFilter.class, OrFilter.NAME));
objectMapper.registerSubtypes(new NamedType(StreamFilter.class, StreamFilter.NAME));
objectMapper.registerSubtypes(new NamedType(QueryStringFilter.class, QueryStringFilter.NAME));
objectMapper.registerSubtypes(new NamedType(AutoIntervalDTO.class, AutoIntervalDTO.type));
final MongoConnection mongoConnection = mongodb.mongoConnection();
final MongoJackObjectMapperProvider mapper = new MongoJackObjectMapperProvider(objectMapper);
searchDbService = new ViewFacadeTest.TestSearchDBService(mongoConnection, mapper);
viewService = new ViewFacadeTest.TestViewService(mongoConnection, mapper, null);
viewSummaryService = new ViewFacadeTest.TestViewSummaryService(mongoConnection, mapper);
userService = mock(UserService.class);
final UserImpl fakeUser = new UserImpl(mock(PasswordAlgorithmFactory.class), new Permissions(ImmutableSet.of()), ImmutableMap.of("username", "testuser"));
when(userService.load("testuser")).thenReturn(fakeUser);
final DashboardWidgetConverter dashboardWidgetConverter = new DashboardWidgetConverter();
final EntityConverter entityConverter = new EntityConverter(dashboardWidgetConverter);
facade = new DashboardV1Facade(objectMapper, searchDbService, entityConverter, viewService, viewSummaryService, userService);
final URL resourceUrl = Resources.getResource(DashboardV1Facade.class, "content-pack-dashboard-v1.json");
final ContentPack contentPack = objectMapper.readValue(resourceUrl, ContentPack.class);
assertThat(contentPack).isInstanceOf(ContentPackV1.class);
final ContentPackV1 contentPackV1 = (ContentPackV1) contentPack;
final Entity entity = contentPackV1.entities().iterator().next();
final StreamImpl stream = new StreamImpl(Collections.emptyMap());
final Map<EntityDescriptor, Object> nativeEntities = new HashMap<>(1);
nativeEntities.put(EntityDescriptor.create("58b3d55a-51ad-4b3e-865c-85776016a151", ModelTypes.STREAM_V1), stream);
final NativeEntity<ViewDTO> nativeEntity = facade.createNativeEntity(entity, ImmutableMap.of(), nativeEntities, "testuser");
assertThat(nativeEntity).isNotNull();
viewDTO = nativeEntity.entity();
}
use of org.graylog2.users.UserImpl in project graylog2-server by Graylog2.
the class UserServiceImplTest method testGetRoleNames.
@Test
public void testGetRoleNames() throws Exception {
final UserImplFactory factory = new UserImplFactory(new Configuration(), permissions);
final UserImpl user = factory.create(new HashMap<>());
final Role role = createRole("Foo");
final ImmutableMap<String, Role> map = ImmutableMap.<String, Role>builder().put(role.getId(), role).build();
when(roleService.loadAllIdMap()).thenReturn(map);
assertThat(userService.getRoleNames(user)).isEmpty();
user.setRoleIds(Sets.newHashSet(role.getId()));
assertThat(userService.getRoleNames(user)).containsOnly("Foo");
when(roleService.loadAllIdMap()).thenReturn(new HashMap<>());
assertThat(userService.getRoleNames(user)).isEmpty();
}
Aggregations