限制ipaddress访问Web服务

时间:2015-06-02 12:35:06

标签: java spring-mvc tomcat tomcat7 tomcat6

我有3个以下的服务,应该让3个不同的ipaddress访问它们,请帮我解决这个问题

getJoinDate
getEmpCode
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
    }

}

1 个答案:

答案 0 :(得分:0)

Web.config ipSecurity

web.config文件可用于通过客户端IP地址限制网站访问。 Web.config可用于限制对单个页面,目录和所有子目录,甚至整个网站的访问。您可以阻止所有IP地址,只允许一些可信任的IP地址,或者您可以允许每个人阻止特定的IP地址或子网。

虽然有些web.config部分要求将包含目录设置为应用程序,但这不是其中之一。具有web.config部分的简单ipSecurity可以放在任何目录中,并且不需要将该目录设置为应用程序。

示例:

<?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>