Example #1
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"));
 }
Example #2
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"));
 }
  @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;
  }
Example #4
0
 // 获取菜单
 public List<MenuView> getMenu(Long roleId) {
   Cache<Object, Object> cache = cacheManager.getCache(MENU_CACHE_KEY);
   return (List<MenuView>) cache.get(roleId);
 }
Example #5
0
 @Test
 public void testGetExistentObject() {
   cache.put("123", "abc");
   assertEquals("abc", cache.get("123"));
 }
Example #6
0
 @Test
 public void testGetNonexistentObject() {
   assertNull(cache.get("abc"));
 }
 public int getRetryCount(String username) {
   AtomicInteger retryCount = passwordRetryCache.get(username);
   return retryCount != null ? retryCount.get() : 0;
 }