use of org.graylog2.system.urlwhitelist.UrlWhitelist in project graylog2-server by Graylog2.
the class V20191129134600_CreateInitialUrlWhitelist method upgrade.
@Override
public void upgrade() {
final MigrationCompleted migrationCompleted = configService.get(MigrationCompleted.class);
if (migrationCompleted != null) {
log.debug("Migration already completed.");
return;
}
UrlWhitelist whitelist = createWhitelist();
whitelistService.saveWhitelist(whitelist);
configService.write(MigrationCompleted.create(whitelist.toString()));
}
use of org.graylog2.system.urlwhitelist.UrlWhitelist in project graylog2-server by Graylog2.
the class V20191129134600_CreateInitialUrlWhitelist method createWhitelist.
private UrlWhitelist createWhitelist() {
final Set<WhitelistEntry> entries = new HashSet<>();
dataAdapterService.findAll().stream().map(this::extractFromDataAdapter).forEach(e -> e.ifPresent(entries::add));
try (final Stream<NotificationDto> notificationsStream = notificationService.streamAll()) {
notificationsStream.map(this::extractFromNotification).forEach(e -> e.ifPresent(entries::add));
}
log.info("Created {} whitelist entries from URLs configured in data adapters and event notifications.", entries.size());
final UrlWhitelist whitelist = UrlWhitelist.createEnabled(new ArrayList<>(entries));
log.debug("Resulting whitelist: {}.", whitelist);
return whitelist;
}
use of org.graylog2.system.urlwhitelist.UrlWhitelist in project graylog2-server by Graylog2.
the class V20191129134600_CreateInitialUrlWhitelistTest method createQuotedRegexEntry.
@Test
public void createQuotedRegexEntry() {
final HTTPJSONPathDataAdapter.Config config = mock(HTTPJSONPathDataAdapter.Config.class);
when(config.url()).thenReturn("https://www.graylog.com/${key}/test.json/${key}");
final DataAdapterDto dataAdapterDto = mock(DataAdapterDto.class);
when(dataAdapterDto.config()).thenReturn(config);
when(dataAdapterService.findAll()).thenReturn(Collections.singleton(dataAdapterDto));
migration.upgrade();
final ArgumentCaptor<UrlWhitelist> captor = ArgumentCaptor.forClass(UrlWhitelist.class);
verify(whitelistService).saveWhitelist(captor.capture());
final UrlWhitelist whitelist = captor.getValue();
final String whitelisted = "https://www.graylog.com/message/test.json/message";
final String notWhitelisted = "https://wwwXgraylogXcom/message/testXjson/messsage";
assertThat(whitelist.isWhitelisted(whitelisted)).withFailMessage("Whitelist " + whitelist + " is expected to consider url <" + whitelisted + "> whitelisted.").isTrue();
assertThat(whitelist.isWhitelisted(notWhitelisted)).withFailMessage("Whitelist " + whitelist + " is expected to consider url <" + notWhitelisted + "> not whitelisted.").isFalse();
assertThat(whitelist.entries().size()).isEqualTo(1);
assertThat(whitelist.entries().get(0).value()).isEqualTo("^\\Qhttps://www.graylog.com/\\E.*?\\Q/test.json/\\E.*?$");
}
Aggregations