By default, Spring Boot will protect all endpoints if Spring Security is in the classpath.
You need to explicitly add an exception for all other endpoints that will be resolved without authentication.
Example:
@Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/employee/*").authenticated() .anyRequest().permitAll() .and() .httpBasic() .and() .csrf().disable(); } @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser("admin").password("admin").roles("USER"); } }
source share