http.cors().and().csrf().disable().authorizeRequests()
.antMatchers(HttpMethod.POST, SIGN_UP_URL).permitAll()
В приведенном выше коде antMatchers
также будет принимать массив строк. Ниже приведена реализация метода anyMatcher в весенней безопасности 4.2.3.RELEASE
. В соответствии с сигнатурой метода вы должны иметь возможность передавать массив строк, содержащий необходимые пути.
/**
* Maps a {@link List} of
* {@link org.springframework.security.web.util.matcher.AntPathRequestMatcher}
* instances that do not care which {@link HttpMethod} is used.
*
* @param antPatterns the ant patterns to create
* {@link org.springframework.security.web.util.matcher.AntPathRequestMatcher} from
*
* @return the object that is chained after creating the {@link RequestMatcher}
*/
public C antMatchers(String... antPatterns) {
return chainRequestMatchers(RequestMatchers.antMatchers(antPatterns));
}
Если вы углубитесь в реализацию, Spring преобразует эти аргументы в ArrayList всех путей.
Кроме того, есть альтернативный способ. Чтобы игнорировать путь, который не должен быть защищен пружинной безопасностью, если вы расширяете класс WebSecurityConfigurerAdapter
пружины, снова переопределите тот же метод.
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("path":);
}
Полагаю, это так аккуратно.