@Test void testGetReachableGrantedAuthoritiesWithCircularHierarchy() { TransactionSynchronizationManager.setCurrentTransactionReadOnly(true); GrantedAuthority managerAuthority = new SimpleGrantedAuthority("ROLE_MANAGER"); GrantedAuthority editorAuthority = new SimpleGrantedAuthority("ROLE_EDITOR"); GrantedAuthority circularAuthority = new SimpleGrantedAuthority("ROLE_CIRCULAR"); ImmutableMap<GrantedAuthority, ImmutableSet<GrantedAuthority>> authorityInclusions = ImmutableMap.<GrantedAuthority, ImmutableSet<GrantedAuthority>>builder() .put(managerAuthority, ImmutableSet.of(editorAuthority)) .put(editorAuthority, ImmutableSet.of(circularAuthority)) .put(circularAuthority, ImmutableSet.of(managerAuthority)) .build(); when(dataserviceRoleHierarchy.getAllGrantedAuthorityInclusions()) .thenReturn(authorityInclusions); assertEquals( ImmutableSet.of(managerAuthority, editorAuthority, circularAuthority), cachedRoleHierarchyImpl.getReachableGrantedAuthorities( asList(managerAuthority, editorAuthority))); }
@Override public Collection<? extends GrantedAuthority> getReachableGrantedAuthorities( Collection<? extends GrantedAuthority> authorities) { Collection<? extends GrantedAuthority> reachableGrantedAuthorities; if (authorities == null || authorities.isEmpty()) { reachableGrantedAuthorities = AuthorityUtils.NO_AUTHORITIES; } else { Boolean isCacheDirty = cacheDirty.get(); if (isCacheDirty == null || !isCacheDirty) { reachableGrantedAuthorities = getCachedReachableAuthorities(authorities); } else { reachableGrantedAuthorities = getPersistedReachableGrantedAuthorities(authorities); } } return reachableGrantedAuthorities; }
CachedRoleHierarchyImpl implements TransactionListener, CachedRoleHierarchy { @Override public Collection<? extends GrantedAuthority> getReachableGrantedAuthorities( Collection<? extends GrantedAuthority> authorities) { Collection<? extends GrantedAuthority> reachableGrantedAuthorities; if (authorities == null || authorities.isEmpty()) { reachableGrantedAuthorities = AuthorityUtils.NO_AUTHORITIES; } else { Boolean isCacheDirty = cacheDirty.get(); if (isCacheDirty == null || !isCacheDirty) { reachableGrantedAuthorities = getCachedReachableAuthorities(authorities); } else { reachableGrantedAuthorities = getPersistedReachableGrantedAuthorities(authorities); } } return reachableGrantedAuthorities; } }
CachedRoleHierarchyImpl implements TransactionListener, CachedRoleHierarchy { @Override public Collection<? extends GrantedAuthority> getReachableGrantedAuthorities( Collection<? extends GrantedAuthority> authorities) { Collection<? extends GrantedAuthority> reachableGrantedAuthorities; if (authorities == null || authorities.isEmpty()) { reachableGrantedAuthorities = AuthorityUtils.NO_AUTHORITIES; } else { Boolean isCacheDirty = cacheDirty.get(); if (isCacheDirty == null || !isCacheDirty) { reachableGrantedAuthorities = getCachedReachableAuthorities(authorities); } else { reachableGrantedAuthorities = getPersistedReachableGrantedAuthorities(authorities); } } return reachableGrantedAuthorities; } CachedRoleHierarchyImpl(
      DataserviceRoleHierarchy dataserviceRoleHierarchy, TransactionManager transactionManager); }
CachedRoleHierarchyImpl implements TransactionListener, CachedRoleHierarchy { @Override public Collection<? extends GrantedAuthority> getReachableGrantedAuthorities( Collection<? extends GrantedAuthority> authorities) { Collection<? extends GrantedAuthority> reachableGrantedAuthorities; if (authorities == null || authorities.isEmpty()) { reachableGrantedAuthorities = AuthorityUtils.NO_AUTHORITIES; } else { Boolean isCacheDirty = cacheDirty.get(); if (isCacheDirty == null || !isCacheDirty) { reachableGrantedAuthorities = getCachedReachableAuthorities(authorities); } else { reachableGrantedAuthorities = getPersistedReachableGrantedAuthorities(authorities); } } return reachableGrantedAuthorities; } CachedRoleHierarchyImpl(
      DataserviceRoleHierarchy dataserviceRoleHierarchy, TransactionManager transactionManager); @Override Collection<? extends GrantedAuthority> getReachableGrantedAuthorities(
      Collection<? extends GrantedAuthority> authorities); @Override void markRoleHierarchyCacheDirty(); @Override void transactionStarted(String transactionId); @Override void afterCommitTransaction(String transactionId); @Override void rollbackTransaction(String transactionId); @Override void doCleanupAfterCompletion(String transactionId); }
CachedRoleHierarchyImpl implements TransactionListener, CachedRoleHierarchy { @Override public Collection<? extends GrantedAuthority> getReachableGrantedAuthorities( Collection<? extends GrantedAuthority> authorities) { Collection<? extends GrantedAuthority> reachableGrantedAuthorities; if (authorities == null || authorities.isEmpty()) { reachableGrantedAuthorities = AuthorityUtils.NO_AUTHORITIES; } else { Boolean isCacheDirty = cacheDirty.get(); if (isCacheDirty == null || !isCacheDirty) { reachableGrantedAuthorities = getCachedReachableAuthorities(authorities); } else { reachableGrantedAuthorities = getPersistedReachableGrantedAuthorities(authorities); } } return reachableGrantedAuthorities; } CachedRoleHierarchyImpl(
      DataserviceRoleHierarchy dataserviceRoleHierarchy, TransactionManager transactionManager); @Override Collection<? extends GrantedAuthority> getReachableGrantedAuthorities(
      Collection<? extends GrantedAuthority> authorities); @Override void markRoleHierarchyCacheDirty(); @Override void transactionStarted(String transactionId); @Override void afterCommitTransaction(String transactionId); @Override void rollbackTransaction(String transactionId); @Override void doCleanupAfterCompletion(String transactionId);  }