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);
}
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);
}
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);
}
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;
}
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());
}
Aggregations