Feature - support of the new Redis options for Spring Boot 3.1 #5056

pull/5068/head
Nikita Koksharov 2 years ago
parent 9fccfc9dda
commit 526ae7ac8b

@ -19,11 +19,10 @@ import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.api.RedissonReactiveClient;
import org.redisson.api.RedissonRxClient;
import org.redisson.config.ClusterServersConfig;
import org.redisson.config.Config;
import org.redisson.config.SentinelServersConfig;
import org.redisson.config.SingleServerConfig;
import org.redisson.config.*;
import org.redisson.spring.data.connection.RedissonConnectionFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@ -32,6 +31,8 @@ import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties.Sentinel;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.ssl.SslBundle;
import org.springframework.boot.ssl.SslBundles;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -204,6 +205,7 @@ public class RedissonAutoConfiguration {
if (connectTimeoutMethod != null && timeout != null) {
c.setTimeout(timeout);
}
initSSL(c);
} else if (clusterMethod != null && ReflectionUtils.invokeMethod(clusterMethod, redisProperties) != null) {
Object clusterObject = ReflectionUtils.invokeMethod(clusterMethod, redisProperties);
Method nodesMethod = ReflectionUtils.findMethod(clusterObject.getClass(), "getNodes");
@ -223,6 +225,7 @@ public class RedissonAutoConfiguration {
if (connectTimeoutMethod != null && timeout != null) {
c.setTimeout(timeout);
}
initSSL(c);
} else {
config = new Config();
@ -238,6 +241,7 @@ public class RedissonAutoConfiguration {
if (connectTimeoutMethod != null && timeout != null) {
c.setTimeout(timeout);
}
initSSL(c);
}
if (redissonAutoConfigurationCustomizers != null) {
for (RedissonAutoConfigurationCustomizer customizer : redissonAutoConfigurationCustomizers) {
@ -247,6 +251,32 @@ public class RedissonAutoConfiguration {
return Redisson.create(config);
}
private void initSSL(BaseConfig<?> config) {
Method getSSLMethod = ReflectionUtils.findMethod(RedisProperties.class, "getSsl");
if (getSSLMethod == null) {
return;
}
RedisProperties.Ssl ssl = redisProperties.getSsl();
if (ssl.getBundle() == null) {
return;
}
ObjectProvider<SslBundles> provider = ctx.getBeanProvider(SslBundles.class);
SslBundles bundles = provider.getIfAvailable();
if (bundles == null) {
return;
}
SslBundle b = bundles.getBundle(ssl.getBundle());
if (b == null) {
return;
}
config.setSslCiphers(b.getOptions().getCiphers());
config.setSslProtocols(b.getOptions().getEnabledProtocols());
config.setSslTrustManagerFactory(b.getManagers().getTrustManagerFactory());
config.setSslKeyManagerFactory(b.getManagers().getKeyManagerFactory());
}
private String getPrefix() {
String prefix = REDIS_PROTOCOL_PREFIX;
Method isSSLMethod = ReflectionUtils.findMethod(RedisProperties.class, "isSsl");

@ -32,11 +32,14 @@ import org.redisson.client.RedisClientConfig;
import org.redisson.client.RedisConnection;
import org.redisson.config.SslProvider;
import javax.net.ssl.*;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.TrustManagerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.security.*;
import java.security.cert.CertificateException;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.util.Arrays;
/**

@ -15,11 +15,8 @@
*/
package org.redisson.config;
import com.fasterxml.jackson.annotation.JsonFilter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
@ -39,6 +36,8 @@ import org.redisson.codec.ReferenceCodecProvider;
import org.redisson.connection.*;
import org.redisson.connection.balancer.LoadBalancer;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.TrustManagerFactory;
import java.io.*;
import java.net.URL;
import java.util.Scanner;
@ -52,7 +51,12 @@ import java.util.regex.Pattern;
*
*/
public class ConfigSupport {
@JsonIgnoreType
public static class IgnoreMixIn {
}
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "class")
@JsonFilter("classFilter")
public static class ClassMixIn {
@ -244,6 +248,8 @@ public class ConfigSupport {
mapper.addMixIn(EventLoopGroup.class, ClassMixIn.class);
mapper.addMixIn(ConnectionListener.class, ClassMixIn.class);
mapper.addMixIn(ExecutorService.class, ClassMixIn.class);
mapper.addMixIn(KeyManagerFactory.class, IgnoreMixIn.class);
mapper.addMixIn(TrustManagerFactory.class, IgnoreMixIn.class);
FilterProvider filterProvider = new SimpleFilterProvider()
.addFilter("classFilter", SimpleBeanPropertyFilter.filterOutAllExcept());

Loading…
Cancel
Save