У меня есть конечная точка (GetMapping( "/testendpoint" )
), которую я хочу оставить без работы фильтра проверки подлинности. Но что бы я ни делал, он все равно вызывает фильтр и отклоняет его как 401, так как в заголовке нет Jwt.
ПРИМЕЧАНИЕ. Фильтр вызывается только один раз.
Как сделать его незащищенным и не допустить вызова фильтра?
@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();
*/
}
}
Моя конечная точка является конечной точкой привода:
@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";
}
}
web.ignoring().antMatchers( "/swagger-ui.html", "/metrics", "/testendpoint");
- person Ritesh   schedule 27.01.2018