When I mix @EnableGlobalMethodSecurity and @EnableCache, cache doesn't work at all;

@Configuration @EnableGlobalMethodSecurity(prePostEnabled = true) public class GlobalMethodSecurity extends GlobalMethodSecurityConfiguration { private final CustomPermissionEvaluator evaluator;

@Autowired
public GlobalMethodSecurity(CustomPermissionEvaluator evaluator) {
    this.evaluator = evaluator;
}

@Override
protected MethodSecurityExpressionHandler createExpressionHandler() {
    DefaultMethodSecurityExpressionHandler expressionHandler =
            new DefaultMethodSecurityExpressionHandler();
    expressionHandler.setPermissionEvaluator(evaluator);
    return expressionHandler;
}

}

@Configuration @EnableCaching @Profile("!junit") public class RedisConfig { private final EnvironmentProperties properties;

@Autowired
public RedisConfig(EnvironmentProperties properties) {
    this.properties = properties;
}

@Bean
public CacheManager generalCacheManager(RedisConnectionFactory factory) {
    RedisCacheConfiguration configuration = RedisCacheConfiguration.defaultCacheConfig()
            .computePrefixWith(cacheName -> properties.getTenant() + "::" + cacheName + "::")
            .serializeValuesWith(
                    RedisSerializationContext.SerializationPair.fromSerializer(new RedisJsonObjectSerializer())
            );
    return RedisCacheManager.builder(factory)
            .cacheDefaults(configuration)
            .build();
}

@Primary
@Bean
public CacheManager primaryCacheManager(RedisConnectionFactory factory) {
    RedisCacheConfiguration configuration = RedisCacheConfiguration.defaultCacheConfig()
            .computePrefixWith(cacheName -> properties.getTenant() + "::" + cacheName + "::");
    return RedisCacheManager.builder(factory)
            .cacheDefaults(configuration)
            .build();
}

}

Version

springBootVersion = '2.0.0.RELEASE'

Comment From: rwinch

Thanks for the report. Can you provide a minimal and complete sample that reproduces this? Have you tried Spring Boot 2.0.1?

Comment From: aliaksandrmikhailik

I found that everything stops working when I specify permission evaluator.

If I have @Override protected MethodSecurityExpressionHandler createExpressionHandler() { DefaultMethodSecurityExpressionHandler expressionHandler = new DefaultMethodSecurityExpressionHandler(); expressionHandler.setPermissionEvaluator(evaluator); return expressionHandler; } cache stops working, but if I have

@Override protected MethodSecurityExpressionHandler createExpressionHandler() { DefaultMethodSecurityExpressionHandler expressionHandler = new DefaultMethodSecurityExpressionHandler(); return expressionHandler; }

everything works properly

Comment From: aliaksandrmikhailik

and I have that with 2.0.0.RELEASE and 2.0.1.RELEASE

Comment From: aliaksandrmikhailik

correction, cache doesn't work inside permission evaluator

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.