DATAGEODE-93 - Realign SSL configuration using @EnableSsl with Apache Geode's SSL configuration properties.
This commit is contained in:
@@ -17,13 +17,17 @@
|
||||
|
||||
package org.springframework.data.gemfire.config.annotation;
|
||||
|
||||
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalArgumentException;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.shiro.util.Assert;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@@ -47,122 +51,177 @@ import org.springframework.context.annotation.Import;
|
||||
public @interface EnableSsl {
|
||||
|
||||
/**
|
||||
* A space-separated list of the valid SSL ciphers for secure Socket connections. A setting of 'any'
|
||||
* uses any ciphers that are enabled by default in the configured JSSE provider.
|
||||
* Configures the SSL ciphers used for secure Socket connections as an array of valid {@link String cipher names}.
|
||||
*
|
||||
* A setting of {@literal any} uses any ciphers that are enabled by default in the configured JSSE provider.
|
||||
*
|
||||
* Defaults to {@literal any}.
|
||||
*
|
||||
* Use either the {@literal spring.data.gemfire.security.ssl.<component>.ciphers} property
|
||||
* or the {@literal spring.data.gemfire.security.ssl.ciphers} property
|
||||
* Use the {@literal spring.data.gemfire.security.ssl.ciphers} property
|
||||
* in {@literal application.properties}.
|
||||
*/
|
||||
String ciphers() default "any";
|
||||
String[] ciphers() default { "any" };
|
||||
|
||||
/**
|
||||
* An array of Pivotal GemFire/Apache Geode Components in which SSL can be enabled.
|
||||
* Configures the Pivotal GemFire/Apache Geode components for which SSL will be enabled.
|
||||
*
|
||||
* Defaults to {@link EnableSsl.Component#CLUSTER}.
|
||||
* Defaults to {@link EnableSsl.Component#ALL}.
|
||||
*
|
||||
* The value(s) for this attribute are used to configure cluster-wide
|
||||
* (e.g. {@literal spring.data.gemfire.security.ssl.cluster.keystore} SSL properties
|
||||
* or individual component {e.g. {@literal spring.data.gemfire.security.ssl.locator.keystore}} SSL properties.
|
||||
* Use the {@literal spring.data.gemfire.security.ssl.components} property
|
||||
* in {@literal application.properties}.
|
||||
*
|
||||
* E.g. {@literal spring.data.gemfire.security.ssl.components=cluster,gateway,locator,server}.
|
||||
*/
|
||||
Component[] components() default { Component.CLUSTER };
|
||||
Component[] components() default { Component.ALL };
|
||||
|
||||
/**
|
||||
* Pathname to the keystore used for SSL communications.
|
||||
* Configures the {@link String names} of all the individual {@literal Keystore} certificates to use
|
||||
* when configuring SSL for each Pivotal GemFire/Apache Geode {@link Component} separately.
|
||||
*
|
||||
* Each {@link Component} defaults to the configured value of the {@link #defaultCertificateAlias()}
|
||||
* if not individually configured with this attribute.
|
||||
*
|
||||
* Use {@literal spring.data.gemfire.security.ssl.certificate.alias.<component>}
|
||||
* in {@literal application.properties}.
|
||||
*
|
||||
* E.g. {@literal spring.data.gemfire.security.ssl.certificate.alias.gateway=WanCert}.
|
||||
*/
|
||||
ComponentAlias[] componentCertificateAliases() default {};
|
||||
|
||||
/**
|
||||
* Configures the default {@link String name} of a single {@literal Keystore} certificate to use
|
||||
* when configuring SSL for all Pivotal GemFire/Apache Geode {@link Component components} collectively.
|
||||
*
|
||||
* If {@code defaultAlias} is not specified, then the first certificate in the {@literal Keystore}
|
||||
* acts as the {@literal default} SSL certificate.
|
||||
*
|
||||
* Use the {@literal spring.data.gemfire.security.ssl.certificate.alias.default} property
|
||||
* in {@literal application.properties}.
|
||||
*/
|
||||
String defaultCertificateAlias() default "";
|
||||
|
||||
/**
|
||||
* Pathname to the {@literal Keystore} used for SSL communications.
|
||||
*
|
||||
* Defaults to unset.
|
||||
*
|
||||
* Use either the {@literal spring.data.gemfire.security.ssl.<component>.keystore} property
|
||||
* or the {@literal spring.data.gemfire.security.ssl.keystore} property
|
||||
* Use the {@literal spring.data.gemfire.security.ssl.keystore} property
|
||||
* in {@literal application.properties}.
|
||||
*/
|
||||
String keystore() default "";
|
||||
|
||||
/**
|
||||
* Password to access the keys in the keystore used in SSL communications.
|
||||
* Password to access the keys in the {@literal Keystore} used for SSL communications.
|
||||
*
|
||||
* Defaults to unset.
|
||||
*
|
||||
* Use either the {@literal spring.data.gemfire.security.ssl.<component>.keystore-password} property
|
||||
* or the {@literal spring.data.gemfire.security.ssl.keystore-password} property
|
||||
* Use the {@literal spring.data.gemfire.security.ssl.keystore.password} property
|
||||
* in {@literal application.properties}.
|
||||
*/
|
||||
String keystorePassword() default "";
|
||||
|
||||
/**
|
||||
* TODO change to an enum?
|
||||
* Identifies the type of {@literal Keystore} used for SSL communications.
|
||||
*
|
||||
* Identifies the type of keystore used in SSL communications. For example, JKS, PKCS11, etc.
|
||||
* For example: {@literal JKS}, {@literal PKCS11}, etc.
|
||||
*
|
||||
* Defaults to unset.
|
||||
* Defaults to {@literal JKS}, or the {@literal Java Keystore}.
|
||||
*
|
||||
* Use either the {@literal spring.data.gemfire.security.ssl.<component>.keystore-type} property
|
||||
* or the {@literal spring.data.gemfire.security.ssl.keystore-type} property
|
||||
* Use the {@literal spring.data.gemfire.security.ssl.keystore.type} property
|
||||
* in {@literal application.properties}.
|
||||
*/
|
||||
String keystoreType() default "";
|
||||
String keystoreType() default "JKS";
|
||||
|
||||
/**
|
||||
* A space-separated list of the valid SSL protocols used in secure Socket connections. A setting of 'any'
|
||||
* uses any protocol that is enabled by default in the configured JSSE provider.
|
||||
* Configures the SSL protocols used for secure Socket connections as an array of
|
||||
* valid {@link String protocol names}.
|
||||
*
|
||||
* A setting of {@literal any} uses any protocol that is enabled by default in the configured JSSE provider.
|
||||
*
|
||||
* Defaults to {@literal any}.
|
||||
*
|
||||
* Use either the {@literal spring.data.gemfire.security.ssl.<component>.protocols} property
|
||||
* or the {@literal spring.data.gemfire.security.ssl.protocols} property
|
||||
* Use the {@literal spring.data.gemfire.security.ssl.protocols} property
|
||||
* in {@literal application.properties}.
|
||||
*/
|
||||
String protocols() default "any";
|
||||
String[] protocols() default { "any" };
|
||||
|
||||
/**
|
||||
* Boolean value indicating whether to require authentication for SSL communication between peers,
|
||||
* clients and servers, gateways, etc.
|
||||
* Boolean value indicating whether to require authentication for SSL communication between clients, servers,
|
||||
* gateways, etc.
|
||||
*
|
||||
* Defaults to {@literal true}.
|
||||
*
|
||||
* Use either the {@literal spring.data.gemfire.security.ssl.<component>.require-authentication} property
|
||||
* or the {@literal spring.data.gemfire.security.ssl.require-authentication} property
|
||||
* Use the {@literal spring.data.gemfire.security.ssl.require-authentication} property
|
||||
* in {@literal application.properties}.
|
||||
*/
|
||||
boolean requireAuthentication() default true;
|
||||
|
||||
/**
|
||||
* Pathname to the truststore used in SSL communications.
|
||||
* Pathname to the truststore used for SSL communications.
|
||||
*
|
||||
* Defaults to unset.
|
||||
*
|
||||
* Use either the {@literal spring.data.gemfire.security.ssl.<component>.truststore} property
|
||||
* or the {@literal spring.data.gemfire.security.ssl.truststore} property
|
||||
* Use the {@literal spring.data.gemfire.security.ssl.truststore} property
|
||||
* in {@literal application.properties}.
|
||||
*/
|
||||
String truststore() default "";
|
||||
|
||||
/**
|
||||
* Password to access the keys in the truststore used in SSL communications.
|
||||
* Password to access the keys in the truststore used for SSL communications.
|
||||
*
|
||||
* Defaults to unset.
|
||||
*
|
||||
* Use either the {@literal spring.data.gemfire.security.ssl.<component>.truststore-password} property
|
||||
* or the {@literal spring.data.gemfire.security.ssl.truststore-password} property
|
||||
* Use the {@literal spring.data.gemfire.security.ssl.truststore.password} property
|
||||
* in {@literal application.properties}.
|
||||
*/
|
||||
String truststorePassword() default "";
|
||||
|
||||
/**
|
||||
* Identifies the type of truststore used for SSL communications.
|
||||
*
|
||||
* For example: {@literal JKS}, {@literal PKCS11}, etc.
|
||||
*
|
||||
* Defaults to {@literal JKS}, or the {@literal Java Keystore}.
|
||||
*
|
||||
* Use the {@literal spring.data.gemfire.security.ssl.truststore.type} property
|
||||
* in {@literal application.properties}.
|
||||
*/
|
||||
String truststoreType() default "JKS";
|
||||
|
||||
/**
|
||||
* If {@literal true} then requires two-way authentication for web component.
|
||||
*
|
||||
* Defaults to {@literal false}.
|
||||
*
|
||||
* Use the {@literal spring.data.gemfire.security.ssl.web-require-authentication}
|
||||
* in {@literal application.properties}.
|
||||
*/
|
||||
boolean webRequireAuthentication() default false;
|
||||
|
||||
enum Component {
|
||||
|
||||
ALL("all"),
|
||||
CLUSTER("cluster"),
|
||||
GATEWAY("gateway"),
|
||||
HTTP("http-service"),
|
||||
JMX("jmx-manager"),
|
||||
JMX("jmx"),
|
||||
LOCATOR("locator"),
|
||||
SERVER("server");
|
||||
SERVER("server"),
|
||||
WEB("web");
|
||||
|
||||
public static Component valueOfName(String name) {
|
||||
|
||||
return Arrays.stream(values())
|
||||
.filter(component -> component.name().equalsIgnoreCase(String.valueOf(name).trim()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> newIllegalArgumentException("Name [%s] is not a valid component", name));
|
||||
}
|
||||
|
||||
private final String prefix;
|
||||
|
||||
/* (non-Javadoc) */
|
||||
Component(String prefix) {
|
||||
|
||||
Assert.hasText(prefix, "Prefix is required");
|
||||
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
@@ -174,7 +233,15 @@ public @interface EnableSsl {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return prefix;
|
||||
return this.prefix;
|
||||
}
|
||||
}
|
||||
|
||||
@interface ComponentAlias {
|
||||
|
||||
String alias();
|
||||
|
||||
Component component();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,24 +17,27 @@
|
||||
|
||||
package org.springframework.data.gemfire.config.annotation;
|
||||
|
||||
import static java.util.Arrays.stream;
|
||||
import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.data.gemfire.config.annotation.support.EmbeddedServiceConfigurationSupport;
|
||||
import org.springframework.data.gemfire.util.CollectionUtils;
|
||||
import org.springframework.data.gemfire.util.PropertiesBuilder;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* The {@link SslConfiguration} class is a Spring {@link ImportBeanDefinitionRegistrar} that applies
|
||||
* additional configuration using Pivotal GemFire/Apache Geode {@link Properties} to configure SSL.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.context.annotation.ImportBeanDefinitionRegistrar
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableSsl
|
||||
* @see org.springframework.data.gemfire.config.annotation.support.EmbeddedServiceConfigurationSupport
|
||||
* @since 1.9.0
|
||||
@@ -42,77 +45,114 @@ import org.springframework.util.ObjectUtils;
|
||||
public class SslConfiguration extends EmbeddedServiceConfigurationSupport {
|
||||
|
||||
/**
|
||||
* Returns the {@link EnableSsl} {@link java.lang.annotation.Annotation} {@link Class} type.
|
||||
* Returns the {@link EnableSsl} {@link Annotation} {@link Class type}.
|
||||
*
|
||||
* @return the {@link EnableSsl} {@link java.lang.annotation.Annotation} {@link Class} type.
|
||||
* @return the {@link EnableSsl} {@link Annotation} {@link Class type}.
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableSsl
|
||||
*/
|
||||
@Override
|
||||
protected Class getAnnotationType() {
|
||||
protected Class<? extends Annotation> getAnnotationType() {
|
||||
return EnableSsl.class;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
protected Properties toGemFireProperties(Map<String, Object> annotationAttributes) {
|
||||
protected Properties toGemFireProperties(Map<String, Object> annotationAttributesMap) {
|
||||
|
||||
AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(annotationAttributesMap);
|
||||
|
||||
PropertiesBuilder gemfireProperties = PropertiesBuilder.create();
|
||||
|
||||
EnableSsl.Component[] components = (EnableSsl.Component[]) annotationAttributes.get("components");
|
||||
Set<EnableSsl.Component> components = resolveComponents(annotationAttributes);
|
||||
|
||||
if (ObjectUtils.isEmpty(components)) {
|
||||
logWarning("SSL will not be configured; No SSL enabled Components %s were specified",
|
||||
Arrays.toString(EnableSsl.Component.values()));
|
||||
}
|
||||
gemfireProperties.setProperty("ssl-enabled-components",
|
||||
StringUtils.collectionToCommaDelimitedString(components.stream()
|
||||
.map(EnableSsl.Component::toString)
|
||||
.collect(Collectors.toSet())))
|
||||
|
||||
stream(nullSafeArray(components, EnableSsl.Component.class)).forEach(component ->
|
||||
.setProperty("ssl-ciphers", resolveProperty(sslProperty("ciphers"),
|
||||
StringUtils.arrayToCommaDelimitedString(annotationAttributes.getStringArray("ciphers"))))
|
||||
|
||||
gemfireProperties.setProperty(String.format("%s-ssl-ciphers", component),
|
||||
resolveProperty(componentSslProperty(component.toString(), "ciphers"),
|
||||
resolveProperty(sslProperty("ciphers"),
|
||||
(String) annotationAttributes.get("ciphers"))))
|
||||
.setPropertyIfNotDefault("ssl-default-alias",
|
||||
resolveProperty(sslProperty("certificate.alias.default"),
|
||||
annotationAttributes.getString("defaultCertificateAlias")), "")
|
||||
|
||||
.setProperty(String.format("%s-ssl-enabled", component),
|
||||
resolveProperty(componentSslProperty(component.toString(), "enabled"),
|
||||
resolveProperty(sslProperty("enabled"), true)))
|
||||
.setProperty("ssl-keystore", resolveProperty(sslProperty("keystore"),
|
||||
annotationAttributes.getString("keystore")))
|
||||
|
||||
.setProperty(String.format("%s-ssl-keystore", component),
|
||||
resolveProperty(componentSslProperty(component.toString(), "keystore"),
|
||||
resolveProperty(sslProperty("keystore"),
|
||||
(String) annotationAttributes.get("keystore"))))
|
||||
.setProperty("ssl-keystore-password", resolveProperty(sslProperty("keystore.password"),
|
||||
annotationAttributes.getString("keystorePassword")))
|
||||
|
||||
.setProperty(String.format("%s-ssl-keystore-password", component),
|
||||
resolveProperty(componentSslProperty(component.toString(), "keystore-password"),
|
||||
resolveProperty(sslProperty("keystore-password"),
|
||||
(String) annotationAttributes.get("keystorePassword"))))
|
||||
.setProperty("ssl-keystore-type", resolveProperty(sslProperty("keystore.type"),
|
||||
annotationAttributes.getString("keystoreType")))
|
||||
|
||||
.setProperty(String.format("%s-ssl-keystore-type", component),
|
||||
resolveProperty(componentSslProperty(component.toString(), "keystore-type"),
|
||||
resolveProperty(sslProperty("keystore-type"),
|
||||
(String) annotationAttributes.get("keystoreType"))))
|
||||
.setProperty("ssl-protocols", resolveProperty(sslProperty("protocols"),
|
||||
StringUtils.arrayToCommaDelimitedString(annotationAttributes.getStringArray("protocols"))))
|
||||
|
||||
.setProperty(String.format("%s-ssl-protocols", component),
|
||||
resolveProperty(componentSslProperty(component.toString(), "protocols"),
|
||||
resolveProperty(sslProperty("protocols"),
|
||||
(String) annotationAttributes.get("protocols"))))
|
||||
.setProperty("ssl-require-authentication",
|
||||
resolveProperty(sslProperty("require-authentication"),
|
||||
annotationAttributes.getBoolean("requireAuthentication")))
|
||||
|
||||
.setProperty(String.format("%s-ssl-require-authentication", component),
|
||||
resolveProperty(componentSslProperty(component.toString(), "require-authentication"),
|
||||
resolveProperty(sslProperty("require-authentication"),
|
||||
Boolean.TRUE.equals(annotationAttributes.get("requireAuthentication")))))
|
||||
.setProperty("ssl-truststore", resolveProperty(sslProperty("truststore"),
|
||||
annotationAttributes.getString("truststore")))
|
||||
|
||||
.setProperty(String.format("%s-ssl-truststore", component),
|
||||
resolveProperty(componentSslProperty(component.toString(), "truststore"),
|
||||
resolveProperty(sslProperty("truststore"),
|
||||
(String) annotationAttributes.get("truststore"))))
|
||||
.setProperty("ssl-truststore-password", resolveProperty(sslProperty("truststore.password"),
|
||||
annotationAttributes.getString("truststorePassword")))
|
||||
|
||||
.setProperty(String.format("%s-ssl-truststore-password", component),
|
||||
resolveProperty(componentSslProperty(component.toString(), "truststore-password"),
|
||||
resolveProperty(sslProperty("truststore-password"),
|
||||
(String) annotationAttributes.get("truststorePassword"))))
|
||||
.setProperty("ssl-truststore-type", resolveProperty(sslProperty("truststore.type"),
|
||||
annotationAttributes.getString("truststoreType")))
|
||||
|
||||
);
|
||||
.setProperty("ssl-web-require-authentication",
|
||||
resolveProperty(sslProperty("web-require-authentication"),
|
||||
annotationAttributes.getBoolean("webRequireAuthentication")));
|
||||
|
||||
configureComponentCertificateAliases(annotationAttributes, gemfireProperties);
|
||||
|
||||
return gemfireProperties.build();
|
||||
}
|
||||
|
||||
private Set<EnableSsl.Component> resolveComponents(AnnotationAttributes annotationAttributes) {
|
||||
|
||||
Set<EnableSsl.Component> components =
|
||||
Arrays.stream(Optional.of(resolveProperty(sslProperty("components"), ""))
|
||||
.filter(StringUtils::hasText)
|
||||
.map(StringUtils::commaDelimitedListToStringArray)
|
||||
.orElseGet(() -> new String[0]))
|
||||
.map(EnableSsl.Component::valueOfName)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
components = components.isEmpty()
|
||||
? CollectionUtils.asSet((EnableSsl.Component[]) annotationAttributes.get("components"))
|
||||
: components;
|
||||
|
||||
components = components.isEmpty() ? Collections.singleton(EnableSsl.Component.ALL) : components;
|
||||
|
||||
return components;
|
||||
}
|
||||
|
||||
private void configureComponentCertificateAliases(AnnotationAttributes annotationAttributes,
|
||||
PropertiesBuilder gemfireProperties) {
|
||||
|
||||
AnnotationAttributes[] componentCertificateAliases =
|
||||
annotationAttributes.getAnnotationArray("componentCertificateAliases");
|
||||
|
||||
Arrays.stream(componentCertificateAliases).forEach(aliasAttributes -> {
|
||||
|
||||
EnableSsl.Component component = aliasAttributes.getEnum("component");
|
||||
String alias = aliasAttributes.getString("alias");
|
||||
|
||||
gemfireProperties.setProperty(String.format("ssl-%s-alias", component), alias);
|
||||
});
|
||||
|
||||
Arrays.stream(EnableSsl.Component.values()).forEach(component -> {
|
||||
|
||||
String propertyNameSuffix = String.format("certificate.alias.%s", component);
|
||||
|
||||
Optional.ofNullable(resolveProperty(sslProperty(propertyNameSuffix), ""))
|
||||
.filter(StringUtils::hasText)
|
||||
.ifPresent(alias ->
|
||||
gemfireProperties.setProperty(String.format("ssl-%s-alias", component),
|
||||
StringUtils.trimWhitespace(alias)));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,7 +435,8 @@ public abstract class AbstractAnnotationConfigSupport
|
||||
* @see #getBeanClassLoader()
|
||||
*/
|
||||
protected ClassLoader resolveBeanClassLoader() {
|
||||
return Optional.ofNullable(getBeanClassLoader()).orElseGet(() -> Thread.currentThread().getContextClassLoader());
|
||||
return Optional.ofNullable(getBeanClassLoader())
|
||||
.orElseGet(() -> Thread.currentThread().getContextClassLoader());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -640,12 +641,10 @@ public abstract class AbstractAnnotationConfigSupport
|
||||
return beanDefinition;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected List<String> arrayOfPropertyNamesFor(String propertyNamePrefix) {
|
||||
return arrayOfPropertyNamesFor(propertyNamePrefix, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected List<String> arrayOfPropertyNamesFor(String propertyNamePrefix, String propertyNameSuffix) {
|
||||
|
||||
List<String> propertyNames = new ArrayList<>();
|
||||
@@ -666,139 +665,107 @@ public abstract class AbstractAnnotationConfigSupport
|
||||
return propertyNames;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String asArrayProperty(String propertyNamePrefix, int index, String propertyNameSuffix) {
|
||||
return String.format("%1$s[%2$d]%3$s", propertyNamePrefix, index,
|
||||
Optional.ofNullable(propertyNameSuffix).filter(StringUtils::hasText).map("."::concat).orElse(""));
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String cacheProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", propertyName("cache."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String cacheClientProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", propertyName("cache.client."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String cacheCompressionProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", propertyName("cache.compression."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String cacheOffHeapProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", propertyName("cache.off-heap."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String cachePeerProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", propertyName("cache.peer."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String cacheServerProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", propertyName("cache.server."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String namedCacheServerProperty(String name, String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s.%3$s", propertyName("cache.server."), name, propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String clusterProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", propertyName("cluster."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String diskStoreProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", propertyName("disk.store."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String namedDiskStoreProperty(String name, String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s.%3$s", propertyName("disk.store."), name, propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String entitiesProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", propertyName("entities."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String locatorProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", propertyName("locator."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String loggingProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", propertyName("logging."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String managementProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", propertyName("management."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String managerProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", propertyName("manager."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String pdxProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", propertyName("pdx."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String poolProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", propertyName("pool."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String namedPoolProperty(String name, String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s.%3$s", propertyName("pool."), name, propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String securityProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", propertyName("security."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String sslProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", securityProperty("ssl."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String componentSslProperty(String component, String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s.%3$s", securityProperty("ssl."),
|
||||
component, propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String statsProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", propertyName("stats."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String serviceProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", propertyName("service."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String redisServiceProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", serviceProperty("redis."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String memcachedServiceProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", serviceProperty("memcached."), propertyNameSuffix);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected String httpServiceProperty(String propertyNameSuffix) {
|
||||
return String.format("%1$s%2$s", serviceProperty("http."), propertyNameSuffix);
|
||||
}
|
||||
@@ -1056,8 +1023,12 @@ public abstract class AbstractAnnotationConfigSupport
|
||||
|
||||
return Optional.ofNullable(getEnvironment())
|
||||
.filter(environment -> environment.containsProperty(propertyName))
|
||||
.map(environment -> environment.getProperty(environment.resolveRequiredPlaceholders(propertyName),
|
||||
targetType, defaultValue))
|
||||
.map(environment -> {
|
||||
|
||||
String resolvedPropertyName = environment.resolveRequiredPlaceholders(propertyName);
|
||||
|
||||
return environment.getProperty(resolvedPropertyName, targetType, defaultValue);
|
||||
})
|
||||
.orElse(defaultValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,8 +38,6 @@ import org.springframework.util.StringUtils;
|
||||
@SuppressWarnings("unused")
|
||||
public class PropertiesBuilder implements FactoryBean<Properties> {
|
||||
|
||||
private final Properties properties;
|
||||
|
||||
/**
|
||||
* Factory method to create a default {@link PropertiesBuilder} instance.
|
||||
*
|
||||
@@ -73,13 +71,14 @@ public class PropertiesBuilder implements FactoryBean<Properties> {
|
||||
* @see java.util.Properties#load(InputStream)
|
||||
*/
|
||||
public static PropertiesBuilder from(InputStream in) {
|
||||
|
||||
try {
|
||||
Properties defaults = new Properties();
|
||||
defaults.load(in);
|
||||
return new PropertiesBuilder(defaults);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalArgumentException("Failed to read properties from InputStream", e);
|
||||
catch (IOException cause) {
|
||||
throw new IllegalArgumentException("Failed to read properties from InputStream", cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,13 +93,14 @@ public class PropertiesBuilder implements FactoryBean<Properties> {
|
||||
* @see java.util.Properties#load(Reader)
|
||||
*/
|
||||
public static PropertiesBuilder from(Reader reader) {
|
||||
|
||||
try {
|
||||
Properties defaults = new Properties();
|
||||
defaults.load(reader);
|
||||
return new PropertiesBuilder(defaults);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalArgumentException("Failed to read properties from Reader", e);
|
||||
catch (IOException cause) {
|
||||
throw new IllegalArgumentException("Failed to read properties from Reader", cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,16 +116,19 @@ public class PropertiesBuilder implements FactoryBean<Properties> {
|
||||
* @see java.util.Properties#loadFromXML(InputStream)
|
||||
*/
|
||||
public static PropertiesBuilder fromXml(InputStream xml) {
|
||||
|
||||
try {
|
||||
Properties defaults = new Properties();
|
||||
defaults.loadFromXML(xml);
|
||||
return new PropertiesBuilder(defaults);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalArgumentException("Failed to read properties from XML", e);
|
||||
catch (IOException cause) {
|
||||
throw new IllegalArgumentException("Failed to read properties from XML", cause);
|
||||
}
|
||||
}
|
||||
|
||||
private final Properties properties;
|
||||
|
||||
/**
|
||||
* Constructs an instance of the {@link PropertiesBuilder} class.
|
||||
*/
|
||||
@@ -172,7 +175,7 @@ public class PropertiesBuilder implements FactoryBean<Properties> {
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return (this.properties != null ? this.properties.getClass() : Properties.class);
|
||||
return this.properties != null ? this.properties.getClass() : Properties.class;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -193,6 +196,7 @@ public class PropertiesBuilder implements FactoryBean<Properties> {
|
||||
* @see java.util.Properties
|
||||
*/
|
||||
public PropertiesBuilder add(Properties properties) {
|
||||
|
||||
if (!CollectionUtils.isEmpty(properties)) {
|
||||
this.properties.putAll(properties);
|
||||
}
|
||||
@@ -209,7 +213,7 @@ public class PropertiesBuilder implements FactoryBean<Properties> {
|
||||
* @see org.springframework.data.gemfire.util.PropertiesBuilder
|
||||
*/
|
||||
public PropertiesBuilder add(PropertiesBuilder builder) {
|
||||
return (builder != null ? add(builder.build()) : this);
|
||||
return builder != null ? add(builder.build()) : this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -221,7 +225,7 @@ public class PropertiesBuilder implements FactoryBean<Properties> {
|
||||
* @see #setProperty(String, String)
|
||||
*/
|
||||
public PropertiesBuilder setProperty(String name, Object value) {
|
||||
return (value != null ? setProperty(name, value.toString()) : this);
|
||||
return value != null ? setProperty(name, value.toString()) : this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,8 +239,7 @@ public class PropertiesBuilder implements FactoryBean<Properties> {
|
||||
* @see #setProperty(String, String)
|
||||
*/
|
||||
public PropertiesBuilder setProperty(String name, Object[] values) {
|
||||
return (!ObjectUtils.isEmpty(values) ? setProperty(name, StringUtils.arrayToCommaDelimitedString(values))
|
||||
: this);
|
||||
return !ObjectUtils.isEmpty(values) ? setProperty(name, StringUtils.arrayToCommaDelimitedString(values)) : this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -251,6 +254,7 @@ public class PropertiesBuilder implements FactoryBean<Properties> {
|
||||
* @see java.util.Properties#setProperty(String, String)
|
||||
*/
|
||||
public PropertiesBuilder setProperty(String name, String value) {
|
||||
|
||||
Assert.hasText(name, String.format("Name [%s] must be specified", name));
|
||||
|
||||
if (isValuable(value)) {
|
||||
@@ -273,7 +277,7 @@ public class PropertiesBuilder implements FactoryBean<Properties> {
|
||||
* @see #setProperty(String, Object)
|
||||
*/
|
||||
public <T> PropertiesBuilder setPropertyIfNotDefault(String name, Object value, T defaultValue) {
|
||||
return (defaultValue == null || !defaultValue.equals(value) ? setProperty(name, value) : this);
|
||||
return defaultValue == null || !defaultValue.equals(value) ? setProperty(name, value) : this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -284,8 +288,11 @@ public class PropertiesBuilder implements FactoryBean<Properties> {
|
||||
* @throws IllegalArgumentException if the property name is not specified.
|
||||
*/
|
||||
public PropertiesBuilder unsetProperty(String name) {
|
||||
|
||||
Assert.hasText(name, String.format("Name [%s] mut be specified", name));
|
||||
|
||||
this.properties.setProperty(name, "");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -298,7 +305,7 @@ public class PropertiesBuilder implements FactoryBean<Properties> {
|
||||
* @return a boolean value indicating whether the given {@link String} value is a valid {@link Properties} value.
|
||||
*/
|
||||
protected boolean isValuable(String value) {
|
||||
return (StringUtils.hasText(value) && !"null".equalsIgnoreCase(value.trim()));
|
||||
return StringUtils.hasText(value) && !"null".equalsIgnoreCase(value.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,20 +42,20 @@ import org.springframework.data.gemfire.process.ProcessWrapper;
|
||||
import org.springframework.data.gemfire.test.support.FileSystemUtils;
|
||||
import org.springframework.data.gemfire.test.support.ThreadUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* The ClientCacheSecurityTest class is a test suite with test cases testing SSL configuration between a GemFire client
|
||||
* and server using the cluster-ssl-* GemFire System properties.
|
||||
* Integration tests to test SSL configuration between a Pivotal GemFire or Apache Geode client and server
|
||||
* using GemFire/Geode System properties.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
@SuppressWarnings("all")
|
||||
public class ClientCacheSecurityTest {
|
||||
@@ -67,6 +67,7 @@ public class ClientCacheSecurityTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() throws IOException {
|
||||
|
||||
String serverName = "GemFireSecurityCacheServer";
|
||||
|
||||
File serverWorkingDirectory = new File(FileSystemUtils.WORKING_DIRECTORY, serverName.toLowerCase());
|
||||
@@ -88,6 +89,7 @@ public class ClientCacheSecurityTest {
|
||||
}
|
||||
|
||||
private static void waitForServerStart(final long milliseconds) {
|
||||
|
||||
ThreadUtils.timedWait(milliseconds, TimeUnit.MILLISECONDS.toMillis(500), new ThreadUtils.WaitCondition() {
|
||||
private File serverPidControlFile = new File(serverProcess.getWorkingDirectory(),
|
||||
ServerProcess.getServerProcessControlFilename());
|
||||
@@ -100,6 +102,7 @@ public class ClientCacheSecurityTest {
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
|
||||
serverProcess.shutdown();
|
||||
|
||||
if (Boolean.valueOf(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) {
|
||||
@@ -115,12 +118,13 @@ public class ClientCacheSecurityTest {
|
||||
@SuppressWarnings("unused")
|
||||
public static class TestCacheLoader implements CacheLoader<String, String> {
|
||||
|
||||
@Override public String load(final LoaderHelper<String, String> helper) throws CacheLoaderException {
|
||||
@Override
|
||||
public String load(LoaderHelper<String, String> helper) throws CacheLoaderException {
|
||||
return "TestValue";
|
||||
}
|
||||
|
||||
@Override public void close() {
|
||||
}
|
||||
@Override
|
||||
public void close() { }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ public abstract class AbstractGeodeSecurityIntegrationTests extends ClientServer
|
||||
}
|
||||
}
|
||||
|
||||
@ClientCacheApplication(name = "GeodeSecurityIntegrationTestsClient", logLevel = TEST_GEMFIRE_LOG_LEVEL,
|
||||
@ClientCacheApplication(name = "GeodeSecurityIntegrationTestsClient", logLevel = "error",
|
||||
servers = { @ClientCacheApplication.Server(port = CACHE_SERVER_PORT) })
|
||||
@EnableAuth(clientAuthenticationInitializer =
|
||||
"org.springframework.data.gemfire.config.annotation.AbstractGeodeSecurityIntegrationTests$GeodeClientAuthInitialize.create")
|
||||
@@ -233,7 +233,7 @@ public abstract class AbstractGeodeSecurityIntegrationTests extends ClientServer
|
||||
}
|
||||
}
|
||||
|
||||
@CacheServerApplication(name = "GeodeSecurityIntegrationTestsServer", logLevel = TEST_GEMFIRE_LOG_LEVEL,
|
||||
@CacheServerApplication(name = "GeodeSecurityIntegrationTestsServer", logLevel = "error",
|
||||
port = CACHE_SERVER_PORT)
|
||||
@Import({
|
||||
ApacheShiroIniSecurityIntegrationTests.ApacheShiroIniConfiguration.class,
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config.annotation;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.geode.cache.CacheLoader;
|
||||
import org.apache.geode.cache.CacheLoaderException;
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.LoaderHelper;
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link ClientCacheApplication}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.GemFireCache
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
@SuppressWarnings("all")
|
||||
public class ClientCacheApplicationIntegrationTests {
|
||||
|
||||
@Resource(name = "Echo")
|
||||
private Region<String, String> echo;
|
||||
|
||||
@Test
|
||||
public void echoClientRegionEchoesKeysAsValues() {
|
||||
assertThat(this.echo.get("hello")).isEqualTo("hello");
|
||||
assertThat(this.echo.get("test")).isEqualTo("test");
|
||||
assertThat(this.echo.get("good-bye")).isEqualTo("good-bye");
|
||||
}
|
||||
|
||||
@ClientCacheApplication(name = "ClientCacheApplicationIntegrationTests", logLevel = "error")
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean("Echo")
|
||||
public ClientRegionFactoryBean<String, String> echoRegion(GemFireCache gemfireCache) {
|
||||
|
||||
ClientRegionFactoryBean<String, String> echoRegion = new ClientRegionFactoryBean<>();
|
||||
|
||||
echoRegion.setCache(gemfireCache);
|
||||
echoRegion.setCacheLoader(echoCacheLoader());
|
||||
echoRegion.setClose(false);
|
||||
echoRegion.setShortcut(ClientRegionShortcut.LOCAL);
|
||||
|
||||
return echoRegion;
|
||||
}
|
||||
|
||||
CacheLoader<String, String> echoCacheLoader() {
|
||||
|
||||
return new CacheLoader<String, String>() {
|
||||
|
||||
@Override
|
||||
public String load(LoaderHelper<String, String> helper) throws CacheLoaderException {
|
||||
return helper.getKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
|
||||
import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor;
|
||||
import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
@@ -86,14 +86,10 @@ public class ClientCacheConfigurerIntegrationTests {
|
||||
assertClientCacheConfigurerInvokedSuccessfully(this.configurerTwo, "gemfireCache");
|
||||
}
|
||||
|
||||
@ClientCacheApplication
|
||||
@EnableGemFireMockObjects
|
||||
@ClientCacheApplication(logLevel = "error")
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
GemfireTestBeanPostProcessor testBeanPostProcessor() {
|
||||
return new GemfireTestBeanPostProcessor();
|
||||
}
|
||||
|
||||
@Bean
|
||||
TestClientCacheConfigurer testClientCacheConfigurerOne() {
|
||||
return new TestClientCacheConfigurer();
|
||||
|
||||
@@ -42,8 +42,12 @@ import org.springframework.mock.env.MockPropertySource;
|
||||
* Integration tests for {@link ClientCacheApplication}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see java.util.Properties
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.core.env.PropertySource
|
||||
* @see org.springframework.data.gemfire.client.ClientCacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication
|
||||
* @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public class ClientCachePropertiesIntegrationTests {
|
||||
@@ -56,7 +60,7 @@ public class ClientCachePropertiesIntegrationTests {
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(PropertySource<?> testPropertySource,
|
||||
Class<?>... annotatedClasses) {
|
||||
Class<?>... annotatedClasses) {
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
||||
|
||||
@@ -64,8 +68,8 @@ public class ClientCachePropertiesIntegrationTests {
|
||||
|
||||
propertySources.addFirst(testPropertySource);
|
||||
|
||||
applicationContext.registerShutdownHook();
|
||||
applicationContext.register(annotatedClasses);
|
||||
applicationContext.registerShutdownHook();
|
||||
applicationContext.refresh();
|
||||
|
||||
return applicationContext;
|
||||
@@ -99,6 +103,8 @@ public class ClientCachePropertiesIntegrationTests {
|
||||
|
||||
ClientCache testClientCache = this.applicationContext.getBean("gemfireCache", ClientCache.class);
|
||||
|
||||
assertThat(testClientCache).isNotNull();
|
||||
|
||||
PdxSerializer mockPdxSerializer = this.applicationContext.getBean("mockPdxSerializer", PdxSerializer.class);
|
||||
|
||||
assertThat(mockPdxSerializer).isNotNull();
|
||||
@@ -271,8 +277,8 @@ public class ClientCachePropertiesIntegrationTests {
|
||||
}
|
||||
|
||||
@EnableGemFireMockObjects
|
||||
@EnablePdx(serializerBeanName = "mockPdxSerializer")
|
||||
@ClientCacheApplication(name = "TestClientCache")
|
||||
@EnablePdx(serializerBeanName = "mockPdxSerializer")
|
||||
@SuppressWarnings("unused")
|
||||
static class TestDynamicClientCacheConfiguration {
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Test suite of test cases testing the contract and functionality of the {@link CacheServerApplication}
|
||||
* and {@link ClientCacheApplication} SDG annotation for configuring and bootstrapping the Pivotal GemFire
|
||||
* client/server topology
|
||||
* and {@link ClientCacheApplication} SDG annotations for configuring and bootstrapping a Pivotal GemFire
|
||||
* or Apache Geode client/server topology
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
@@ -57,7 +57,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @since 1.9.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = ClientServerCacheApplicationIntegrationTests.ClientCacheApplicationConfiguration.class)
|
||||
@ContextConfiguration(classes = ClientServerCacheApplicationIntegrationTests.ClientTestConfiguration.class)
|
||||
@SuppressWarnings("all")
|
||||
public class ClientServerCacheApplicationIntegrationTests extends ClientServerIntegrationTestsSupport {
|
||||
|
||||
@@ -68,7 +68,7 @@ public class ClientServerCacheApplicationIntegrationTests extends ClientServerIn
|
||||
@BeforeClass
|
||||
public static void setupGemFireServer() throws Exception {
|
||||
|
||||
gemfireServerProcess = run(CacheServerApplicationConfiguration.class, String.format("-Dgemfire.name=%1$s",
|
||||
gemfireServerProcess = run(ServerTestConfiguration.class, String.format("-Dgemfire.name=%1$s",
|
||||
asApplicationName(ClientServerCacheApplicationIntegrationTests.class)));
|
||||
|
||||
waitForServerToStart("localhost", PORT);
|
||||
@@ -91,11 +91,28 @@ public class ClientServerCacheApplicationIntegrationTests extends ClientServerIn
|
||||
assertThat(echo.get("Test")).isEqualTo("Test");
|
||||
}
|
||||
|
||||
@CacheServerApplication(name = "ClientServerCacheApplicationIntegrationTests", logLevel = "warn", port = PORT)
|
||||
public static class CacheServerApplicationConfiguration {
|
||||
@ClientCacheApplication(logLevel = TEST_GEMFIRE_LOG_LEVEL, servers = { @ClientCacheApplication.Server(port = PORT)})
|
||||
static class ClientTestConfiguration {
|
||||
|
||||
@Bean(name = "Echo")
|
||||
ClientRegionFactoryBean<String, String> echoRegion(ClientCache gemfireCache) {
|
||||
|
||||
ClientRegionFactoryBean<String, String> echoRegion = new ClientRegionFactoryBean<String, String>();
|
||||
|
||||
echoRegion.setCache(gemfireCache);
|
||||
echoRegion.setClose(false);
|
||||
echoRegion.setShortcut(ClientRegionShortcut.PROXY);
|
||||
|
||||
return echoRegion;
|
||||
}
|
||||
}
|
||||
|
||||
@CacheServerApplication(name = "ClientServerCacheApplicationIntegrationTests",
|
||||
logLevel = TEST_GEMFIRE_LOG_LEVEL, port = PORT)
|
||||
public static class ServerTestConfiguration {
|
||||
|
||||
public static void main(String[] args) {
|
||||
runSpringApplication(CacheServerApplicationConfiguration.class, args);
|
||||
runSpringApplication(ServerTestConfiguration.class, args);
|
||||
}
|
||||
|
||||
@Bean("Echo")
|
||||
@@ -126,20 +143,4 @@ public class ClientServerCacheApplicationIntegrationTests extends ClientServerIn
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ClientCacheApplication(logLevel = "warn", servers = { @ClientCacheApplication.Server(port = PORT)})
|
||||
static class ClientCacheApplicationConfiguration {
|
||||
|
||||
@Bean(name = "Echo")
|
||||
ClientRegionFactoryBean<String, String> echoRegion(ClientCache gemfireCache) {
|
||||
|
||||
ClientRegionFactoryBean<String, String> echoRegion = new ClientRegionFactoryBean<String, String>();
|
||||
|
||||
echoRegion.setCache(gemfireCache);
|
||||
echoRegion.setClose(false);
|
||||
echoRegion.setShortcut(ClientRegionShortcut.PROXY);
|
||||
|
||||
return echoRegion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,8 +74,6 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
@SuppressWarnings("unused")
|
||||
public class EnableClusterConfigurationIntegrationTests extends ClientServerIntegrationTestsSupport {
|
||||
|
||||
private static final String LOG_LEVEL = "warning";
|
||||
|
||||
private static ProcessWrapper gemfireServer;
|
||||
|
||||
@Autowired
|
||||
@@ -88,7 +86,7 @@ public class EnableClusterConfigurationIntegrationTests extends ClientServerInte
|
||||
|
||||
int availablePort = findAvailablePort();
|
||||
|
||||
gemfireServer = run(GemFireServerConfiguration.class,
|
||||
gemfireServer = run(ServerTestConfiguration.class,
|
||||
String.format("-D%s=%d", GEMFIRE_CACHE_SERVER_PORT_PROPERTY, availablePort));
|
||||
|
||||
waitForServerToStart("localhost", availablePort);
|
||||
@@ -122,12 +120,12 @@ public class EnableClusterConfigurationIntegrationTests extends ClientServerInte
|
||||
|
||||
@Configuration
|
||||
@EnableClusterConfiguration
|
||||
@Import(GemFireClientConfiguration.class)
|
||||
@Import(ClientTestConfiguration.class)
|
||||
static class TestConfiguration {
|
||||
}
|
||||
|
||||
@ClientCacheApplication(logLevel = LOG_LEVEL, subscriptionEnabled = true)
|
||||
static class GemFireClientConfiguration {
|
||||
@ClientCacheApplication(logLevel = TEST_GEMFIRE_LOG_LEVEL, subscriptionEnabled = true)
|
||||
static class ClientTestConfiguration {
|
||||
|
||||
@Bean
|
||||
ClientCacheConfigurer clientCachePoolPortConfigurer(
|
||||
@@ -188,13 +186,13 @@ public class EnableClusterConfigurationIntegrationTests extends ClientServerInte
|
||||
}
|
||||
}
|
||||
|
||||
@CacheServerApplication(name = "EnableClusterConfigurationIntegrationTests", logLevel = LOG_LEVEL)
|
||||
static class GemFireServerConfiguration {
|
||||
@CacheServerApplication(name = "EnableClusterConfigurationIntegrationTests", logLevel = TEST_GEMFIRE_LOG_LEVEL)
|
||||
static class ServerTestConfiguration {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
|
||||
EnableClusterConfigurationIntegrationTests.GemFireServerConfiguration.class);
|
||||
AnnotationConfigApplicationContext applicationContext =
|
||||
new AnnotationConfigApplicationContext(ServerTestConfiguration.class);
|
||||
|
||||
applicationContext.registerShutdownHook();
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.data.gemfire.config.annotation;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.data.gemfire.util.ArrayUtils.asArray;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
@@ -30,7 +29,9 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects;
|
||||
import org.springframework.data.gemfire.util.ArrayUtils;
|
||||
import org.springframework.mock.env.MockPropertySource;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link EnableAuth}, {@link EnableGemFireProperties}, {@link EnableHttpService},
|
||||
@@ -57,7 +58,7 @@ public class EnableGemFirePropertiesIntegrationTests {
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(PropertySource<?> testPropertySource,
|
||||
Class<?>... annotatedClasses) {
|
||||
Class<?>... annotatedClasses) {
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
||||
|
||||
@@ -75,7 +76,7 @@ public class EnableGemFirePropertiesIntegrationTests {
|
||||
@Test
|
||||
public void authGemFirePropertiesConfiguration() {
|
||||
|
||||
MockPropertySource testPropertySource = new MockPropertySource()
|
||||
PropertySource testPropertySource = new MockPropertySource("TestPropertySource")
|
||||
.withProperty("spring.data.gemfire.security.client.accessor", "example.client.AccessController")
|
||||
.withProperty("spring.data.gemfire.security.client.accessor-post-processor", "example.client.AccessControllerPostProcessor")
|
||||
.withProperty("spring.data.gemfire.security.client.authentication-initializer", "example.client.AuthenticationInitializer")
|
||||
@@ -88,7 +89,8 @@ public class EnableGemFirePropertiesIntegrationTests {
|
||||
.withProperty("spring.data.gemfire.security.log.level", "info")
|
||||
.withProperty("spring.data.gemfire.security.properties-file", "/path/to/security.properties");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, TestAuthGemFirePropertiesConfiguration.class);
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestAuthGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
@@ -117,13 +119,14 @@ public class EnableGemFirePropertiesIntegrationTests {
|
||||
@Test
|
||||
public void httpGemFirePropertiesConfiguration() {
|
||||
|
||||
MockPropertySource testPropertySource = new MockPropertySource()
|
||||
PropertySource testPropertySource = new MockPropertySource("TestPropertySource")
|
||||
.withProperty("spring.data.gemfire.service.http.bind-address", "10.128.64.32")
|
||||
.withProperty("spring.data.gemfire.service.http.port", "8181")
|
||||
.withProperty("spring.data.gemfire.service.http.ssl-require-authentication", "true")
|
||||
.withProperty("spring.data.gemfire.service.http.dev-rest-api.start", "true");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, TestHttpGemFirePropertiesConfiguration.class);
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestHttpGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
@@ -145,11 +148,12 @@ public class EnableGemFirePropertiesIntegrationTests {
|
||||
@Test
|
||||
public void locatorGemFirePropertiesConfiguration() {
|
||||
|
||||
MockPropertySource testPropertySource = new MockPropertySource()
|
||||
PropertySource testPropertySource = new MockPropertySource("TestPropertySource")
|
||||
.withProperty("spring.data.gemfire.locator.host", "10.64.32.16")
|
||||
.withProperty("spring.data.gemfire.locator.port", "11235");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, TestLocatorGemFirePropertiesConfiguration.class);
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestLocatorGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
@@ -168,13 +172,14 @@ public class EnableGemFirePropertiesIntegrationTests {
|
||||
@Test
|
||||
public void loggingGemFirePropertiesConfiguration() {
|
||||
|
||||
MockPropertySource testPropertySource = new MockPropertySource()
|
||||
PropertySource testPropertySource = new MockPropertySource("TestPropertySource")
|
||||
.withProperty("spring.data.gemfire.logging.log-disk-space-limit", "100")
|
||||
.withProperty("spring.data.gemfire.logging.log-file", "/path/to/file.log")
|
||||
.withProperty("spring.data.gemfire.logging.log-file-size-limit", "10")
|
||||
.withProperty("spring.data.gemfire.logging.level", "info");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, TestLoggingGemFirePropertiesConfiguration.class);
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestLoggingGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
@@ -196,7 +201,7 @@ public class EnableGemFirePropertiesIntegrationTests {
|
||||
@Test
|
||||
public void managerGemFirePropertiesConfiguration() {
|
||||
|
||||
MockPropertySource testPropertySource = new MockPropertySource()
|
||||
PropertySource testPropertySource = new MockPropertySource("TestPropertySource")
|
||||
.withProperty("spring.data.gemfire.manager.access-file", "/path/to/access.control")
|
||||
.withProperty("spring.data.gemfire.manager.bind-address", "10.32.16.8")
|
||||
.withProperty("spring.data.gemfire.manager.hostname-for-clients", "skullbox")
|
||||
@@ -205,7 +210,8 @@ public class EnableGemFirePropertiesIntegrationTests {
|
||||
.withProperty("spring.data.gemfire.manager.start", "true")
|
||||
.withProperty("spring.data.gemfire.manager.update-rate", "1000");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, TestManagerGemFirePropertiesConfiguration.class);
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestManagerGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
@@ -231,11 +237,12 @@ public class EnableGemFirePropertiesIntegrationTests {
|
||||
@Test
|
||||
public void memcachedServerGemFirePropertiesConfiguration() {
|
||||
|
||||
MockPropertySource testPropertySource = new MockPropertySource()
|
||||
PropertySource testPropertySource = new MockPropertySource("TestPropertySource")
|
||||
.withProperty("spring.data.gemfire.service.memcached.port", "2468")
|
||||
.withProperty("spring.data.gemfire.service.memcached.protocol", "BINARY");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, TestMemcachedServerGemFirePropertiesConfiguration.class);
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestMemcachedServerGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
@@ -255,10 +262,11 @@ public class EnableGemFirePropertiesIntegrationTests {
|
||||
@Test
|
||||
public void offHeapGemFirePropertiesConfiguration() {
|
||||
|
||||
MockPropertySource testPropertySource = new MockPropertySource()
|
||||
PropertySource testPropertySource = new MockPropertySource("TestPropertySource")
|
||||
.withProperty("spring.data.gemfire.cache.off-heap.memory-size", "1024g");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, TestOffHeapGemFirePropertiesConfiguration.class);
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestOffHeapGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
@@ -277,11 +285,12 @@ public class EnableGemFirePropertiesIntegrationTests {
|
||||
@Test
|
||||
public void redisServerGemFirePropertiesConfiguration() {
|
||||
|
||||
MockPropertySource testPropertySource = new MockPropertySource()
|
||||
PropertySource testPropertySource = new MockPropertySource("TestPropertySource")
|
||||
.withProperty("spring.data.gemfire.service.redis.bind-address", "10.16.8.4")
|
||||
.withProperty("spring.data.gemfire.service.redis.port", "13579");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, TestRedisServerGemFirePropertiesConfiguration.class);
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestRedisServerGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
@@ -301,14 +310,15 @@ public class EnableGemFirePropertiesIntegrationTests {
|
||||
@Test
|
||||
public void securityGemFirePropertiesConfiguration() {
|
||||
|
||||
MockPropertySource testPropertySource = new MockPropertySource()
|
||||
PropertySource testPropertySource = new MockPropertySource("TestPropertySource")
|
||||
.withProperty("spring.data.gemfire.security.client.authentication-initializer", "example.security.client.AuthenticationInitializer")
|
||||
.withProperty("spring.data.gemfire.security.peer.authentication-initializer", "example.security.peer.AuthenticationInitializer")
|
||||
.withProperty("spring.data.gemfire.security.manager.class-name", "example.security.SecurityManager")
|
||||
.withProperty("spring.data.gemfire.security.postprocessor.class-name", "example.security.PostProcessor")
|
||||
.withProperty("spring.data.gemfire.security.shiro.ini-resource-path", "/path/to/shiro.ini");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, TestSecurityGemFirePropertiesConfiguration.class);
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestSecurityGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
@@ -331,68 +341,25 @@ public class EnableGemFirePropertiesIntegrationTests {
|
||||
@Test
|
||||
public void sslGemFirePropertiesConfiguration() {
|
||||
|
||||
MockPropertySource testPropertySource = new MockPropertySource()
|
||||
.withProperty("spring.data.gemfire.security.ssl.ciphers", "DSA")
|
||||
PropertySource testPropertySource = new MockPropertySource("TestPropertySource")
|
||||
.withProperty("spring.data.gemfire.security.ssl.ciphers", "DSA, RSA")
|
||||
.withProperty("spring.data.gemfire.security.ssl.certificate.alias.default", "TestCert")
|
||||
.withProperty("spring.data.gemfire.security.ssl.keystore", "/path/to/keystore")
|
||||
.withProperty("spring.data.gemfire.security.ssl.keystore-password", "p@55w0rd")
|
||||
.withProperty("spring.data.gemfire.security.ssl.keystore-type", "JKS")
|
||||
.withProperty("spring.data.gemfire.security.ssl.protocols", "TLS")
|
||||
.withProperty("spring.data.gemfire.security.ssl.keystore.password", "p@55w0rd")
|
||||
.withProperty("spring.data.gemfire.security.ssl.keystore.type", "JKS")
|
||||
.withProperty("spring.data.gemfire.security.ssl.protocols", "IP, TCP/IP, UDP")
|
||||
.withProperty("spring.data.gemfire.security.ssl.require-authentication", "false")
|
||||
.withProperty("spring.data.gemfire.security.ssl.truststore", "/path/to/truststore")
|
||||
.withProperty("spring.data.gemfire.security.ssl.truststore-password", "p@55w0rd")
|
||||
.withProperty("spring.data.gemfire.security.ssl.cluster.ciphers", "RSA")
|
||||
.withProperty("spring.data.gemfire.security.ssl.cluster.keystore", "/path/to/cluster/keystore")
|
||||
.withProperty("spring.data.gemfire.security.ssl.cluster.keystore-password", "clusterP@55w0rd")
|
||||
.withProperty("spring.data.gemfire.security.ssl.cluster.keystore-type", "PKCS11")
|
||||
.withProperty("spring.data.gemfire.security.ssl.cluster.protocols", "TLS")
|
||||
.withProperty("spring.data.gemfire.security.ssl.cluster.require-authentication", "true")
|
||||
.withProperty("spring.data.gemfire.security.ssl.cluster.truststore", "/path/to/cluster/truststore")
|
||||
.withProperty("spring.data.gemfire.security.ssl.cluster.truststore-password", "clusterP@55w0rd")
|
||||
.withProperty("spring.data.gemfire.security.ssl.gateway.ciphers", "AES")
|
||||
.withProperty("spring.data.gemfire.security.ssl.gateway.keystore", "/path/to/gateway/keystore")
|
||||
.withProperty("spring.data.gemfire.security.ssl.gateway.keystore-password", "gatewayP@55w0rd")
|
||||
.withProperty("spring.data.gemfire.security.ssl.gateway.keystore-type", "PKCS11")
|
||||
.withProperty("spring.data.gemfire.security.ssl.gateway.protocols", "TLS")
|
||||
.withProperty("spring.data.gemfire.security.ssl.gateway.require-authentication", "true")
|
||||
.withProperty("spring.data.gemfire.security.ssl.gateway.truststore", "/path/to/gateway/truststore")
|
||||
.withProperty("spring.data.gemfire.security.ssl.gateway.truststore-password", "gatewayP@55w0rd")
|
||||
.withProperty("spring.data.gemfire.security.ssl.http-service.ciphers", "DES")
|
||||
.withProperty("spring.data.gemfire.security.ssl.http-service.keystore", "/path/to/http/keystore")
|
||||
.withProperty("spring.data.gemfire.security.ssl.http-service.keystore-password", "httpP@55w0rd")
|
||||
.withProperty("spring.data.gemfire.security.ssl.http-service.keystore-type", "JKS")
|
||||
.withProperty("spring.data.gemfire.security.ssl.http-service.protocols", "TLS")
|
||||
.withProperty("spring.data.gemfire.security.ssl.http-service.require-authentication", "true")
|
||||
.withProperty("spring.data.gemfire.security.ssl.http-service.truststore", "/path/to/http/truststore")
|
||||
.withProperty("spring.data.gemfire.security.ssl.http-service.truststore-password", "httpP@55w0rd")
|
||||
.withProperty("spring.data.gemfire.security.ssl.jmx-manager.ciphers", "RC4")
|
||||
.withProperty("spring.data.gemfire.security.ssl.jmx-manager.keystore", "/path/to/jmx/keystore")
|
||||
.withProperty("spring.data.gemfire.security.ssl.jmx-manager.keystore-password", "jmxP@55w0rd")
|
||||
.withProperty("spring.data.gemfire.security.ssl.jmx-manager.keystore-type", "PKCS11")
|
||||
.withProperty("spring.data.gemfire.security.ssl.jmx-manager.protocols", "TLS")
|
||||
.withProperty("spring.data.gemfire.security.ssl.jmx-manager.require-authentication", "true")
|
||||
.withProperty("spring.data.gemfire.security.ssl.jmx-manager.truststore", "/path/to/jmx/truststore")
|
||||
.withProperty("spring.data.gemfire.security.ssl.jmx-manager.truststore-password", "jmxP@55w0rd")
|
||||
.withProperty("spring.data.gemfire.security.ssl.locator.ciphers", "IDEA")
|
||||
.withProperty("spring.data.gemfire.security.ssl.locator.keystore", "/path/to/locator/keystore")
|
||||
.withProperty("spring.data.gemfire.security.ssl.locator.keystore-password", "locatorP@55w0rd")
|
||||
.withProperty("spring.data.gemfire.security.ssl.locator.keystore-type", "PKCS11")
|
||||
.withProperty("spring.data.gemfire.security.ssl.locator.protocols", "TLS")
|
||||
.withProperty("spring.data.gemfire.security.ssl.locator.require-authentication", "true")
|
||||
.withProperty("spring.data.gemfire.security.ssl.locator.truststore", "/path/to/locator/truststore")
|
||||
.withProperty("spring.data.gemfire.security.ssl.locator.truststore-password", "locatorP@55w0rd")
|
||||
.withProperty("spring.data.gemfire.security.ssl.server.ciphers", "TSA")
|
||||
.withProperty("spring.data.gemfire.security.ssl.server.keystore", "/path/to/server/keystore")
|
||||
.withProperty("spring.data.gemfire.security.ssl.server.keystore-password", "serverP@55w0rd")
|
||||
.withProperty("spring.data.gemfire.security.ssl.server.keystore-type", "PKCS11")
|
||||
.withProperty("spring.data.gemfire.security.ssl.server.protocols", "TLS")
|
||||
.withProperty("spring.data.gemfire.security.ssl.server.require-authentication", "true")
|
||||
.withProperty("spring.data.gemfire.security.ssl.server.truststore", "/path/to/server/truststore")
|
||||
.withProperty("spring.data.gemfire.security.ssl.server.truststore-password", "serverP@55w0rd");
|
||||
.withProperty("spring.data.gemfire.security.ssl.truststore.password", "p@55w0rd")
|
||||
.withProperty("spring.data.gemfire.security.ssl.truststore.type", "PKCS11")
|
||||
.withProperty("spring.data.gemfire.security.ssl.web-require-authentication", "true");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, TestSslGemFirePropertiesConfiguration.class);
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestSslGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(this.applicationContext.containsBean("gemfireProperties")).isTrue();
|
||||
|
||||
GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
@@ -401,123 +368,24 @@ public class EnableGemFirePropertiesIntegrationTests {
|
||||
|
||||
Properties gemfireProperties = gemfireCache.getDistributedSystem().getProperties();
|
||||
|
||||
assertThat(gemfireProperties).isNotNull();
|
||||
assertThat(gemfireProperties.contains("ssl-ciphers")).isFalse();
|
||||
assertThat(gemfireProperties.contains("ssl-keystore")).isFalse();
|
||||
assertThat(gemfireProperties.contains("ssl-keystore-password")).isFalse();
|
||||
assertThat(gemfireProperties.contains("ssl-keystore-type")).isFalse();
|
||||
assertThat(gemfireProperties.contains("ssl-protocols")).isFalse();
|
||||
assertThat(gemfireProperties.contains("ssl-require-authentication")).isFalse();
|
||||
assertThat(gemfireProperties.contains("ssl-truststore")).isFalse();
|
||||
assertThat(gemfireProperties.contains("ssl-truststore-password")).isFalse();
|
||||
assertThat(gemfireProperties.getProperty("cluster-ssl-ciphers")).isEqualTo("RSA");
|
||||
assertThat(gemfireProperties.getProperty("cluster-ssl-keystore")).isEqualTo("/path/to/cluster/keystore");
|
||||
assertThat(gemfireProperties.getProperty("cluster-ssl-keystore-password")).isEqualTo("clusterP@55w0rd");
|
||||
assertThat(gemfireProperties.getProperty("cluster-ssl-keystore-type")).isEqualTo("PKCS11");
|
||||
assertThat(gemfireProperties.getProperty("cluster-ssl-protocols")).isEqualTo("TLS");
|
||||
assertThat(gemfireProperties.getProperty("cluster-ssl-require-authentication")).isEqualTo("true");
|
||||
assertThat(gemfireProperties.getProperty("cluster-ssl-truststore")).isEqualTo("/path/to/cluster/truststore");
|
||||
assertThat(gemfireProperties.getProperty("cluster-ssl-truststore-password")).isEqualTo("clusterP@55w0rd");
|
||||
assertThat(gemfireProperties.getProperty("gateway-ssl-ciphers")).isEqualTo("AES");
|
||||
assertThat(gemfireProperties.getProperty("gateway-ssl-keystore")).isEqualTo("/path/to/gateway/keystore");
|
||||
assertThat(gemfireProperties.getProperty("gateway-ssl-keystore-password")).isEqualTo("gatewayP@55w0rd");
|
||||
assertThat(gemfireProperties.getProperty("gateway-ssl-keystore-type")).isEqualTo("PKCS11");
|
||||
assertThat(gemfireProperties.getProperty("gateway-ssl-protocols")).isEqualTo("TLS");
|
||||
assertThat(gemfireProperties.getProperty("gateway-ssl-require-authentication")).isEqualTo("true");
|
||||
assertThat(gemfireProperties.getProperty("gateway-ssl-truststore")).isEqualTo("/path/to/gateway/truststore");
|
||||
assertThat(gemfireProperties.getProperty("gateway-ssl-truststore-password")).isEqualTo("gatewayP@55w0rd");
|
||||
assertThat(gemfireProperties.getProperty("http-service-ssl-ciphers")).isEqualTo("DES");
|
||||
assertThat(gemfireProperties.getProperty("http-service-ssl-keystore")).isEqualTo("/path/to/http/keystore");
|
||||
assertThat(gemfireProperties.getProperty("http-service-ssl-keystore-password")).isEqualTo("httpP@55w0rd");
|
||||
assertThat(gemfireProperties.getProperty("http-service-ssl-keystore-type")).isEqualTo("JKS");
|
||||
assertThat(gemfireProperties.getProperty("http-service-ssl-protocols")).isEqualTo("TLS");
|
||||
assertThat(gemfireProperties.getProperty("http-service-ssl-require-authentication")).isEqualTo("true");
|
||||
assertThat(gemfireProperties.getProperty("http-service-ssl-truststore")).isEqualTo("/path/to/http/truststore");
|
||||
assertThat(gemfireProperties.getProperty("http-service-ssl-truststore-password")).isEqualTo("httpP@55w0rd");
|
||||
assertThat(gemfireProperties.getProperty("jmx-manager-ssl-ciphers")).isEqualTo("RC4");
|
||||
assertThat(gemfireProperties.getProperty("jmx-manager-ssl-keystore")).isEqualTo("/path/to/jmx/keystore");
|
||||
assertThat(gemfireProperties.getProperty("jmx-manager-ssl-keystore-password")).isEqualTo("jmxP@55w0rd");
|
||||
assertThat(gemfireProperties.getProperty("jmx-manager-ssl-keystore-type")).isEqualTo("PKCS11");
|
||||
assertThat(gemfireProperties.getProperty("jmx-manager-ssl-protocols")).isEqualTo("TLS");
|
||||
assertThat(gemfireProperties.getProperty("jmx-manager-ssl-require-authentication")).isEqualTo("true");
|
||||
assertThat(gemfireProperties.getProperty("jmx-manager-ssl-truststore")).isEqualTo("/path/to/jmx/truststore");
|
||||
assertThat(gemfireProperties.getProperty("jmx-manager-ssl-truststore-password")).isEqualTo("jmxP@55w0rd");
|
||||
assertThat(gemfireProperties.getProperty("locator-ssl-ciphers")).isEqualTo("IDEA");
|
||||
assertThat(gemfireProperties.getProperty("locator-ssl-keystore")).isEqualTo("/path/to/locator/keystore");
|
||||
assertThat(gemfireProperties.getProperty("locator-ssl-keystore-password")).isEqualTo("locatorP@55w0rd");
|
||||
assertThat(gemfireProperties.getProperty("locator-ssl-keystore-type")).isEqualTo("PKCS11");
|
||||
assertThat(gemfireProperties.getProperty("locator-ssl-protocols")).isEqualTo("TLS");
|
||||
assertThat(gemfireProperties.getProperty("locator-ssl-require-authentication")).isEqualTo("true");
|
||||
assertThat(gemfireProperties.getProperty("locator-ssl-truststore")).isEqualTo("/path/to/locator/truststore");
|
||||
assertThat(gemfireProperties.getProperty("locator-ssl-truststore-password")).isEqualTo("locatorP@55w0rd");
|
||||
assertThat(gemfireProperties.getProperty("server-ssl-ciphers")).isEqualTo("TSA");
|
||||
assertThat(gemfireProperties.getProperty("server-ssl-keystore")).isEqualTo("/path/to/server/keystore");
|
||||
assertThat(gemfireProperties.getProperty("server-ssl-keystore-password")).isEqualTo("serverP@55w0rd");
|
||||
assertThat(gemfireProperties.getProperty("server-ssl-keystore-type")).isEqualTo("PKCS11");
|
||||
assertThat(gemfireProperties.getProperty("server-ssl-protocols")).isEqualTo("TLS");
|
||||
assertThat(gemfireProperties.getProperty("server-ssl-require-authentication")).isEqualTo("true");
|
||||
assertThat(gemfireProperties.getProperty("server-ssl-truststore")).isEqualTo("/path/to/server/truststore");
|
||||
assertThat(gemfireProperties.getProperty("server-ssl-truststore-password")).isEqualTo("serverP@55w0rd");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inheritedSslGemFirePropertiesConfiguration() {
|
||||
|
||||
MockPropertySource testPropertySource = new MockPropertySource()
|
||||
.withProperty("spring.data.gemfire.security.ssl.ciphers", "DSA")
|
||||
.withProperty("spring.data.gemfire.security.ssl.keystore", "/path/to/keystore")
|
||||
.withProperty("spring.data.gemfire.security.ssl.keystore-password", "p@55w0rd")
|
||||
.withProperty("spring.data.gemfire.security.ssl.keystore-type", "JKS")
|
||||
.withProperty("spring.data.gemfire.security.ssl.protocols", "TLS")
|
||||
.withProperty("spring.data.gemfire.security.ssl.require-authentication", "false")
|
||||
.withProperty("spring.data.gemfire.security.ssl.truststore", "/path/to/truststore")
|
||||
.withProperty("spring.data.gemfire.security.ssl.truststore-password", "p@55w0rd");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, TestInheritedSslGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
|
||||
GemFireCache gemfireCache = this.applicationContext.getBean("gemfireCache", GemFireCache.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getDistributedSystem()).isNotNull();
|
||||
|
||||
Properties gemfireProperties = gemfireCache.getDistributedSystem().getProperties();
|
||||
String sslEnabledComponents = Optional.ofNullable(gemfireProperties.getProperty("ssl-enabled-components"))
|
||||
.filter(StringUtils::hasText)
|
||||
.map(it -> StringUtils.arrayToCommaDelimitedString(ArrayUtils.sort(
|
||||
StringUtils.commaDelimitedListToStringArray(it))))
|
||||
.orElse(null);
|
||||
|
||||
assertThat(gemfireProperties).isNotNull();
|
||||
assertThat(gemfireProperties.contains("ssl-ciphers")).isFalse();
|
||||
assertThat(gemfireProperties.contains("ssl-keystore")).isFalse();
|
||||
assertThat(gemfireProperties.contains("ssl-keystore-password")).isFalse();
|
||||
assertThat(gemfireProperties.contains("ssl-keystore-type")).isFalse();
|
||||
assertThat(gemfireProperties.contains("ssl-protocols")).isFalse();
|
||||
assertThat(gemfireProperties.contains("ssl-require-authentication")).isFalse();
|
||||
assertThat(gemfireProperties.contains("ssl-truststore")).isFalse();
|
||||
assertThat(gemfireProperties.contains("ssl-truststore-password")).isFalse();
|
||||
|
||||
for (EnableSsl.Component component : asArray(EnableSsl.Component.CLUSTER, EnableSsl.Component.HTTP)) {
|
||||
assertThat(gemfireProperties.contains(String.format("%s-ssl-ciphers", component))).isFalse();
|
||||
assertThat(gemfireProperties.contains(String.format("%s-ssl-keystore", component))).isFalse();
|
||||
assertThat(gemfireProperties.contains(String.format("%s-ssl-keystore-password", component))).isFalse();
|
||||
assertThat(gemfireProperties.contains(String.format("%s-ssl-keystore-type", component))).isFalse();
|
||||
assertThat(gemfireProperties.contains(String.format("%s-ssl-protocols", component))).isFalse();
|
||||
assertThat(gemfireProperties.contains(String.format("%s-ssl-require-authentication", component))).isFalse();
|
||||
assertThat(gemfireProperties.contains(String.format("%s-ssl-truststore", component))).isFalse();
|
||||
assertThat(gemfireProperties.contains(String.format("%s-ssl-truststore-password", component))).isFalse();
|
||||
}
|
||||
|
||||
for (EnableSsl.Component component : asArray(EnableSsl.Component.GATEWAY, EnableSsl.Component.JMX,
|
||||
EnableSsl.Component.LOCATOR, EnableSsl.Component.SERVER)) {
|
||||
|
||||
assertThat(gemfireProperties.getProperty(String.format("%s-ssl-ciphers", component))).isEqualTo("DSA");
|
||||
assertThat(gemfireProperties.getProperty(String.format("%s-ssl-keystore", component))).isEqualTo("/path/to/keystore");
|
||||
assertThat(gemfireProperties.getProperty(String.format("%s-ssl-keystore-password", component))).isEqualTo("p@55w0rd");
|
||||
assertThat(gemfireProperties.getProperty(String.format("%s-ssl-keystore-type", component))).isEqualTo("JKS");
|
||||
assertThat(gemfireProperties.getProperty(String.format("%s-ssl-protocols", component))).isEqualTo("TLS");
|
||||
assertThat(gemfireProperties.getProperty(String.format("%s-ssl-require-authentication", component))).isEqualTo("false");
|
||||
assertThat(gemfireProperties.getProperty(String.format("%s-ssl-truststore", component))).isEqualTo("/path/to/truststore");
|
||||
assertThat(gemfireProperties.getProperty(String.format("%s-ssl-truststore-password", component))).isEqualTo("p@55w0rd");
|
||||
}
|
||||
assertThat(gemfireProperties.getProperty("ssl-ciphers")).isEqualTo("DSA, RSA");
|
||||
assertThat(sslEnabledComponents).isEqualTo("cluster,gateway,jmx,locator,server,web");
|
||||
assertThat(gemfireProperties.getProperty("ssl-default-alias")).isEqualTo("TestCert");
|
||||
assertThat(gemfireProperties.getProperty("ssl-keystore")).isEqualTo("/path/to/keystore");
|
||||
assertThat(gemfireProperties.getProperty("ssl-keystore-password")).isEqualTo("p@55w0rd");
|
||||
assertThat(gemfireProperties.getProperty("ssl-keystore-type")).isEqualTo("JKS");
|
||||
assertThat(gemfireProperties.getProperty("ssl-protocols")).isEqualTo("IP, TCP/IP, UDP");
|
||||
assertThat(gemfireProperties.getProperty("ssl-require-authentication")).isEqualTo("false");
|
||||
assertThat(gemfireProperties.getProperty("ssl-truststore")).isEqualTo("/path/to/truststore");
|
||||
assertThat(gemfireProperties.getProperty("ssl-truststore-password")).isEqualTo("p@55w0rd");
|
||||
assertThat(gemfireProperties.getProperty("ssl-truststore-type")).isEqualTo("PKCS11");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -530,7 +398,8 @@ public class EnableGemFirePropertiesIntegrationTests {
|
||||
.withProperty("spring.data.gemfire.stats.enable-time-statistics", "true")
|
||||
.withProperty("spring.data.gemfire.stats.sample-rate", "100");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, TestStatisticsGemFirePropertiesConfiguration.class);
|
||||
this.applicationContext =
|
||||
newApplicationContext(testPropertySource, TestStatisticsGemFirePropertiesConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
@@ -617,19 +486,16 @@ public class EnableGemFirePropertiesIntegrationTests {
|
||||
@EnableGemFireMockObjects
|
||||
@PeerCacheApplication
|
||||
@EnableGemFireProperties
|
||||
@EnableSsl(components = { EnableSsl.Component.CLUSTER, EnableSsl.Component.GATEWAY, EnableSsl.Component.HTTP,
|
||||
EnableSsl.Component.JMX, EnableSsl.Component.LOCATOR, EnableSsl.Component.SERVER })
|
||||
@EnableSsl(ciphers = "FISH", components = {
|
||||
EnableSsl.Component.CLUSTER, EnableSsl.Component.GATEWAY, EnableSsl.Component.JMX,
|
||||
EnableSsl.Component.LOCATOR, EnableSsl.Component.SERVER, EnableSsl.Component.WEB
|
||||
}, componentCertificateAliases = {
|
||||
@EnableSsl.ComponentAlias(component = EnableSsl.Component.GATEWAY, alias = "WanCert"),
|
||||
@EnableSsl.ComponentAlias(component = EnableSsl.Component.WEB, alias = "HttpCert")
|
||||
}, defaultCertificateAlias = "MockCert", protocols = "HTTP")
|
||||
static class TestSslGemFirePropertiesConfiguration {
|
||||
}
|
||||
|
||||
@EnableGemFireMockObjects
|
||||
@PeerCacheApplication
|
||||
@EnableGemFireProperties
|
||||
@EnableSsl(components = { EnableSsl.Component.GATEWAY, EnableSsl.Component.JMX, EnableSsl.Component.LOCATOR,
|
||||
EnableSsl.Component.SERVER })
|
||||
static class TestInheritedSslGemFirePropertiesConfiguration {
|
||||
}
|
||||
|
||||
@EnableGemFireMockObjects
|
||||
@PeerCacheApplication
|
||||
@EnableGemFireProperties
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config.annotation;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.geode.cache.CacheLoader;
|
||||
import org.apache.geode.cache.CacheLoaderException;
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.LoaderHelper;
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.process.ProcessWrapper;
|
||||
import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link EnableSsl} and {@link SslConfiguration}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableSsl
|
||||
* @see org.springframework.data.gemfire.config.annotation.SslConfiguration
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = EnableSslConfigurationIntegrationTests.ClientTestConfiguration.class)
|
||||
@SuppressWarnings("all")
|
||||
public class EnableSslConfigurationIntegrationTests extends ClientServerIntegrationTestsSupport {
|
||||
|
||||
private static final String LOG_LEVEL = "error";
|
||||
|
||||
private static ProcessWrapper gemfireServer;
|
||||
|
||||
@Resource(name = "Echo")
|
||||
private Region<String, String> echo;
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void setupGemFireServer() throws Exception {
|
||||
|
||||
String hostname = "localhost";
|
||||
|
||||
int availablePort = findAvailablePort();
|
||||
|
||||
gemfireServer = run(ServerTestConfiguration.class,
|
||||
String.format("-Dgemfire.name=%s", asApplicationName(EnableSslConfigurationIntegrationTests.class)),
|
||||
String.format("-Djavax.net.ssl.keyStore=%s", System.getProperty("javax.net.ssl.keyStore")),
|
||||
String.format("-D%s=%d", GEMFIRE_CACHE_SERVER_PORT_PROPERTY, availablePort));
|
||||
|
||||
waitForServerToStart("localhost", availablePort);
|
||||
|
||||
System.setProperty(GEMFIRE_CACHE_SERVER_PORT_PROPERTY, String.format("%s[%d]", hostname, availablePort));
|
||||
System.setProperty(GEMFIRE_POOL_SERVERS_PROPERTY, String.format("%s[%d]", hostname, availablePort));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownGemFireServer() {
|
||||
stop(gemfireServer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clientServerWithSslEnabledWorks() {
|
||||
assertThat(this.echo.get("testing123")).isEqualTo("testing123");
|
||||
}
|
||||
|
||||
@ClientCacheApplication(logLevel = LOG_LEVEL)
|
||||
@EnableSsl(keystorePassword = "s3cr3t", truststorePassword = "s3cr3t")
|
||||
static class ClientTestConfiguration {
|
||||
|
||||
@Bean
|
||||
ClientCacheConfigurer clientCacheSslConfigurer(
|
||||
@Value("${javax.net.ssl.keyStore:trusted.keystore}") String keystoreLocation) {
|
||||
|
||||
return (beanName, bean) -> {
|
||||
bean.getProperties().setProperty("ssl-keystore", keystoreLocation);
|
||||
bean.getProperties().setProperty("ssl-truststore", keystoreLocation);
|
||||
};
|
||||
}
|
||||
|
||||
@Bean("Echo")
|
||||
ClientRegionFactoryBean<String, String> echoRegion(GemFireCache gemfireCache) {
|
||||
|
||||
ClientRegionFactoryBean<String, String> echoRegion = new ClientRegionFactoryBean<>();
|
||||
|
||||
echoRegion.setCache(gemfireCache);
|
||||
echoRegion.setClose(false);
|
||||
echoRegion.setShortcut(ClientRegionShortcut.PROXY);
|
||||
|
||||
return echoRegion;
|
||||
}
|
||||
}
|
||||
|
||||
@CacheServerApplication(name = "EnableSslConfigurationIntegrationTests", logLevel = LOG_LEVEL)
|
||||
@EnableSsl(keystorePassword = "s3cr3t", truststorePassword = "s3cr3t")
|
||||
static class ServerTestConfiguration {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext =
|
||||
new AnnotationConfigApplicationContext(ServerTestConfiguration.class);
|
||||
|
||||
applicationContext.registerShutdownHook();
|
||||
}
|
||||
|
||||
@Bean
|
||||
PeerCacheConfigurer cacheServerSslConfigurer(
|
||||
@Value("${javax.net.ssl.keyStore:trusted.keystore}") String keystoreLocation) {
|
||||
|
||||
return (beanName, bean) -> {
|
||||
bean.getProperties().setProperty("ssl-keystore", keystoreLocation);
|
||||
bean.getProperties().setProperty("ssl-truststore", keystoreLocation);
|
||||
};
|
||||
}
|
||||
|
||||
@Bean("Echo")
|
||||
PartitionedRegionFactoryBean<String, String> echoRegion(GemFireCache gemfireCache) {
|
||||
|
||||
PartitionedRegionFactoryBean<String, String> echoRegion = new PartitionedRegionFactoryBean<>();
|
||||
|
||||
echoRegion.setCache(gemfireCache);
|
||||
echoRegion.setCacheLoader(echoCacheLoader());
|
||||
echoRegion.setClose(false);
|
||||
echoRegion.setPersistent(false);
|
||||
|
||||
return echoRegion;
|
||||
}
|
||||
|
||||
@Bean
|
||||
CacheLoader<String, String> echoCacheLoader() {
|
||||
|
||||
return new CacheLoader<String, String>() {
|
||||
|
||||
@Override
|
||||
public String load(LoaderHelper<String, String> helper) throws CacheLoaderException {
|
||||
return helper.getKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config.annotation;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
|
||||
import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockObjects;
|
||||
import org.springframework.data.gemfire.util.ArrayUtils;
|
||||
import org.springframework.mock.env.MockPropertySource;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link EnableSsl} and {@link SslConfiguration}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.GemFireCache
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableSsl
|
||||
* @see org.springframework.data.gemfire.config.annotation.SslConfiguration
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public class EnableSslConfigurationUnitTests {
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close);
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext newApplicationContext(PropertySource<?> testPropertySource,
|
||||
Class<?>... annotatedClasses) {
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
||||
|
||||
MutablePropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
|
||||
|
||||
propertySources.addFirst(testPropertySource);
|
||||
|
||||
applicationContext.register(annotatedClasses);
|
||||
applicationContext.registerShutdownHook();
|
||||
applicationContext.refresh();
|
||||
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sslAnnotationBasedConfigurationIsCorrect() {
|
||||
|
||||
this.applicationContext = newApplicationContext(new MockPropertySource("TestPropertySource"),
|
||||
SslAnnotationBasedConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache"));
|
||||
assertThat(this.applicationContext.containsBean("gemfireProperties"));
|
||||
|
||||
ClientCacheFactoryBean clientCache =
|
||||
this.applicationContext.getBean("&gemfireCache", ClientCacheFactoryBean.class);
|
||||
|
||||
assertThat(clientCache).isNotNull();
|
||||
|
||||
Properties gemfireProperties = clientCache.getProperties();
|
||||
|
||||
assertThat(gemfireProperties).isNotNull();
|
||||
assertThat(gemfireProperties.getProperty("ssl-ciphers")).isEqualTo("FISH,Scream,SEAL,SNOW");
|
||||
assertThat(gemfireProperties.getProperty("ssl-enabled-components")).isEqualTo("server,gateway");
|
||||
assertThat(gemfireProperties.getProperty("ssl-default-alias")).isEqualTo("TestCert");
|
||||
assertThat(gemfireProperties.getProperty("ssl-gateway-alias")).isEqualTo("WanCert");
|
||||
assertThat(gemfireProperties.getProperty("ssl-keystore")).isEqualTo("/path/to/keystore.jks");
|
||||
assertThat(gemfireProperties.getProperty("ssl-keystore-password")).isEqualTo("s3cr3t!");
|
||||
assertThat(gemfireProperties.getProperty("ssl-keystore-type")).isEqualTo("JKS");
|
||||
assertThat(gemfireProperties.getProperty("ssl-protocols")).isEqualTo("TCP/IP,HTTP");
|
||||
assertThat(gemfireProperties.getProperty("ssl-require-authentication")).isEqualTo("true");
|
||||
assertThat(gemfireProperties.getProperty("ssl-truststore")).isEqualTo("/path/to/truststore.jks");
|
||||
assertThat(gemfireProperties.getProperty("ssl-truststore-password")).isEqualTo("p@55w0rd!");
|
||||
assertThat(gemfireProperties.getProperty("ssl-truststore-type")).isEqualTo("PKCS11");
|
||||
assertThat(gemfireProperties.getProperty("ssl-web-require-authentication")).isEqualTo("true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sslPropertyBasedConfigurationIsCorrect() {
|
||||
|
||||
PropertySource testPropertySource = new MockPropertySource("TestPropertySource")
|
||||
.withProperty("spring.data.gemfire.security.ssl.ciphers", "Scream, SEAL, SNOW")
|
||||
.withProperty("spring.data.gemfire.security.ssl.components", "locator, server, gateway")
|
||||
.withProperty("spring.data.gemfire.security.ssl.certificate.alias.default", "MockCert")
|
||||
.withProperty("spring.data.gemfire.security.ssl.certificate.alias.gateway", "WanCert")
|
||||
.withProperty("spring.data.gemfire.security.ssl.certificate.alias.server", "ServerCert")
|
||||
.withProperty("spring.data.gemfire.security.ssl.keystore", "~/test/app/keystore.jks")
|
||||
.withProperty("spring.data.gemfire.security.ssl.keystore.password", "0p3nS@y5M3")
|
||||
.withProperty("spring.data.gemfire.security.ssl.keystore.type", "R2D2")
|
||||
.withProperty("spring.data.gemfire.security.ssl.protocols", "IP, TCP/IP, UDP")
|
||||
.withProperty("spring.data.gemfire.security.ssl.require-authentication", "false")
|
||||
.withProperty("spring.data.gemfire.security.ssl.truststore", "relative/path/to/trusted.keystore")
|
||||
.withProperty("spring.data.gemfire.security.ssl.truststore.password", "kn0ckKn0ck")
|
||||
.withProperty("spring.data.gemfire.security.ssl.truststore.type", "C3PO")
|
||||
.withProperty("spring.data.gemfire.security.ssl.web-require-authentication", "true");
|
||||
|
||||
this.applicationContext = newApplicationContext(testPropertySource, SslPropertyBasedConfiguration.class);
|
||||
|
||||
assertThat(this.applicationContext).isNotNull();
|
||||
assertThat(this.applicationContext.containsBean("gemfireCache"));
|
||||
assertThat(this.applicationContext.containsBean("gemfireProperties"));
|
||||
|
||||
ClientCacheFactoryBean clientCache =
|
||||
this.applicationContext.getBean("&gemfireCache", ClientCacheFactoryBean.class);
|
||||
|
||||
assertThat(clientCache).isNotNull();
|
||||
|
||||
Properties gemfireProperties = clientCache.getProperties();
|
||||
|
||||
String sslEnabledComponents = Optional.ofNullable(gemfireProperties.getProperty("ssl-enabled-components"))
|
||||
.filter(StringUtils::hasText)
|
||||
.map(it -> StringUtils.arrayToCommaDelimitedString(
|
||||
ArrayUtils.sort(StringUtils.commaDelimitedListToStringArray(it))))
|
||||
.orElse(null);
|
||||
|
||||
assertThat(gemfireProperties).isNotNull();
|
||||
assertThat(gemfireProperties.getProperty("ssl-ciphers")).isEqualTo("Scream, SEAL, SNOW");
|
||||
assertThat(sslEnabledComponents).isEqualTo("gateway,locator,server");
|
||||
assertThat(gemfireProperties.getProperty("ssl-default-alias")).isEqualTo("MockCert");
|
||||
assertThat(gemfireProperties.getProperty("ssl-gateway-alias")).isEqualTo("WanCert");
|
||||
assertThat(gemfireProperties.getProperty("ssl-server-alias")).isEqualTo("ServerCert");
|
||||
assertThat(gemfireProperties.getProperty("ssl-keystore")).isEqualTo("~/test/app/keystore.jks");
|
||||
assertThat(gemfireProperties.getProperty("ssl-keystore-password")).isEqualTo("0p3nS@y5M3");
|
||||
assertThat(gemfireProperties.getProperty("ssl-keystore-type")).isEqualTo("R2D2");
|
||||
assertThat(gemfireProperties.getProperty("ssl-protocols")).isEqualTo("IP, TCP/IP, UDP");
|
||||
assertThat(gemfireProperties.getProperty("ssl-require-authentication")).isEqualTo("false");
|
||||
assertThat(gemfireProperties.getProperty("ssl-truststore")).isEqualTo("relative/path/to/trusted.keystore");
|
||||
assertThat(gemfireProperties.getProperty("ssl-truststore-password")).isEqualTo("kn0ckKn0ck");
|
||||
assertThat(gemfireProperties.getProperty("ssl-truststore-type")).isEqualTo("C3PO");
|
||||
assertThat(gemfireProperties.getProperty("ssl-web-require-authentication")).isEqualTo("true");
|
||||
}
|
||||
|
||||
@EnableGemFireMockObjects
|
||||
@ClientCacheApplication(logLevel = "error")
|
||||
@EnableSsl(
|
||||
ciphers = { "FISH", "Scream", "SEAL", "SNOW" },
|
||||
components = { EnableSsl.Component.SERVER, EnableSsl.Component.GATEWAY },
|
||||
componentCertificateAliases = {
|
||||
@EnableSsl.ComponentAlias(component = EnableSsl.Component.GATEWAY, alias = "WanCert")
|
||||
},
|
||||
defaultCertificateAlias = "TestCert",
|
||||
keystore = "/path/to/keystore.jks",
|
||||
keystorePassword = "s3cr3t!",
|
||||
protocols = { "TCP/IP", "HTTP" },
|
||||
truststore = "/path/to/truststore.jks",
|
||||
truststorePassword = "p@55w0rd!",
|
||||
truststoreType = "PKCS11",
|
||||
webRequireAuthentication = true
|
||||
)
|
||||
static class SslAnnotationBasedConfiguration { }
|
||||
|
||||
@EnableGemFireMockObjects
|
||||
@ClientCacheApplication(logLevel = "error")
|
||||
@EnableSsl
|
||||
static class SslPropertyBasedConfiguration { }
|
||||
|
||||
}
|
||||
@@ -45,7 +45,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @since 1.9.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = PeerCacheApplicationIntegrationTests.PeerCacheApplicationConfiguration.class)
|
||||
@ContextConfiguration
|
||||
@SuppressWarnings("all")
|
||||
public class PeerCacheApplicationIntegrationTests {
|
||||
|
||||
@@ -54,11 +54,12 @@ public class PeerCacheApplicationIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void echoPartitionRegionEchoesKeysAsValues() {
|
||||
assertThat(echo.get("Hello")).isEqualTo("Hello");
|
||||
assertThat(echo.get("Test")).isEqualTo("Test");
|
||||
assertThat(this.echo.get("hello")).isEqualTo("hello");
|
||||
assertThat(this.echo.get("test")).isEqualTo("test");
|
||||
assertThat(this.echo.get("good-bye")).isEqualTo("good-bye");
|
||||
}
|
||||
|
||||
@PeerCacheApplication(name = "PeerCacheApplicationIntegrationTests", logLevel="warn")
|
||||
@PeerCacheApplication(name = "PeerCacheApplicationIntegrationTests", logLevel="error")
|
||||
static class PeerCacheApplicationConfiguration {
|
||||
|
||||
@Bean("Echo")
|
||||
|
||||
@@ -64,13 +64,15 @@ public class ClientServerIntegrationTestsSupport {
|
||||
protected static final String DEFAULT_HOSTNAME = "localhost";
|
||||
protected static final String DIRECTORY_DELETE_ON_EXIT_PROPERTY = "spring.data.gemfire.directory.delete-on-exit";
|
||||
protected static final String GEMFIRE_CACHE_SERVER_PORT_PROPERTY = "spring.data.gemfire.cache.server.port";
|
||||
protected static final String GEMFIRE_POOL_LOCATORS_PROPERTY = "spring.data.gemfire.pool.locators";
|
||||
protected static final String GEMFIRE_POOL_SERVERS_PROPERTY = "spring.data.gemfire.pool.servers";
|
||||
protected static final String GEMFIRE_LOG_FILE = "gemfire-server.log";
|
||||
protected static final String GEMFIRE_LOG_FILE_PROPERTY = "spring.data.gemfire.log.file";
|
||||
protected static final String GEMFIRE_LOG_LEVEL = "warning";
|
||||
protected static final String GEMFIRE_LOG_LEVEL = "error";
|
||||
protected static final String GEMFIRE_LOG_LEVEL_PROPERTY = "spring.data.gemfire.log.level";
|
||||
protected static final String PROCESS_RUN_MANUAL_PROPERTY = "spring.data.gemfire.process.run-manual";
|
||||
protected static final String SYSTEM_PROPERTIES_LOG_FILE = "system-properties.log";
|
||||
protected static final String TEST_GEMFIRE_LOG_LEVEL = "warning";
|
||||
protected static final String TEST_GEMFIRE_LOG_LEVEL = "error";
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected static String asApplicationName(Class<?> type) {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<util:properties id="clientProperties">
|
||||
<prop key="client.server.host">localhost</prop>
|
||||
<prop key="client.server.port">31517</prop>
|
||||
<prop key="gemfire.security.ssl.enabled">true</prop>
|
||||
<prop key="gemfire.security.ssl.components">all</prop>
|
||||
<prop key="gemfire.security.ssl.require-authentication">true</prop>
|
||||
<prop key="gemfire.security.ssl.protocols">any</prop>
|
||||
<prop key="gemfire.security.ssl.ciphers">any</prop>
|
||||
@@ -26,17 +26,17 @@
|
||||
<context:property-placeholder properties-ref="clientProperties" system-properties-mode="FALLBACK"/>
|
||||
|
||||
<util:properties id="gemfireProperties">
|
||||
<prop key="cluster-ssl-enabled">${gemfire.security.ssl.enabled}</prop>
|
||||
<prop key="cluster-ssl-require-authentication">${gemfire.security.ssl.require-authentication}</prop>
|
||||
<prop key="cluster-ssl-protocols">${gemfire.security.ssl.protocols}</prop>
|
||||
<prop key="cluster-ssl-ciphers">${gemfire.security.ssl.ciphers}</prop>
|
||||
<prop key="cluster-ssl-keystore">${gemfire.security.ssl.keystore.location}</prop>
|
||||
<prop key="cluster-ssl-keystore-password">${gemfire.security.ssl.keystore.password}</prop>
|
||||
<prop key="cluster-ssl-keystore-type">${gemfire.security.ssl.keystore.type}</prop>
|
||||
<prop key="cluster-ssl-truststore">${gemfire.security.ssl.keystore.location}</prop>
|
||||
<prop key="cluster-ssl-truststore-password">${gemfire.security.ssl.keystore.password}</prop>
|
||||
<prop key="log-level">warning</prop>
|
||||
<prop key="mcast-port">0</prop>
|
||||
<prop key="log-level">error</prop>
|
||||
<prop key="ssl-ciphers">${gemfire.security.ssl.ciphers}</prop>
|
||||
<prop key="ssl-enabled-components">${gemfire.security.ssl.components}</prop>
|
||||
<prop key="ssl-keystore">${gemfire.security.ssl.keystore.location}</prop>
|
||||
<prop key="ssl-keystore-password">${gemfire.security.ssl.keystore.password}</prop>
|
||||
<prop key="ssl-keystore-type">${gemfire.security.ssl.keystore.type}</prop>
|
||||
<prop key="ssl-protocols">${gemfire.security.ssl.protocols}</prop>
|
||||
<prop key="ssl-require-authentication">${gemfire.security.ssl.require-authentication}</prop>
|
||||
<prop key="ssl-truststore">${gemfire.security.ssl.keystore.location}</prop>
|
||||
<prop key="ssl-truststore-password">${gemfire.security.ssl.keystore.password}</prop>
|
||||
<prop key="ssl-truststore-type">${gemfire.security.ssl.keystore.type}</prop>
|
||||
</util:properties>
|
||||
|
||||
<gfe:pool id="gemfireServerPool" max-connections="1" min-connections="1">
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
">
|
||||
|
||||
<util:properties id="server.properties">
|
||||
<util:properties id="serverProperties">
|
||||
<prop key="gemfire.security.ssl.enabled">true</prop>
|
||||
<prop key="gemfire.security.ssl.require-authentication">true</prop>
|
||||
<prop key="gemfire.security.ssl.protocols">any</prop>
|
||||
@@ -23,12 +23,12 @@
|
||||
<prop key="gemfire.server.port">31517</prop>
|
||||
</util:properties>
|
||||
|
||||
<context:property-placeholder properties-ref="server.properties"/>
|
||||
<context:property-placeholder properties-ref="serverProperties"/>
|
||||
|
||||
<util:properties id="gemfireProperties">
|
||||
<prop key="name">ClientCacheSecurityTestServer</prop>
|
||||
<prop key="mcast-port">0</prop>
|
||||
<prop key="log-level">warning</prop>
|
||||
<prop key="log-level">error</prop>
|
||||
<prop key="cluster-ssl-enabled">${gemfire.security.ssl.enabled}</prop>
|
||||
<prop key="cluster-ssl-require-authentication">${gemfire.security.ssl.require-authentication}</prop>
|
||||
<prop key="cluster-ssl-protocols">${gemfire.security.ssl.protocols}</prop>
|
||||
|
||||
Reference in New Issue
Block a user