Java Code Examples for org.apache.shiro.cache.Cache#clear()
The following examples show how to use
org.apache.shiro.cache.Cache#clear() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApiKeyRealmTest.java From emodb with Apache License 2.0 | 6 votes |
@Test public void simpleNewExists() { Cache<String, RolePermissionSet> cache = _underTest.getAvailableRolesCache(); assertEquals(cache.size(), 0, "precondition: cache is empty"); Permission p1 = mock(Permission.class); when(p1.toString()).thenReturn("p1"); when(_permissionManager.getPermissions(PermissionIDs.forRole("role"))).thenReturn(Sets.newHashSet(p1)); Collection<Permission> resultPerms = _underTest.getRolePermissions("role"); assertEquals(resultPerms.iterator().next(), p1, "should have the first permission we added"); assertEquals(cache.size(), 1, "side effect: cache has one element"); Permission p2 = mock(Permission.class); when(p2.toString()).thenReturn("p2"); when(_permissionManager.getPermissions(PermissionIDs.forRole("role"))).thenReturn(Sets.newHashSet(p2)); cache.clear(); Collection<Permission> resultPerms2 = _underTest.getRolePermissions("role"); assertEquals(resultPerms2.iterator().next(), p2, "should have the second permission we added"); assertEquals(cache.size(), 1, "side effect: cache still has one element"); resultPerms2 = _underTest.getRolePermissions("role"); assertEquals(resultPerms2.iterator().next(), p2, "should still have the second permission we added"); assertEquals(cache.size(), 1, "side effect: cache still has one element"); }
Example 2
Source File: ApiKeyRealmTest.java From emodb with Apache License 2.0 | 6 votes |
@Test public void simpleNowEmpty() { Cache<String, RolePermissionSet> cache = _underTest.getAvailableRolesCache(); assertEquals(cache.size(), 0, "precondition: cache is empty"); Permission p1 = mock(Permission.class); when(p1.toString()).thenReturn("p1"); when(_permissionManager.getPermissions(PermissionIDs.forRole("role"))).thenReturn(Sets.newHashSet(p1)); Collection<Permission> resultPerms = _underTest.getRolePermissions("role"); assertEquals(resultPerms.iterator().next(), p1, "should have the first permission we added"); assertEquals(cache.size(), 1, "side effect: cache has one element"); when(_permissionManager.getPermissions(PermissionIDs.forRole("role"))).thenReturn(Sets.<Permission>newHashSet()); cache.clear(); resultPerms = _underTest.getRolePermissions("role"); assertTrue(resultPerms.isEmpty(), "now should have empty"); assertEquals(cache.size(), 1, "side effect: cache has empty permission"); }
Example 3
Source File: ApiKeyRealmTest.java From emodb with Apache License 2.0 | 6 votes |
@Test public void pseudoConcurrentNewThenCacheFlush() { Cache<String, RolePermissionSet> cache = _underTest.getAvailableRolesCache(); assertEquals(cache.size(), 0, "precondition: cache is empty"); Permission p1 = mock(Permission.class); when(p1.toString()).thenReturn("p1"); Permission p2 = mock(Permission.class); when(p2.toString()).thenReturn("p2"); when(_permissionManager.getPermissions(PermissionIDs.forRole("role"))) .thenReturn(Sets.newHashSet(p1)) .thenReturn(Sets.newHashSet(p2)); Collection<Permission> resultPerms = _underTest.getRolePermissions("role"); assertEquals(resultPerms.iterator().next(), p1, "should have the last permission we added"); assertEquals(cache.size(), 1, "side effect: cache has one element"); cache.clear(); resultPerms = _underTest.getRolePermissions("role"); assertEquals(resultPerms.iterator().next(), p2, "should again have the last permission we added"); assertEquals(cache.size(), 1, "side effect: cache again has one element"); }
Example 4
Source File: RealmManagerImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
/** * Looks up registered {@link AuthenticatingRealm}s, and clears their authc caches if they have it set. */ private void clearAuthcRealmCaches() { // NOTE: we don't need to iterate all the Sec Managers, they use the same Realms, so one is fine. Collection<Realm> realms = realmSecurityManager.getRealms(); if (realms != null) { for (Realm realm : realms) { if (realm instanceof AuthenticatingRealm) { Cache<Object, AuthenticationInfo> cache = ((AuthenticatingRealm) realm).getAuthenticationCache(); if (cache != null) { log.debug("Clearing cache: {}", cache); cache.clear(); } } } } }
Example 5
Source File: RealmManagerImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
/** * Looks up registered {@link AuthorizingRealm}s, and clears their authz caches if they have it set. */ private void clearAuthzRealmCaches() { // NOTE: we don't need to iterate all the Sec Managers, they use the same Realms, so one is fine. Collection<Realm> realms = realmSecurityManager.getRealms(); if (realms != null) { for (Realm realm : realms) { if (realm instanceof AuthorizingRealm) { Cache<Object, AuthorizationInfo> cache = ((AuthorizingRealm) realm).getAuthorizationCache(); if (cache != null) { log.debug("Clearing cache: {}", cache); cache.clear(); } } } } }
Example 6
Source File: ShiroCacheUtils.java From jboot-admin with Apache License 2.0 | 4 votes |
public static void clearAuthorizationInfoAll() { Cache<Object, Object> cache = cacheManager.getCache(CacheKey.CACHE_SHIRO_AUTH); cache.clear(); }