use of org.springframework.security.core.userdetails.cache.EhCacheBasedUserCache in project spring-security by spring-projects.
the class DaoAuthenticationProviderTests method testGettersSetters.
@Test
public void testGettersSetters() {
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
provider.setPasswordEncoder(new ShaPasswordEncoder());
assertThat(provider.getPasswordEncoder().getClass()).isEqualTo(ShaPasswordEncoder.class);
provider.setSaltSource(new SystemWideSaltSource());
assertThat(provider.getSaltSource().getClass()).isEqualTo(SystemWideSaltSource.class);
provider.setUserCache(new EhCacheBasedUserCache());
assertThat(provider.getUserCache().getClass()).isEqualTo(EhCacheBasedUserCache.class);
assertThat(provider.isForcePrincipalAsString()).isFalse();
provider.setForcePrincipalAsString(true);
assertThat(provider.isForcePrincipalAsString()).isTrue();
}
use of org.springframework.security.core.userdetails.cache.EhCacheBasedUserCache in project spring-security by spring-projects.
the class EhCacheBasedUserCacheTests method cacheOperationsAreSuccessful.
@Test
public void cacheOperationsAreSuccessful() throws Exception {
EhCacheBasedUserCache cache = new EhCacheBasedUserCache();
cache.setCache(getCache());
cache.afterPropertiesSet();
// Check it gets stored in the cache
cache.putUserInCache(getUser());
assertThat(getUser().getPassword()).isEqualTo(cache.getUserFromCache(getUser().getUsername()).getPassword());
// Check it gets removed from the cache
cache.removeUserFromCache(getUser());
assertThat(cache.getUserFromCache(getUser().getUsername())).isNull();
// Check it doesn't return values for null or unknown users
assertThat(cache.getUserFromCache(null)).isNull();
assertThat(cache.getUserFromCache("UNKNOWN_USER")).isNull();
}
use of org.springframework.security.core.userdetails.cache.EhCacheBasedUserCache in project spring-security by spring-projects.
the class EhCacheBasedUserCacheTests method startupDetectsMissingCache.
@Test(expected = IllegalArgumentException.class)
public void startupDetectsMissingCache() throws Exception {
EhCacheBasedUserCache cache = new EhCacheBasedUserCache();
cache.afterPropertiesSet();
fail("Should have thrown IllegalArgumentException");
Ehcache myCache = getCache();
cache.setCache(myCache);
assertThat(cache.getCache()).isEqualTo(myCache);
}
Aggregations