玩!限制对特定路由的访问(如 Apache 中的 Limit)
Play! Limit access to specific routes (like Limit in Apache)
我正在寻找任何方法来过滤对 /login 和 /register 的访问(以及可能的任何自定义 url 或路由中的条目),以防止 lan(或 ip 范围)之外的用户) 访问这些页面。
Apache 中类似的东西只需由以下人员完成:
<Limit POST PUT DELETE>
Order Deny,Allow
Deny from all
Allow from ip list or dns
</Limit>
播放服务器 运行 linux(Ubuntu 服务器 10.04)
两种解决方案:
- 这样做 using custom annotation 这样您就可以添加自己的过滤机制。
- 使用... Apache(或者可能是一些更轻的 HTTP 服务器)作为您的应用程序的反向代理(我最喜欢这个问题),这样您就可以通过它的规则控制那里的访问。 Documentation
您的专属解决方案(不是我的):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"
}
我正在寻找任何方法来过滤对 /login 和 /register 的访问(以及可能的任何自定义 url 或路由中的条目),以防止 lan(或 ip 范围)之外的用户) 访问这些页面。
Apache 中类似的东西只需由以下人员完成:
<Limit POST PUT DELETE>
Order Deny,Allow
Deny from all
Allow from ip list or dns
</Limit>
播放服务器 运行 linux(Ubuntu 服务器 10.04)
两种解决方案:
- 这样做 using custom annotation 这样您就可以添加自己的过滤机制。
- 使用... Apache(或者可能是一些更轻的 HTTP 服务器)作为您的应用程序的反向代理(我最喜欢这个问题),这样您就可以通过它的规则控制那里的访问。 Documentation
您的专属解决方案(不是我的):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"
}