Search in sources :

Example 46 with Configuration

use of org.graylog2.Configuration in project graylog2-server by Graylog2.

the class RegexReplaceTesterResource method testRegexReplaceExtractor.

private RegexReplaceTesterResponse testRegexReplaceExtractor(String example, String regex, String replacement, boolean replaceAll) {
    final Map<String, Object> config = ImmutableMap.<String, Object>of("regex", regex, "replacement", replacement, "replace_all", replaceAll);
    final RegexReplaceExtractor extractor;
    try {
        extractor = new RegexReplaceExtractor(new MetricRegistry(), "test", "Test", 0L, Extractor.CursorStrategy.COPY, "test", "test", config, getCurrentUser().getName(), Collections.<Converter>emptyList(), Extractor.ConditionType.NONE, "");
    } catch (Extractor.ReservedFieldException e) {
        throw new BadRequestException("Trying to overwrite a reserved message field", e);
    } catch (ConfigurationException e) {
        throw new BadRequestException("Invalid extractor configuration", e);
    }
    final Extractor.Result result = extractor.runExtractor(example);
    final RegexReplaceTesterResponse.Match match = result == null ? null : RegexReplaceTesterResponse.Match.create(String.valueOf(result.getValue()), result.getBeginIndex(), result.getEndIndex());
    return RegexReplaceTesterResponse.create(result != null, match, regex, replacement, replaceAll, example);
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) RegexReplaceExtractor(org.graylog2.inputs.extractors.RegexReplaceExtractor) RegexReplaceTesterResponse(org.graylog2.rest.models.tools.responses.RegexReplaceTesterResponse) ConfigurationException(org.graylog2.ConfigurationException) Converter(org.graylog2.plugin.inputs.Converter) BadRequestException(javax.ws.rs.BadRequestException) Extractor(org.graylog2.plugin.inputs.Extractor) RegexReplaceExtractor(org.graylog2.inputs.extractors.RegexReplaceExtractor)

Example 47 with Configuration

use of org.graylog2.Configuration in project graylog2-server by Graylog2.

the class AbstractInputsResource method maskPasswordsInConfiguration.

protected Map<String, Object> maskPasswordsInConfiguration(Map<String, Object> configuration, ConfigurationRequest configurationRequest) {
    if (configuration == null || configurationRequest == null) {
        return configuration;
    }
    return configuration.entrySet().stream().collect(HashMap::new, (map, entry) -> {
        final ConfigurationField field = configurationRequest.getField(entry.getKey());
        if (field instanceof TextField) {
            final TextField textField = (TextField) field;
            if (textField.getAttributes().contains(TextField.Attribute.IS_PASSWORD.toString().toLowerCase(Locale.ENGLISH)) && !Strings.isNullOrEmpty((String) entry.getValue())) {
                map.put(entry.getKey(), "<password set>");
                return;
            }
        }
        map.put(entry.getKey(), entry.getValue());
    }, HashMap::putAll);
}
Also used : HashMap(java.util.HashMap) ConfigurationField(org.graylog2.plugin.configuration.fields.ConfigurationField) TextField(org.graylog2.plugin.configuration.fields.TextField)

Example 48 with Configuration

use of org.graylog2.Configuration in project graylog2-server by Graylog2.

the class JsonTesterResource method testJsonExtractor.

private JsonTesterResponse testJsonExtractor(String testString, boolean flatten, String listSeparator, String keySeparator, String kvSeparator, boolean replaceKeyWhitespace, String keyWhitespaceReplacement, String keyPrefix) {
    final Map<String, Object> config = ImmutableMap.<String, Object>builder().put("flatten", flatten).put("list_separator", listSeparator).put("key_separator", keySeparator).put("kv_separator", kvSeparator).put("replace_key_whitespace", replaceKeyWhitespace).put("key_whitespace_replacement", keyWhitespaceReplacement).put("key_prefix", keyPrefix).build();
    final JsonExtractor extractor;
    try {
        extractor = new JsonExtractor(new MetricRegistry(), "test", "Test", 0L, Extractor.CursorStrategy.COPY, "test", "test", config, getCurrentUser().getName(), Collections.<Converter>emptyList(), Extractor.ConditionType.NONE, "");
    } catch (Extractor.ReservedFieldException e) {
        throw new BadRequestException("Trying to overwrite a reserved message field", e);
    } catch (ConfigurationException e) {
        throw new BadRequestException("Invalid extractor configuration", e);
    }
    final Map<String, Object> result;
    try {
        result = extractor.extractJson(testString);
    } catch (IOException e) {
        throw new BadRequestException("Failure running JSON extractor: " + e.getMessage(), e);
    }
    return JsonTesterResponse.create(result, flatten, listSeparator, keySeparator, kvSeparator, testString);
}
Also used : ConfigurationException(org.graylog2.ConfigurationException) MetricRegistry(com.codahale.metrics.MetricRegistry) JsonExtractor(org.graylog2.inputs.extractors.JsonExtractor) Converter(org.graylog2.plugin.inputs.Converter) BadRequestException(javax.ws.rs.BadRequestException) Extractor(org.graylog2.plugin.inputs.Extractor) JsonExtractor(org.graylog2.inputs.extractors.JsonExtractor) IOException(java.io.IOException)

Example 49 with Configuration

use of org.graylog2.Configuration in project graylog2-server by Graylog2.

the class ConfigurationMapConverter method convertValues.

/**
 * Converts the values in the map to the requested types. This has been copied from the Graylog web interface
 * and should be removed once we have better configuration objects.
 */
public static Map<String, Object> convertValues(final Map<String, Object> data, final ConfigurationRequest configurationRequest) throws ValidationException {
    final Map<String, Object> configuration = Maps.newHashMapWithExpectedSize(data.size());
    final Map<String, Map<String, Object>> configurationFields = configurationRequest.asList();
    for (final Map.Entry<String, Object> entry : data.entrySet()) {
        final String field = entry.getKey();
        final Map<String, Object> fieldDescription = configurationFields.get(field);
        if (fieldDescription == null || fieldDescription.isEmpty()) {
            throw new ValidationException(field, "Unknown configuration field description for field \"" + field + "\"");
        }
        final String type = (String) fieldDescription.get("type");
        // Decide what to cast to. (string, bool, number)
        Object value;
        switch(type) {
            case "text":
            case "dropdown":
                value = entry.getValue() == null ? "" : String.valueOf(entry.getValue());
                break;
            case "number":
                try {
                    value = Integer.parseInt(String.valueOf(entry.getValue()));
                } catch (NumberFormatException e) {
                    // If a numeric field is optional and not provided, use null as value
                    if ("true".equals(String.valueOf(fieldDescription.get("is_optional")))) {
                        value = null;
                    } else {
                        throw new ValidationException(field, e.getMessage());
                    }
                }
                break;
            case "boolean":
                value = "true".equalsIgnoreCase(String.valueOf(entry.getValue()));
                break;
            case "list":
                final List<?> valueList = entry.getValue() == null ? Collections.emptyList() : (List<?>) entry.getValue();
                value = valueList.stream().filter(o -> o != null && o instanceof String).map(String::valueOf).collect(Collectors.toList());
                break;
            default:
                throw new ValidationException(field, "Unknown configuration field type \"" + type + "\"");
        }
        configuration.put(field, value);
    }
    return configuration;
}
Also used : ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) List(java.util.List) ValidationException(org.graylog2.plugin.database.ValidationException) Map(java.util.Map) Maps(com.google.common.collect.Maps) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) ValidationException(org.graylog2.plugin.database.ValidationException) Map(java.util.Map)

Example 50 with Configuration

use of org.graylog2.Configuration in project graylog2-server by Graylog2.

the class CmdLineTool method applySecuritySettings.

protected static void applySecuritySettings(TLSProtocolsConfiguration configuration) {
    // Disable insecure TLS parameters and ciphers by default.
    // Prevent attacks like LOGJAM, LUCKY13, et al.
    setSystemPropertyIfEmpty("jdk.tls.ephemeralDHKeySize", "2048");
    setSystemPropertyIfEmpty("jdk.tls.rejectClientInitiatedRenegotiation", "true");
    final Set<String> tlsProtocols = configuration.getConfiguredTlsProtocols();
    final List<String> disabledAlgorithms = Stream.of(Security.getProperty("jdk.tls.disabledAlgorithms").split(",")).map(String::trim).collect(Collectors.toList());
    // c.f. https://github.com/Graylog2/graylog2-server/issues/10944
    if (tlsProtocols == null || !(tlsProtocols.isEmpty() || tlsProtocols.contains("TLSv1") || tlsProtocols.contains("TLSv1.1"))) {
        disabledAlgorithms.addAll(ImmutableSet.of("CBC", "3DES"));
        Security.setProperty("jdk.tls.disabledAlgorithms", Strings.join(disabledAlgorithms, ", "));
    } else {
        // Remove explicitly enabled legacy TLS protocols from the disabledAlgorithms filter
        Set<String> reEnabledTLSProtocols;
        if (tlsProtocols.isEmpty()) {
            reEnabledTLSProtocols = ImmutableSet.of("TLSv1", "TLSv1.1");
        } else {
            reEnabledTLSProtocols = tlsProtocols;
        }
        final List<String> updatedProperties = disabledAlgorithms.stream().filter(p -> !reEnabledTLSProtocols.contains(p)).collect(Collectors.toList());
        Security.setProperty("jdk.tls.disabledAlgorithms", Strings.join(updatedProperties, ", "));
    }
    // Explicitly register Bouncy Castle as security provider.
    // This allows us to use more key formats than with JCE
    Security.addProvider(new BouncyCastleProvider());
}
Also used : Option(com.github.rvesse.airline.annotations.Option) Module(com.google.inject.Module) Plugin(org.graylog2.plugin.Plugin) Arrays(java.util.Arrays) ParameterException(com.github.joschi.jadconfig.ParameterException) NodeIdPersistenceException(org.graylog2.plugin.system.NodeIdPersistenceException) FeatureFlagsFactory(org.graylog2.featureflag.FeatureFlagsFactory) GuiceInjectorHolder(org.graylog2.shared.bindings.GuiceInjectorHolder) RepositoryException(com.github.joschi.jadconfig.RepositoryException) LoggerContext(org.apache.logging.log4j.core.LoggerContext) Tools(org.graylog2.plugin.Tools) LoggerFactory(org.slf4j.LoggerFactory) Level(org.apache.logging.log4j.Level) Security(java.security.Security) InstrumentedAppender(com.codahale.metrics.log4j2.InstrumentedAppender) Message(com.google.inject.spi.Message) PluginLoaderConfig(org.graylog2.plugin.PluginLoaderConfig) Map(java.util.Map) UnsupportedSearchException(org.graylog2.storage.UnsupportedSearchException) Version(org.graylog2.plugin.Version) PropertiesRepository(com.github.joschi.jadconfig.repositories.PropertiesRepository) Command(com.github.rvesse.airline.annotations.Command) ChainingClassLoader(org.graylog2.shared.plugins.ChainingClassLoader) Path(java.nio.file.Path) TLSProtocolsConfiguration(org.graylog2.configuration.TLSProtocolsConfiguration) ExceptionUtils(org.graylog2.shared.utilities.ExceptionUtils) Slf4JLoggerFactory(io.netty.util.internal.logging.Slf4JLoggerFactory) ImmutableSet(com.google.common.collect.ImmutableSet) JodaTimeConverterFactory(com.github.joschi.jadconfig.jodatime.JodaTimeConverterFactory) Collection(java.util.Collection) Set(java.util.Set) ServerStatus(org.graylog2.plugin.ServerStatus) SearchVersion(org.graylog2.storage.SearchVersion) ValidationException(com.github.joschi.jadconfig.ValidationException) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Stage(com.google.inject.Stage) List(java.util.List) Stream(java.util.stream.Stream) Configuration(org.graylog2.Configuration) DocsHelper(org.graylog2.plugin.DocsHelper) PluginBindings(org.graylog2.shared.bindings.PluginBindings) PathConfiguration(org.graylog2.configuration.PathConfiguration) PluginMetaData(org.graylog2.plugin.PluginMetaData) ElasticsearchProbeException(org.graylog2.storage.versionprobe.ElasticsearchProbeException) UI(org.graylog2.shared.UI) AccessDeniedException(java.nio.file.AccessDeniedException) GuavaConverterFactory(com.github.joschi.jadconfig.guava.GuavaConverterFactory) Joiner(com.google.common.base.Joiner) EnvironmentRepository(com.github.joschi.jadconfig.repositories.EnvironmentRepository) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) Strings(joptsimple.internal.Strings) HashSet(java.util.HashSet) JmxReporter(com.codahale.metrics.jmx.JmxReporter) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Binder(com.google.inject.Binder) SystemPropertiesRepository(com.github.joschi.jadconfig.repositories.SystemPropertiesRepository) JadConfig(com.github.joschi.jadconfig.JadConfig) ManagementFactory(java.lang.management.ManagementFactory) NamedConfigParametersModule(com.github.joschi.jadconfig.guice.NamedConfigParametersModule) MigrateCmd(org.graylog2.bootstrap.commands.MigrateCmd) FeatureFlags(org.graylog2.featureflag.FeatureFlags) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) Names(com.google.inject.name.Names) PluginLoader(org.graylog2.shared.plugins.PluginLoader) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) Injector(com.google.inject.Injector) CreationException(com.google.inject.CreationException) Repository(com.github.joschi.jadconfig.Repository) Guice(com.google.inject.Guice) MetricRegistryFactory(org.graylog2.shared.metrics.MetricRegistryFactory) InternalLoggerFactory(io.netty.util.internal.logging.InternalLoggerFactory) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Aggregations

Test (org.junit.Test)67 Configuration (org.graylog2.plugin.configuration.Configuration)46 Configuration (org.apache.commons.configuration2.Configuration)35 ApiOperation (io.swagger.annotations.ApiOperation)31 Timed (com.codahale.metrics.annotation.Timed)23 AuditEvent (org.graylog2.audit.jersey.AuditEvent)23 Path (javax.ws.rs.Path)22 BadRequestException (javax.ws.rs.BadRequestException)21 MessageInput (org.graylog2.plugin.inputs.MessageInput)18 ConfigurationRequest (org.graylog2.plugin.configuration.ConfigurationRequest)17 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)15 Stream (org.graylog2.plugin.streams.Stream)15 MidpointConfiguration (com.evolveum.midpoint.common.configuration.api.MidpointConfiguration)14 File (java.io.File)14 Consumes (javax.ws.rs.Consumes)14 DateTime (org.joda.time.DateTime)14 POST (javax.ws.rs.POST)13 Produces (javax.ws.rs.Produces)13 Configuration (org.graylog2.Configuration)13 ApiResponses (io.swagger.annotations.ApiResponses)12