Spring WebSecurity 允许来自 url 的访问

Spring WebSecurity allow access from url

我需要通过我的安全机制来允许某个请求,但我只想允许它从某个位置发送到我服务器上的某个特定位置。这是我当前与 WebSecurity 相关的安全配置:

    @Override
    public void configure(WebSecurity web) throws Exception
    {
        web
        .ignoring()
        .antMatchers("/authentication/login")
        .antMatchers("/users/create")
        .antMatchers("/services/**")
        .antMatchers("/favicon.ico")
        .antMatchers("/resources/**")
        .antMatchers("/leagues/signupDetails/**");

        // allow from https://connect.stripe.com/
        // to
        // "/stripeAccountConfirm"
    }

我确定有办法做到这一点,但我对整个配置场景还是陌生的。提前致谢。

您可以使用网络安全表达式来做到这一点:

...
.antMatchers("/services/**").access("hasRole('admin') and hasIpAddress('192.168.10.0/32')")
...