您可以通过 IPAddressAccessControlHandler 在 Spring Boot 中配置IP 地址的访问控制列表。 让我们看看怎么做。
@Bean public UndertowServletWebServerFactory embeddedServletContainerFactory() {
UndertowServletWebServerFactory factory = new UndertowServletWebServerFactory();
factory.addDeploymentInfoCustomizers(new UndertowDeploymentInfoCustomizer() {
@Override public void customize(DeploymentInfo deploymentInfo) {
// Enable IPAddressAccessControlHandler
deploymentInfo.addOuterHandlerChainWrapper(new HandlerWrapper() {
@Override public HttpHandler wrap(HttpHandler handler) {
return new IPAddressAccessControlHandler(handler).setDefaultAllow(false).addAllow("192.168.10.1").addAllow("192.168.10.2");
}
});
}
});
return factory;
}
如果您愿意,可以使用 HandlerParser.parse() 方法来读取 IP ACL:
@Bean public UndertowServletWebServerFactory embeddedServletContainerFactory() {
UndertowServletWebServerFactory factory = new UndertowServletWebServerFactory();
factory.addDeploymentInfoCustomizers(new UndertowDeploymentInfoCustomizer() {
@Override public void customize(DeploymentInfo deploymentInfo) {
deploymentInfo.addOuterHandlerChainWrapper(HandlerParser.parse("ip-access-control(default-allow=false, acl={'192.168.10.1 allow', '192.168.10.2 allow'})", getClass().getClassLoader()));
});
}
});
return factory;
}
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
内容来源于网络,如有侵权,请联系作者删除!