I am using spring boot 2.1.4.RELEASE and trying to figure out 401 Unauthorized error.
Below is my webconfig class
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/somepath/")
}
@Override
protected void configure(HttpSecurity http) throws Exception {
if(securityEnabled) {
http
.csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.anyRequest().authenticated()
.antMatchers("/somepath/").permitAll()
.and()
.httpBasic()
.and()
.anonymous().disable()
.exceptionHandling().authenticationEntryPoint(unauthorizedEntryPoint());
}
In my main class i have excluded -
@EnableAutoConfiguration(exclude = {ErrorMvcAutoConfiguration.class,org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class,
org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration.class})
Now when i try to test my api using http://localhost:8080/somepath
then i am getting 401 unauthorized. But when i try the same endpoint with token then it works which means that authentication has not been disabled successfully. I would appreciate any help here.