I have REST APIs and I wish to secure them using Spring Security -
override fun configure(http: HttpSecurity?) {
http?.authorizeRequests()
?.antMatchers("/podcast/**")?.hasRole("admin")
?.antMatchers(HttpMethod.GET, "/podcast/details/**")?.permitAll()
?.antMatchers("/")?.permitAll()
?.and()
?.formLogin()
}
?.antMatchers("/podcast/**")?.hasRole("admin")
is working but,
?.antMatchers(HttpMethod.GET, "/podcast/details/**")?.permitAll()
gets completely ignored when I'm trying to hit http://localhost:8080/podcast/details/all
API.
However, when I reverse the pattenr checks like this -
override fun configure(http: HttpSecurity?) {
http?.authorizeRequests()
?.antMatchers(HttpMethod.GET, "/podcast/details/**")?.permitAll()
?.antMatchers("/podcast/**")?.hasRole("admin")
?.antMatchers("/")?.permitAll()
?.and()
?.formLogin()
}
It works as expected.
I was of belief that the strictest pattern has to be first but the above case is proving otherwise. What am I missing?