玩!限制对特定路由的访问(例如Apache中的限制)

时间:2015-09-11 19:43:10

标签: apache playframework routes

我正在寻找任何方法来过滤对/ login和/ register(以及可能的路由中的任何自定义URL或条目)的访问,以防止局域网(或ip范围)以外的用户访问页面。< / p>

像Apache这样的事情只需通过以下方式完成:

 <Limit POST PUT DELETE>
  Order Deny,Allow
  Deny from all
  Allow from ip list or dns
 </Limit>

Play服务器正在linux(Ubuntu Server 10.04)上运行

2 个答案:

答案 0 :(得分:1)

两种解决方案:

  1. 执行using custom annotation,以便添加自己的过滤机制。
  2. 使用... Apache(或者可能是一些较轻的HTTP服务器)作为您的应用程序的反向代理(我最喜欢这个问题),因此您可以通过其规则控制访问。 Documentation

答案 1 :(得分:1)

特别针对您的解决方案(它不是我的):Simple IP Access List for Play 2 with Java

它基于注释(如biesior建议)并且已经可以使用了。您只需要将两个文件复制到项目中,然后就可以在applications.conf中配置IP列表,如下所示

restricttohostgroup {
    groups {
        default = ["0:0:0:0:0:0:0:1", "127.0.0.1", "10.0.0.", "192.168.0."],
        admin = ["192.168.7."]
    },
    redirect = "http://github.com"
}