【问题标题】:Ip authentication in Spring SecuritySpring Security中的IP认证
【发布时间】:2017-05-10 14:17:34
【问题描述】:

我的网络应用程序中有 Spring Security 4.2.2 并配置了基于 LDAP 的身份验证。此外,我还需要在没有登录表单的情况下对所有具有指定 ip 的用户进行身份验证,并为他们设置“local_user”角色。如何执行该身份验证方案?

更新: 我的意思是,“本地用户”必须查看与通过登录表单授权的用户相同的内容。

【问题讨论】:

    标签: java spring-security


    【解决方案1】:

    您可以使用 antMatchers 来做到这一点,如下代码所示:

        @EnableWebSecurity
        @Configuration
        public class BasicSecurityConfig extends WebSecurityConfigurerAdapter{
    
        @Override
        protected void configure(HttpSecurity http) throws Exception {
             http.authorizeRequests().antMatchers("/baseUrl/anything-else/**").hasIpAddress("ipAddressExpression")
        }
    }
    

    更新

    http.authorizeRequests()
            .antMatchers("/baseUrl/anything-else/**").access("hasIpAddress('ipAddressExpression') or fullyAuthenticated()");
    

    【讨论】:

    • 您是否想说您只是根据用户 ip 地址限制部分数据?
    • 那么我认为您应该使用方法级别的安全性。检查这篇文章:concretepage.com/spring/spring-security/… 或这个websystique.com/spring-security/… 取决于您的要求
    • 查看我更新的答案,它将满足您的需求“更新:我的意思是,“本地用户”必须查看与通过登录表单授权的用户相同的内容。”
    猜你喜欢
    • 2012-08-15
    • 2016-08-11
    • 2016-11-15
    • 2015-03-17
    • 2013-11-03
    • 1970-01-01
    • 2013-08-10
    • 2012-10-15
    • 2015-10-12
    相关资源
    最近更新 更多