无法在hystrix线程中设置Spring SecurityContext

时间:2019-05-14 12:31:08

标签: spring-boot spring-security hystrix security-context

我正在评估我的应用程序中的hystrix,由于线程失去了父线程中存在的上下文,因此我无法执行后备方法。

我正在使用spring boot并使用@PreAuthorize注释,如下所示:

@PreAuthorize("hasAnyRole('" + SecuredConstants.ROLE_APP_DEBUG + "')")
void clearAllRedisCaches();
@PreAuthorize("hasAnyRole('" + SecuredConstants.ROLE_APP_DEBUG + "')")
Set<String> getAllCaches();

@PreAuthorize("hasAnyRole('" + SecuredConstants.ROLE_APP_DEBUG + "')")
Set<String> getKeys(String cacheName);

现在,我的后备方法是:

public String getAssetsFromBackup(String domainId) {
    CacheEntry entry = cacheService.get(Constants.CACHE_NAME_ALL_COLLIBRA_ASSETS_BY_DOMAIN_ID_BACKUP, domainId);
    if (entry != null) {
        return (String) entry.getV();
    }
    return null;
}

cachService.get()失败,因为我在hystrix线程中没有安全上下文。 我怎样才能做到这一点?我在春季靴1.5上

我尝试了其他一些帖子(Unreachable security context using Feign RequestInterceptor)中提到的一些解决方案,但是它们不起作用。

0 个答案:

没有答案
相关问题