Skip to content

Commit

Permalink
fix(api): Catch additional UncheckedExecutionException in cache loadi…
Browse files Browse the repository at this point in the history
…ng (#161)
  • Loading branch information
Travis Tomsu committed Mar 30, 2017
1 parent afc0703 commit 3b94a31
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.util.concurrent.UncheckedExecutionException;
import com.netflix.frigga.Names;
import com.netflix.spinnaker.fiat.model.Authorization;
import com.netflix.spinnaker.fiat.model.UserPermission;
Expand All @@ -33,9 +34,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
import org.springframework.stereotype.Component;
import retrofit.RetrofitError;

Expand Down Expand Up @@ -66,7 +65,8 @@ public class FiatPermissionEvaluator implements PermissionEvaluator, Initializin

@Override
public void afterPropertiesSet() throws Exception {
permissionsCache = CacheBuilder.newBuilder()
permissionsCache = CacheBuilder
.newBuilder()
.maximumSize(configProps.getCache().getMaxEntries())
.expireAfterWrite(configProps.getCache().getExpiresAfterWriteSeconds(), TimeUnit.SECONDS)
.recordStats()
Expand Down Expand Up @@ -118,7 +118,7 @@ private String getUsername(Authentication authentication) {
Object principal = authentication.getPrincipal();
if (principal instanceof User) {
username = ((User) principal).getUsername();
} else if (StringUtils.isNotEmpty(principal.toString())){
} else if (StringUtils.isNotEmpty(principal.toString())) {
username = principal.toString();
}
}
Expand Down Expand Up @@ -161,7 +161,7 @@ public UserPermission.View getPermission(String username) {
return fiatService.getUserPermission(username);
});
log.debug("Fiat permission cache hit: " + cacheHit.get());
} catch (ExecutionException ee) {
} catch (ExecutionException | UncheckedExecutionException ee) {
String message = String.format("Cannot get whole user permission for user %s. Cause: %s",
username,
ee.getCause().getMessage());
Expand Down

0 comments on commit 3b94a31

Please sign in to comment.