Change access to static web ressources on runtime spring boot

86 Views Asked by At

I use Spring Boot and Spring Security in my project to manage the delivery of static web resources. Until now, it was sufficient for my application to identify users via Spring Security and allow them to access these resources. Subsequently, I control the delivery of certain resources via Feature Flags (https://www.togglz.org/documentation/spring-boot-starter.html). By using Feature Flags, it is possible to check if a Feature (e.g. "TEST") is enabled by calling a FeatureManager Bean during runtime like this: manager.isActive(FeatureToggles.TEST). In order to access the flag for managing web resources, I tried to use the mapping functionality of Spring:

@Controller
@RequestMapping("/")    
public class IndexController {
    private FeatureManager manager;

    public IndexController(FeatureManager manager) {
        this.manager = manager;
    }

...

   @RequestMapping(path ="myFeature/")
    public ModelAndView redirectToMyFeature(ModelMap modelMap) {
        if (manager.isActive(FeatureToggles.TEST)) {
            return new ModelAndView("redirect:", modelMap);
        }
        return null;
    }

Unfortunatelly, this code leads to an infinite loop. I wonder how to handle a mapping to the same path with conditions (see code above). Are there other ways to use Spring Boot in order to control the delivery of certain resources during runtime?

0

There are 0 best solutions below