我已经在我的 Spring Boot 应用程序中实现了 togglz。我什至可以访问 Togglz 控制台,并且我已经使用 FeatureManager 测试了这些限制。但是,如果我转到 togglz 控制台并尝试更改激活策略或启用/禁用某个功能,我会收到 403 Forbidden 错误页面。
换句话说,我可以访问 /togglz/index 但我不能访问/调用 /togglz/edit
在我的 WebMvcConfigurer 类中:
@Bean
public FilterRegistrationBean<TogglzFilter> togglzRegistration() {
FilterRegistrationBean<TogglzFilter> reg = new FilterRegistrationBean<>();
reg.setFilter(new TogglzFilter());
reg.addUrlPatterns("/*");
reg.setName("TogglzFilter");
return reg;
}
@Bean
public ServletRegistrationBean<TogglzConsoleServlet> togglzConsoleServlet() {
ServletRegistrationBean<TogglzConsoleServlet> reg = new ServletRegistrationBean<>();
reg.setServlet(new TogglzConsoleServlet());
reg.setName("TogglzConsoleServlet");
reg.addUrlMappings("/togglz/*");
return reg;
}
在我的 TogglzConfiguration 中:
@Component
public class TogglzConfiguration implements TogglzConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(TogglzConfiguration.class);
@Autowired
private ResourceLoader resourceLoader;
@Override
public Class<? extends Feature> getFeatureClass() {
return Features.class;
}
@Override
public StateRepository getStateRepository() {
try {
return new FileBasedStateRepository(
resourceLoader.getResource("classpath:/togglz.properties").getFile()
);
} catch (IOException ex) {
LOGGER.error(ex.getMessage(),ex);
throw new RuntimeException(ex);
}
}
@Override
public UserProvider getUserProvider() {
return new UserProvider() {
@Override
public FeatureUser getCurrentUser() {
return new SimpleFeatureUser("admin", true);
}
};
}
}
我的功能类:
public enum Features implements Feature {
@Label("Inventory Initiation")
@TestingUI
TESTING_UI_INITIATE_INVENTORY,
@Label("Random Warehouse Creation")
@TestingUI
TESTING_UI_CREATE_WAREHOUSE
;
public boolean isActive() {
return FeatureContext.getFeatureManager().isActive(this);
}
}