Example usage for org.apache.shiro.realm CachingRealm getCacheManager

List of usage examples for org.apache.shiro.realm CachingRealm getCacheManager

Introduction

In this page you can find the example usage for org.apache.shiro.realm CachingRealm getCacheManager.

Prototype

public CacheManager getCacheManager() 

Source Link

Document

Returns the CacheManager used for data caching to reduce EIS round trips, or null if caching is disabled.

Usage

From source file:org.sonatype.security.web.WebRealmSecurityTest.java

License:Open Source License

public void testCacheManagerInit() throws Exception {
    // Start up security
    SecuritySystem securitySystem = this.lookup(SecuritySystem.class);
    RealmSecurityManager plexusSecurityManager = this.lookup(RealmSecurityManager.class, "default");

    List<String> realms = securitySystem.getRealms();
    realms.clear();//from  w  ww .j av a 2s .  com
    realms.add(SimpleAccountRealm.class.getName());
    securitySystem.setRealms(realms);

    // now if we grab one of the realms from the Realm locator, it should have its cache set
    CachingRealm cRealm1 = (CachingRealm) plexusSecurityManager.getRealms().iterator().next();
    Assert.assertNotNull("Realm has null cacheManager", cRealm1.getCacheManager());

    // // so far so good, the cacheManager should be set on all the child realms, but what if we add one after the
    // init method?
    realms.add(SimpleAccountRealm.class.getName());
    securitySystem.setRealms(realms);

    // this list should have exactly 2 elements
    Assert.assertEquals(2, plexusSecurityManager.getRealms().size());

    for (Realm realm : plexusSecurityManager.getRealms()) {
        Assert.assertNotNull("Realm has null cacheManager", ((CachingRealm) realm).getCacheManager());
    }
}