Search in sources :

Example 1 with WhitelistEntry

use of org.graylog2.system.urlwhitelist.WhitelistEntry 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 2 with WhitelistEntry

use of org.graylog2.system.urlwhitelist.WhitelistEntry in project graylog2-server by Graylog2.

the class UrlWhitelistFacade method createNativeEntity.

@Override
public NativeEntity<WhitelistEntry> createNativeEntity(Entity entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> nativeEntities, String username) {
    if (!(entity instanceof EntityV1)) {
        throw new IllegalArgumentException("Unsupported entity version: " + entity.getClass());
    }
    final WhitelistEntry whitelistEntry = objectMapper.convertValue(((EntityV1) entity).data(), WhitelistEntry.class);
    urlWhitelistService.addEntry(whitelistEntry);
    return NativeEntity.create(entity.id(), whitelistEntry.id(), TYPE_V1, createTitle(whitelistEntry), whitelistEntry);
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) WhitelistEntry(org.graylog2.system.urlwhitelist.WhitelistEntry)

Aggregations

WhitelistEntry (org.graylog2.system.urlwhitelist.WhitelistEntry)2 HashSet (java.util.HashSet)1 NotificationDto (org.graylog.events.notifications.NotificationDto)1 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)1 LiteralWhitelistEntry (org.graylog2.system.urlwhitelist.LiteralWhitelistEntry)1 RegexWhitelistEntry (org.graylog2.system.urlwhitelist.RegexWhitelistEntry)1 UrlWhitelist (org.graylog2.system.urlwhitelist.UrlWhitelist)1