Authentication with requirepass and user/pass now working
This commit is contained in:
		@ -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
 | 
					 * This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 * it under the terms of the Server Side Public License, version 1,
 | 
					 * 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.RedisURI;
 | 
				
			||||||
import io.lettuce.core.api.StatefulRedisConnection;
 | 
					import io.lettuce.core.api.StatefulRedisConnection;
 | 
				
			||||||
import io.lettuce.core.api.sync.RedisCommands;
 | 
					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 in.nosd.redis.dataadapters.AutoValue_RedisLookupDataAdapter_Config;
 | 
				
			||||||
import org.graylog2.plugin.lookup.LookupCachePurge;
 | 
					import org.graylog2.plugin.lookup.LookupCachePurge;
 | 
				
			||||||
import org.graylog2.plugin.lookup.LookupDataAdapter;
 | 
					import org.graylog2.plugin.lookup.LookupDataAdapter;
 | 
				
			||||||
@ -89,18 +80,19 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
 | 
				
			|||||||
        super(dto, metricRegistry);
 | 
					        super(dto, metricRegistry);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.config = (Config) dto.config();
 | 
					        this.config = (Config) dto.config();
 | 
				
			||||||
        RedisURI redisUri = RedisURI.Builder.redis(this.config.redisHost(),this.config.redisPort())
 | 
					        RedisURI redisUri ;
 | 
				
			||||||
 | 
					        redisUri = RedisURI.Builder.redis(this.config.redisHost(),this.config.redisPort())
 | 
				
			||||||
                            .withPort(this.config.redisPort())
 | 
					                            .withPort(this.config.redisPort())
 | 
				
			||||||
            	//.withAuthentication(this.config.redisUsername(), this.config.redisPassword())
 | 
					 | 
				
			||||||
                            .withDatabase(this.config.redisDB())
 | 
					                            .withDatabase(this.config.redisDB())
 | 
				
			||||||
                            .build();
 | 
					                            .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);
 | 
				
			||||||
        /*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.redisGetRequestTimer = metricRegistry.timer(MetricRegistry.name(getClass(), "redisGetRequestTime"));
 | 
				
			||||||
        this.redisGetRequestErrors = metricRegistry.meter(MetricRegistry.name(getClass(), "redisGetRequestErrors"));
 | 
					        this.redisGetRequestErrors = metricRegistry.meter(MetricRegistry.name(getClass(), "redisGetRequestErrors"));
 | 
				
			||||||
        this.redisSetRequestTimer = metricRegistry.timer(MetricRegistry.name(getClass(), "redisSetRequestTime"));
 | 
					        this.redisSetRequestTimer = metricRegistry.timer(MetricRegistry.name(getClass(), "redisSetRequestTime"));
 | 
				
			||||||
@ -202,8 +194,8 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
 | 
				
			|||||||
                    .redisHost("127.0.0.1")
 | 
					                    .redisHost("127.0.0.1")
 | 
				
			||||||
                    .redisPort(6379)
 | 
					                    .redisPort(6379)
 | 
				
			||||||
                    .redisDB(0)
 | 
					                    .redisDB(0)
 | 
				
			||||||
                    /*.redisUsername("")
 | 
					                    .redisUsername("")
 | 
				
			||||||
                    .redisPassword("")*/
 | 
					                    .redisPassword("")
 | 
				
			||||||
                    .build();
 | 
					                    .build();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -233,13 +225,13 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
 | 
				
			|||||||
        @Min(0)
 | 
					        @Min(0)
 | 
				
			||||||
        public abstract int redisDB();
 | 
					        public abstract int redisDB();
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        /*@JsonProperty("redis_username")
 | 
					        @JsonProperty("redis_username")
 | 
				
			||||||
        @Nullable
 | 
					        @Nullable
 | 
				
			||||||
        public abstract String redisUsername();
 | 
					        public abstract String redisUsername();
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        @JsonProperty("redis_password")
 | 
					        @JsonProperty("redis_password")
 | 
				
			||||||
        @Nullable
 | 
					        @Nullable
 | 
				
			||||||
        public abstract String redisPassword();*/
 | 
					        public abstract String redisPassword();
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        public static Builder builder() {
 | 
					        public static Builder builder() {
 | 
				
			||||||
            return new AutoValue_RedisLookupDataAdapter_Config.Builder();
 | 
					            return new AutoValue_RedisLookupDataAdapter_Config.Builder();
 | 
				
			||||||
@ -278,11 +270,11 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
 | 
				
			|||||||
            @JsonProperty("redis_database")
 | 
					            @JsonProperty("redis_database")
 | 
				
			||||||
            public abstract Builder redisDB(int redisDB);
 | 
					            public abstract Builder redisDB(int redisDB);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            /*@JsonProperty("redis_username")
 | 
					            @JsonProperty("redis_username")
 | 
				
			||||||
            public abstract Builder redisUsername(String redisUsername);
 | 
					            public abstract Builder redisUsername(String redisUsername);
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            @JsonProperty("redis_password")
 | 
					            @JsonProperty("redis_password")
 | 
				
			||||||
            public abstract Builder redisPassword(String redisPassword);*/
 | 
					            public abstract Builder redisPassword(String redisPassword);
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            public abstract Config build();
 | 
					            public abstract Config build();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -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
 | 
					 * This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 * it under the terms of the Server Side Public License, version 1,
 | 
					 * it under the terms of the Server Side Public License, version 1,
 | 
				
			||||||
@ -76,6 +76,26 @@ class RedisLookupAdapterFieldSet extends React.Component {
 | 
				
			|||||||
        value={config.redis_database}
 | 
					        value={config.redis_database}
 | 
				
			||||||
        labelClassName="col-sm-3"
 | 
					        labelClassName="col-sm-3"
 | 
				
			||||||
        wrapperClassName="col-sm-9" />
 | 
					        wrapperClassName="col-sm-9" />
 | 
				
			||||||
 | 
					      <Input type="text"
 | 
				
			||||||
 | 
					        id="redis_username"
 | 
				
			||||||
 | 
					        name="redis_username"
 | 
				
			||||||
 | 
					        label="Redis username"
 | 
				
			||||||
 | 
					        onChange={this.props.handleFormEvent}
 | 
				
			||||||
 | 
					        help={this.props.validationMessage('redis_username', 'Redis username. Leave empty for no auth or "requirepass" authentication')}
 | 
				
			||||||
 | 
					        bsStyle={this.props.validationState('redis_username')}
 | 
				
			||||||
 | 
					        value={config.redis_username}
 | 
				
			||||||
 | 
					        labelClassName="col-sm-3"
 | 
				
			||||||
 | 
					        wrapperClassName="col-sm-9" />
 | 
				
			||||||
 | 
					      <Input type="password"
 | 
				
			||||||
 | 
					        id="redis_password"
 | 
				
			||||||
 | 
					        label="Redis password"
 | 
				
			||||||
 | 
					        onChange={this.props.handleFormEvent}
 | 
				
			||||||
 | 
					        help={this.props.validationMessage('redis_password', 'Redis password. Leave empty for no auth')}
 | 
				
			||||||
 | 
					        bsStyle={this.props.validationState('redis_password')}
 | 
				
			||||||
 | 
					        value={config.redis_password}
 | 
				
			||||||
 | 
					        labelClassName="col-sm-3"
 | 
				
			||||||
 | 
					        wrapperClassName="col-sm-9">
 | 
				
			||||||
 | 
					        </Input>
 | 
				
			||||||
      </fieldset>
 | 
					      </fieldset>
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user