Пример #1
0
 /** 清除所有用户授权信息缓存. */
 public void clearAllCachedAuthorizationInfo() {
   Cache<Object, AuthorizationInfo> cache = getAuthorizationCache();
   if (cache != null) {
     for (Object key : cache.keys()) {
       cache.remove(key);
     }
   }
 }
Пример #2
0
 @Test
 public void testReplace() {
   String firstValue = "abc";
   String secondValue = "def";
   cache.put("123", firstValue);
   assertEquals(firstValue, cache.put("123", secondValue));
   assertEquals(secondValue, cache.get("123"));
 }
Пример #3
0
 @Test
 public void testRemove() {
   cache.put("1", "one");
   cache.put("2", "two");
   assertEquals(2, cache.size());
   cache.remove("1");
   assertEquals(1, cache.size());
   assertNull(cache.get("1"));
 }
Пример #4
0
 @Test
 public void testClear() {
   cache.put("1", "one");
   cache.put("2", "two");
   cache.put("3", "three");
   assertEquals(3, cache.size());
   cache.clear();
   assertEquals(0, cache.size());
 }
  @Override
  public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
    String username = (String) token.getPrincipal();
    AtomicInteger retryCount = passwordRetryCache.get(username);
    if (retryCount == null) {
      retryCount = new AtomicInteger(0);
      passwordRetryCache.put(username, retryCount);
    }
    if (retryCount.incrementAndGet() > 10) {
      throw new ExcessiveAttemptsException(String.valueOf(retryCount.get()));
    }

    boolean matches = super.doCredentialsMatch(token, info);
    if (matches) {
      passwordRetryCache.remove(username);
    }
    return matches;
  }
Пример #6
0
 // 删除所有菜单
 public void clearAllMenu() {
   Cache<Object, Object> cache = cacheManager.getCache(MENU_CACHE_KEY);
   cache.clear();
 }
Пример #7
0
 // 删除菜单
 public void clearMenu(Long roleId) {
   Cache<Object, Object> cache = cacheManager.getCache(MENU_CACHE_KEY);
   cache.remove(roleId);
 }
Пример #8
0
 // 菜单 cache
 public void putMenu(Long roleId, List<MenuView> list) {
   Cache<Object, Object> cache = cacheManager.getCache(MENU_CACHE_KEY);
   cache.put(roleId, list);
 }
Пример #9
0
 // 获取菜单
 public List<MenuView> getMenu(Long roleId) {
   Cache<Object, Object> cache = cacheManager.getCache(MENU_CACHE_KEY);
   return (List<MenuView>) cache.get(roleId);
 }
Пример #10
0
 @Test
 public void testSize() {
   assertEquals(0, cache.size());
   cache.put("123", "abc");
   assertEquals(1, cache.size());
 }
Пример #11
0
 @Test
 public void testGetExistentObject() {
   cache.put("123", "abc");
   assertEquals("abc", cache.get("123"));
 }
Пример #12
0
 @Test
 public void testGetNonexistentObject() {
   assertNull(cache.get("abc"));
 }
Пример #13
0
 @PreDestroy
 private void destroy() {
   Cache<Serializable, Session> cache = getActiveSessionsCache();
   cache.clear();
 }
 public void clearRetryCache(String username) {
   if (username == null) passwordRetryCache.clear();
   else passwordRetryCache.remove(username);
 }
 public int getRetryCount(String username) {
   AtomicInteger retryCount = passwordRetryCache.get(username);
   return retryCount != null ? retryCount.get() : 0;
 }