1
可以讓Spring的緩存框架知道請求上下文的身份驗證狀態,還是更容易推出自己的緩存解決方案?Bypass @Cacheable for(un)authenticated requests
可以讓Spring的緩存框架知道請求上下文的身份驗證狀態,還是更容易推出自己的緩存解決方案?Bypass @Cacheable for(un)authenticated requests
無論事實如何,我發現用例超級怪異,你可以調整緩存幾乎所有與SpEL一起工作的東西。既然你可以用SpEL調用你想要的任何方法,那麼你就很好。
我意識到它比它應該更難,但下面的工作。首先創建一個靜態方法,它支票(可以使用SecurityContextHolder
爲)
public class SecurityChecker {
public static boolean isSecured() {
// Whatever
return SecurityContextHolder.getContext().getAuthentication() != null;
}
}
然後在您的註解的方法,指定以下(假設myCache
應該不受影響):
@Cacheable(cacheNames = "myCache", condition = "T(com.example.SecurityChecker).isSecured()")
public Foo doIt(String key) { ... }
目前有兩個問題: