Skip to content

Commit

Permalink
fix(apps): Clear resource provider caches to ensure up-to-date data (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ncknt authored and dibyom committed May 22, 2019
1 parent 9ee2d58 commit ed2db48
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ public UserPermission resolveAndMerge(@NonNull ExternalUser user) {
return getUserPermission(user.getId(), combo);
}

@Override
public void clearCache() {
for (ResourceProvider provider : resourceProviders) {
provider.clearCache();
}
}

private boolean resolveAdminRole(Set<Role> roles) {
List<String> adminRoles = fiatAdminConfig.getAdmin().getRoles();
return roles.stream().map(Role::getName).anyMatch(adminRoles::contains);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ public interface PermissionsResolver {
/** Resolves multiple user's permissions. Returned map is keyed by userId. */
Map<String, UserPermission> resolve(Collection<ExternalUser> users)
throws PermissionResolutionException;

/** Clears resource cache: apps, service accounts,... */
void clearCache();
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,9 @@ private Cache<Integer, Set<R>> buildCache(int expireAfterWrite) {
.build();
}

public void clearCache() {
cache.invalidate(CACHE_KEY);
}

protected abstract Set<R> loadAll() throws ProviderException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ public interface ResourceProvider<R extends Resource> {
Set<R> getAllRestricted(Set<Role> roles, boolean isAdmin) throws ProviderException;

Set<R> getAllUnrestricted() throws ProviderException;

void clearCache();
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ public long syncAndReturn(List<String> roles) {
+ "resolution may not complete until this server becomes healthy again.");
}

// Ensure we're going to reload app and service account definitions
permissionsResolver.clearCache();

while (true) {
try {
Map<String, UserPermission> combo = new HashMap<>();
Expand Down

0 comments on commit ed2db48

Please sign in to comment.