We are facing an issue with SpringSecurity ignoring a method. We tried to skip authentication for a few urls (acutator/health) and resources. Authentication is being taken care externally and we are having one custom filter to extract the principle for authorization.
We override the configured method as shown below:
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/resources/**", "/actuator/health");
}
protected void configure(HttpSecurity http) throws Exception {
http.addFilter(cutstomFilter).authorizeRequests()
.antMatchers("/add","/update","/upload").hasAuthority("ADMIN").anyRequest().authenticated()
.and().logout().logoutSuccessUrl("/logoutUser").and()
.exceptionHandling().accessDeniedPage("/accessDenied").and().csrf().disable();
}
With the given implementation, our customFilter is being called for resources and health url. This is causing reauthenticating due to principle change.
We tried adding this code but customFilter gets called for health url as well.
http.authorizeRequests().antMatchers("/actuator/health").permitAll()
Note: Checked the @Rob Winch answer but did not understand why we need a custom filer if we are putting those url in the ignore list. https://stackoverflow.com/a/19985323/2138633