使用 Spring Security 的 IP 过滤器 [英] IP filter using Spring Security

查看:69
本文介绍了使用 Spring Security 的 IP 过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用 Spring Security 通过用户的 IP 过滤用户对我的 Web 应用程序的访问.我应该扩展 AbstractAuthenticationProcessingFilter 或类似的东西并以我自己的方式覆盖它的方法吗?如果是这样,您能否举例说明web.xml 中的这种扩展和过滤器描述示例?提前致谢.

I wonder how to filter users' access to my web app by their IP using Spring Security. Should I extend AbstractAuthenticationProcessingFilter or something like that and override it's methods in my own way? If so, could you give an example of such extending and example of filter description in web.xml? Thanks in advance.

附言在我的应用程序中,我也有 Spring Security 支持(使用默认的 org.springframework.web.filter.DelegatingFilterProxy),但我希望它不仅检查用户凭据,还检查他们的 IP.

P.S. In my app I also have Spring Security support (using default org.springframework.web.filter.DelegatingFilterProxy), but I want it to check not only user credentials, but their IP's as well.

推荐答案

一种方法是使用 Spring Security 的 网络安全表达式.例如:

One way you can do this is to use Spring Security's Web Security Expressions. For example:

<http use-expressions="true">
    <intercept-url pattern="/admin*"
        access="hasRole('admin') and hasIpAddress('192.168.1.0/24')"/>
    ...
</http>

这篇关于使用 Spring Security 的 IP 过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆