From 31cef8b0a61dcbdd9f753bf23e36c26c618d3190 Mon Sep 17 00:00:00 2001 From: yo000 Date: Sat, 3 Feb 2024 19:13:56 +0100 Subject: [PATCH] Authentication with requirepass and user/pass now working --- .../dataadapters/RedisLookupDataAdapter.java | 46 +++++------ .../RedisLookupAdapterFieldSet.jsx | 82 ++++++++++++------- 2 files changed, 70 insertions(+), 58 deletions(-) diff --git a/src/main/java/in/nosd/redis/dataadapters/RedisLookupDataAdapter.java b/src/main/java/in/nosd/redis/dataadapters/RedisLookupDataAdapter.java index 796e17b..7a431c9 100755 --- a/src/main/java/in/nosd/redis/dataadapters/RedisLookupDataAdapter.java +++ b/src/main/java/in/nosd/redis/dataadapters/RedisLookupDataAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Graylog, Inc. + * Copyright (C) 2024 johan@nosd.in * * This program is free software: you can redistribute it and/or modify * it under the terms of the Server Side Public License, version 1, @@ -36,15 +36,6 @@ import io.lettuce.core.RedisClient; import io.lettuce.core.RedisURI; import io.lettuce.core.api.StatefulRedisConnection; import io.lettuce.core.api.sync.RedisCommands; -/* -//To delete after clean -import okhttp3.HttpUrl; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; -import okhttp3.ResponseBody; -//END To delete after clean -*/ import in.nosd.redis.dataadapters.AutoValue_RedisLookupDataAdapter_Config; import org.graylog2.plugin.lookup.LookupCachePurge; import org.graylog2.plugin.lookup.LookupDataAdapter; @@ -89,18 +80,19 @@ public class RedisLookupDataAdapter extends LookupDataAdapter { super(dto, metricRegistry); this.config = (Config) dto.config(); - RedisURI redisUri = RedisURI.Builder.redis(this.config.redisHost(),this.config.redisPort()) - .withPort(this.config.redisPort()) - //.withAuthentication(this.config.redisUsername(), this.config.redisPassword()) - .withDatabase(this.config.redisDB()) - .build(); + RedisURI redisUri ; + redisUri = RedisURI.Builder.redis(this.config.redisHost(),this.config.redisPort()) + .withPort(this.config.redisPort()) + .withDatabase(this.config.redisDB()) + .build(); + if (this.config.redisPassword() != null && this.config.redisPassword().length() > 0) { + redisUri.setPassword(this.config.redisPassword()); + } + if (this.config.redisUsername() != null && this.config.redisUsername().length() > 0) { + redisUri.setUsername(this.config.redisUsername()); + } this.client = RedisClient.create(redisUri); - /*this.client = RedisClient.create(RedisURI.Builder.redis(this.config.redisHost(),this.config.redisPort()) - .withPort(this.config.redisPort()) - .withAuthentication(this.config.redisUsername(), this.config.redisPassword()) - .withDatabase(this.config.redisDB()) - .build()); - */ + this.redisGetRequestTimer = metricRegistry.timer(MetricRegistry.name(getClass(), "redisGetRequestTime")); this.redisGetRequestErrors = metricRegistry.meter(MetricRegistry.name(getClass(), "redisGetRequestErrors")); this.redisSetRequestTimer = metricRegistry.timer(MetricRegistry.name(getClass(), "redisSetRequestTime")); @@ -202,8 +194,8 @@ public class RedisLookupDataAdapter extends LookupDataAdapter { .redisHost("127.0.0.1") .redisPort(6379) .redisDB(0) - /*.redisUsername("") - .redisPassword("")*/ + .redisUsername("") + .redisPassword("") .build(); } @@ -233,13 +225,13 @@ public class RedisLookupDataAdapter extends LookupDataAdapter { @Min(0) public abstract int redisDB(); - /*@JsonProperty("redis_username") + @JsonProperty("redis_username") @Nullable public abstract String redisUsername(); @JsonProperty("redis_password") @Nullable - public abstract String redisPassword();*/ + public abstract String redisPassword(); public static Builder builder() { return new AutoValue_RedisLookupDataAdapter_Config.Builder(); @@ -278,11 +270,11 @@ public class RedisLookupDataAdapter extends LookupDataAdapter { @JsonProperty("redis_database") public abstract Builder redisDB(int redisDB); - /*@JsonProperty("redis_username") + @JsonProperty("redis_username") public abstract Builder redisUsername(String redisUsername); @JsonProperty("redis_password") - public abstract Builder redisPassword(String redisPassword);*/ + public abstract Builder redisPassword(String redisPassword); public abstract Config build(); } diff --git a/src/web/dataadapters/RedisLookupAdapterFieldSet.jsx b/src/web/dataadapters/RedisLookupAdapterFieldSet.jsx index 07a1fc6..67b93f5 100644 --- a/src/web/dataadapters/RedisLookupAdapterFieldSet.jsx +++ b/src/web/dataadapters/RedisLookupAdapterFieldSet.jsx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Graylog, Inc. + * Copyright (C) 2024 johan@nosd.in * * This program is free software: you can redistribute it and/or modify * it under the terms of the Server Side Public License, version 1, @@ -44,38 +44,58 @@ class RedisLookupAdapterFieldSet extends React.Component { return (
+ id="redis_host" + name="redis_host" + label="Redis host" + required + onChange={this.props.handleFormEvent} + help={this.props.validationMessage('redis_host', 'Your Redis Host')} + bsStyle={this.props.validationState('redis_host')} + value={config.redis_host} + labelClassName="col-sm-3" + wrapperClassName="col-sm-9" /> + id="redis_port" + name="redis_port" + label="Redis port" + required + onChange={this.props.handleFormEvent} + help={this.props.validationMessage('redis_port', 'Redis port instance is listening on')} + bsStyle={this.props.validationState('redis_port')} + value={config.redis_port} + labelClassName="col-sm-3" + wrapperClassName="col-sm-9" /> + id="redis_database" + name="redis_database" + label="Redis database" + required + onChange={this.props.handleFormEvent} + help={this.props.validationMessage('redis_database', 'Redis database')} + bsStyle={this.props.validationState('redis_database')} + value={config.redis_database} + labelClassName="col-sm-3" + wrapperClassName="col-sm-9" /> + + +
); }