Search in sources :

Example 1 with EhCacheBasedTicketCache

use of org.springframework.security.cas.authentication.EhCacheBasedTicketCache in project spring-security by spring-projects.

the class EhCacheBasedTicketCacheTests method testCacheOperation.

@Test
public void testCacheOperation() throws Exception {
    EhCacheBasedTicketCache cache = new EhCacheBasedTicketCache();
    cache.setCache(cacheManager.getCache("castickets"));
    cache.afterPropertiesSet();
    final CasAuthenticationToken token = getToken();
    // Check it gets stored in the cache
    cache.putTicketInCache(token);
    assertThat(cache.getByTicketId("ST-0-ER94xMJmn6pha35CQRoZ")).isEqualTo(token);
    // Check it gets removed from the cache
    cache.removeTicketFromCache(getToken());
    assertThat(cache.getByTicketId("ST-0-ER94xMJmn6pha35CQRoZ")).isNull();
    // Check it doesn't return values for null or unknown service tickets
    assertThat(cache.getByTicketId(null)).isNull();
    assertThat(cache.getByTicketId("UNKNOWN_SERVICE_TICKET")).isNull();
}
Also used : EhCacheBasedTicketCache(org.springframework.security.cas.authentication.EhCacheBasedTicketCache) CasAuthenticationToken(org.springframework.security.cas.authentication.CasAuthenticationToken) Test(org.junit.Test)

Example 2 with EhCacheBasedTicketCache

use of org.springframework.security.cas.authentication.EhCacheBasedTicketCache in project spring-security by spring-projects.

the class EhCacheBasedTicketCacheTests method testStartupDetectsMissingCache.

@Test
public void testStartupDetectsMissingCache() throws Exception {
    EhCacheBasedTicketCache cache = new EhCacheBasedTicketCache();
    try {
        cache.afterPropertiesSet();
        fail("Should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
    Ehcache myCache = cacheManager.getCache("castickets");
    cache.setCache(myCache);
    assertThat(cache.getCache()).isEqualTo(myCache);
}
Also used : EhCacheBasedTicketCache(org.springframework.security.cas.authentication.EhCacheBasedTicketCache) Ehcache(net.sf.ehcache.Ehcache) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 EhCacheBasedTicketCache (org.springframework.security.cas.authentication.EhCacheBasedTicketCache)2 Ehcache (net.sf.ehcache.Ehcache)1 CasAuthenticationToken (org.springframework.security.cas.authentication.CasAuthenticationToken)1