I can enable/disable the whole @RestController using @ConditionalOnProperty, for example:
@RestController
@ConditionalOnProperty(name = "com.example.api.controller.decision.DecisionController.enabled", havingValue = "true")
@RequestMapping("/v1.0/decisions")
public class DecisionController {
}
The following configuration works fine. But I need to have more fine-grained control over this controller and enable/disable access to the certain methods inside, for example:
@RestController
@ConditionalOnProperty(name = "com.example.api.controller.decision.DecisionController.enabled", havingValue = "true")
@RequestMapping("/v1.0/decisions")
public class DecisionController {
@ConditionalOnProperty(name = "com.example.api.controller.decision.DecisionController.create.enabled", havingValue = "true")
@PreAuthorize("isAuthenticated()")
@RequestMapping(method = RequestMethod.POST)
public DecisionResponse create(@Valid @RequestBody CreateDecisionRequest request, Authentication authentication) {
...
}
}
As you may see, I have added @ConditionalOnProperty to create method but this approach doesn't work and in case of enabled DecisionController the create method is also enabled even if com.example.api.controller.decision.DecisionController.create.enabled property is absent in my application.properties.
How to properly enable/disable create method in this case ?