Spring security 在Spring Security中对同一url使用两种不同的规则(如或()
我需要保护url,以便有两种可能的访问方式:Spring security 在Spring Security中对同一url使用两种不同的规则(如或(),spring-security,Spring Security,我需要保护url,以便有两种可能的访问方式: 客户端具有特定的ip地址 或者客户端需要登录 因此,我需要为单个URL提供两条规则,使用下面的或方法: .antMatchers(“/url/**”).authenticated()或().hasIpAddress(“192.bla.bla”) 有没有办法做到这一点?您可以使用SPEL将它们结合起来 String expression = "hasIpAddress('127.0.0.1') or hasRole('ROLE_USER'
- 客户端具有特定的ip地址
- 或者客户端需要登录
或方法:
.antMatchers(“/url/**”).authenticated()或().hasIpAddress(“192.bla.bla”)
有没有办法做到这一点?您可以使用SPEL将它们结合起来
String expression = "hasIpAddress('127.0.0.1') or hasRole('ROLE_USER')";
http
.authorizeRequests()
.antMatchers("/home").access(expression)