I have an endpoint (GetMapping( "/testendpoint" )
) that I want to leave without my authentication filter running. But no matter what I do, it still calls the filter and rejects it as 401 since there's no Jwt in the header.
NOTE: It only calls the filter once.
How do I make it unsecured and keep it from calling the filter?
@EnableWebSecurity
@Import( { Config.class } )
@EnableConfigurationProperties( { JwtProperties.class } )
public class SecurityConfig extends WebSecurityConfigurerAdapter
{
@Autowired
private JwtProperties jwtProperties;
@Override
public void configure(WebSecurity web) throws Exception
{
web.ignoring()
.antMatchers( "/swagger-ui.html" ) //This goes through without security
.antMatchers( "/metrics" ) //This calls the filter
.antMatchers( "/testendpoint" ); //This calls the filter
}
@Override
protected void configure(HttpSecurity http) throws Exception
{
JWTAuthenticationFilter jwtAuthenticationFilter = new JWTAuthenticationFilter( jwtProperties );
ExceptionHandlerFilter exceptionHandlerFilter = new ExceptionHandlerFilter();
http.csrf().disable().authorizeRequests()
.antMatchers( "/" ).permitAll()
.antMatchers( "/testendpoint" ).permitAll() //Doesn't stop the filter
.and()
.addFilterAfter( jwtAuthenticationFilter, BasicAuthenticationFilter.class )
.addFilterBefore( exceptionHandlerFilter, JWTAuthenticationFilter.class );
/* Adding the below also did not work
.authorizeRequests()
.antMatchers( "/testendpoint/**" ).permitAll();
*/
}
}
My endpoint is an actuator endpoint:
@Configuration
@ManagementContextConfiguration
@CacheController
public class TestController extends AbstractMvcEndpoint
{
@GetMapping( value = "/testendpoint", produces = MediaType.APPLICATION_JSON_UTF8_VALUE )
public String getSomething(HttpServletRequest request) throws Exception
{
return "hello";
}
}