Search in sources :

Example 1 with UrlWhitelist

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()));
}
Also used : UrlWhitelist(org.graylog2.system.urlwhitelist.UrlWhitelist)

Example 2 with UrlWhitelist

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;
}
Also used : RegexWhitelistEntry(org.graylog2.system.urlwhitelist.RegexWhitelistEntry) LiteralWhitelistEntry(org.graylog2.system.urlwhitelist.LiteralWhitelistEntry) WhitelistEntry(org.graylog2.system.urlwhitelist.WhitelistEntry) NotificationDto(org.graylog.events.notifications.NotificationDto) UrlWhitelist(org.graylog2.system.urlwhitelist.UrlWhitelist) HashSet(java.util.HashSet)

Example 3 with UrlWhitelist

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.*?$");
}
Also used : DataAdapterDto(org.graylog2.lookup.dto.DataAdapterDto) HTTPJSONPathDataAdapter(org.graylog2.lookup.adapters.HTTPJSONPathDataAdapter) UrlWhitelist(org.graylog2.system.urlwhitelist.UrlWhitelist) Test(org.junit.Test)

Aggregations

UrlWhitelist (org.graylog2.system.urlwhitelist.UrlWhitelist)3 HashSet (java.util.HashSet)1 NotificationDto (org.graylog.events.notifications.NotificationDto)1 HTTPJSONPathDataAdapter (org.graylog2.lookup.adapters.HTTPJSONPathDataAdapter)1 DataAdapterDto (org.graylog2.lookup.dto.DataAdapterDto)1 LiteralWhitelistEntry (org.graylog2.system.urlwhitelist.LiteralWhitelistEntry)1 RegexWhitelistEntry (org.graylog2.system.urlwhitelist.RegexWhitelistEntry)1 WhitelistEntry (org.graylog2.system.urlwhitelist.WhitelistEntry)1 Test (org.junit.Test)1