我有以下 3 个服务,应该让 3 个不同的 ipaddress 访问它们,请帮我解决这个问题
获取加入日期
获取工作码
getEmpSal
@Controller
public class EmpRESTService {
@RequestMapping(value = "/Emp/getJoinDate", produces = "application/json", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<?> getJoinDate(@RequestBody EmpJoinREST joinDateBody){
//Code
}
@RequestMapping(value = "/Emp/getEmpCode", produces = "application/json", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<?> getEmpCode(@RequestBody EmpCodeREST empCodeBody){
//Code
}
@RequestMapping(value = "/Emp/getSal", produces = "application/json", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<?> getEmpSal(@RequestBody EmpSal empSalBody){
//Code
}
}
最佳答案
Web.config ipSecurity
web.config
文件可用于通过客户端 IP 地址限制网站访问。 Web.config
可用于限制对单个页面、目录和所有子目录甚至整个网站的访问。您可以阻止所有 IP 地址并只允许少数受信任的 IP 地址进入,或者您可以允许所有人进入并阻止特定 IP 地址或子网。
虽然某些 web.config
部分要求将包含目录设置为应用程序,但这不是其中之一。带有ipSecurity
部分的简单web.config
可以放置在任何目录中,并且该目录不需要设置为应用程序。
例子:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<security>
<ipSecurity allowUnlisted="true"> <!-- this line blocks everybody, except those listed below -->
<clear/> <!-- removes all upstream restrictions -->
<add ipAddress="83.116.19.53"/> <!-- block one IP -->
<add ipAddress="83.116.119.0" subnetMask="255.255.255.0"/> <!--block network 83.116.119.0 to 83.116.119.255-->
</ipSecurity>
</security>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
关于java - 限制ip地址访问web服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30596259/