Search in sources :

Example 1 with EhCacheBasedUserCache

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();
}
Also used : EhCacheBasedUserCache(org.springframework.security.core.userdetails.cache.EhCacheBasedUserCache) ShaPasswordEncoder(org.springframework.security.authentication.encoding.ShaPasswordEncoder) Test(org.junit.Test)

Example 2 with EhCacheBasedUserCache

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();
}
Also used : EhCacheBasedUserCache(org.springframework.security.core.userdetails.cache.EhCacheBasedUserCache) Test(org.junit.Test)

Example 3 with EhCacheBasedUserCache

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);
}
Also used : EhCacheBasedUserCache(org.springframework.security.core.userdetails.cache.EhCacheBasedUserCache) Ehcache(net.sf.ehcache.Ehcache) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 EhCacheBasedUserCache (org.springframework.security.core.userdetails.cache.EhCacheBasedUserCache)3 Ehcache (net.sf.ehcache.Ehcache)1 ShaPasswordEncoder (org.springframework.security.authentication.encoding.ShaPasswordEncoder)1