DATAGEODE-111 - Add ability to configure SecurityManager on CacheFactoryBean.
This commit is contained in:
@@ -53,6 +53,7 @@ import org.apache.geode.internal.datasource.ConfigProperty;
|
||||
import org.apache.geode.internal.jndi.JNDIInvoker;
|
||||
import org.apache.geode.pdx.PdxSerializable;
|
||||
import org.apache.geode.pdx.PdxSerializer;
|
||||
import org.apache.geode.security.SecurityManager;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
@@ -159,6 +160,8 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport<GemFireCache>
|
||||
private String cacheResolutionMessagePrefix;
|
||||
private String pdxDiskStoreName;
|
||||
|
||||
private org.apache.geode.security.SecurityManager securityManager;
|
||||
|
||||
private TransactionWriter transactionWriter;
|
||||
|
||||
/**
|
||||
@@ -402,13 +405,13 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport<GemFireCache>
|
||||
* @see #configurePdx(CacheFactory)
|
||||
*/
|
||||
protected Object configureFactory(Object factory) {
|
||||
return configurePdx((CacheFactory) factory);
|
||||
return configureSecurity(configurePdx((CacheFactory) factory));
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure PDX for the given {@link CacheFactory}.
|
||||
* Configures PDX for this peer {@link Cache} instance.
|
||||
*
|
||||
* @param cacheFactory {@link CacheFactory} used to configure PDX.
|
||||
* @param cacheFactory {@link CacheFactory} used to configure the peer {@link Cache} with PDX.
|
||||
* @return the given {@link CacheFactory}.
|
||||
* @see org.apache.geode.cache.CacheFactory
|
||||
*/
|
||||
@@ -428,6 +431,20 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport<GemFireCache>
|
||||
return cacheFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures security for this peer {@link Cache} instance.
|
||||
*
|
||||
* @param cacheFactory {@link CacheFactory} used to configure the peer {@link Cache} with security.
|
||||
* @return the given {@link CacheFactory}.
|
||||
* @see org.apache.geode.cache.CacheFactory
|
||||
*/
|
||||
private CacheFactory configureSecurity(CacheFactory cacheFactory) {
|
||||
|
||||
Optional.ofNullable(getSecurityManager()).ifPresent(cacheFactory::setSecurityManager);
|
||||
|
||||
return cacheFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post processes the {@link CacheFactory} used to create the {@link Cache}.
|
||||
*
|
||||
@@ -1223,6 +1240,26 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport<GemFireCache>
|
||||
return searchTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the {@link org.apache.geode.security.SecurityManager} used to secure this cache.
|
||||
*
|
||||
* @param securityManager {@link org.apache.geode.security.SecurityManager} used to secure this cache.
|
||||
* @see org.apache.geode.security.SecurityManager
|
||||
*/
|
||||
public void setSecurityManager(SecurityManager securityManager) {
|
||||
this.securityManager = securityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link org.apache.geode.security.SecurityManager} used to secure this cache.
|
||||
*
|
||||
* @return the {@link org.apache.geode.security.SecurityManager} used to secure this cache.
|
||||
* @see org.apache.geode.security.SecurityManager
|
||||
*/
|
||||
public SecurityManager getSecurityManager() {
|
||||
return securityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the list of TransactionListeners used to configure the Cache to receive transaction events after
|
||||
* the transaction is processed (committed, rolled back).
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -444,7 +445,41 @@ public class CacheFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prepareFactoryWithUnspecifiedPdxOptions() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void initializesFactoryWitCacheFactoryInitializer() {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
CacheFactoryBean.CacheFactoryInitializer<Object> mockCacheFactoryInitializer =
|
||||
mock(CacheFactoryBean.CacheFactoryInitializer.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCacheFactoryInitializer(mockCacheFactoryInitializer);
|
||||
|
||||
assertThat(cacheFactoryBean.getCacheFactoryInitializer(), is(equalTo(mockCacheFactoryInitializer)));
|
||||
assertThat(cacheFactoryBean.initializeFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
|
||||
verify(mockCacheFactoryInitializer, times(1)).initialize(eq(mockCacheFactory));
|
||||
verifyZeroInteractions(mockCacheFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initializeFactoryWhenNoCacheFactoryInitializerIsPresentIsNullSafe() {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
assertThat(cacheFactoryBean.getCacheFactoryInitializer(),
|
||||
is(nullValue(CacheFactoryBean.CacheFactoryInitializer.class)));
|
||||
assertThat(cacheFactoryBean.initializeFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
|
||||
verifyZeroInteractions(mockCacheFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configureFactoryWithUnspecifiedPdxOptions() {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
@@ -458,7 +493,7 @@ public class CacheFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prepareFactoryWithSpecificPdxOptions() {
|
||||
public void configureFactoryWithSpecificPdxOptions() {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
@@ -478,7 +513,7 @@ public class CacheFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prepareFactoryWithAllPdxOptions() {
|
||||
public void configureFactoryWithAllPdxOptions() {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
@@ -499,6 +534,25 @@ public class CacheFactoryBeanTest {
|
||||
verify(mockCacheFactory, times(1)).setPdxSerializer(any(PdxSerializer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configureFactoryWithSecurityManager() {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
org.apache.geode.security.SecurityManager mockSecurityManager =
|
||||
mock(org.apache.geode.security.SecurityManager.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setSecurityManager(mockSecurityManager);
|
||||
|
||||
assertThat(cacheFactoryBean.getSecurityManager(), is(sameInstance(mockSecurityManager)));
|
||||
assertThat(cacheFactoryBean.configureFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
|
||||
verify(mockCacheFactory, times(1)).setSecurityManager(eq(mockSecurityManager));
|
||||
verifyZeroInteractions(mockSecurityManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createCacheWithCacheFactory() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user