В итоге JwtAuthorizationFilter не работает.
Если я оставляю //filterChain.doFilter(request, response) закомментированным, я правильно получаю 200, но тело пустое, что означает две вещи: 1) Контроллер / Ответ от контроллера выполняется, но не Лог c на нем. 2) Функция getAuthentication () правильно читает утверждения / токен
. Проблема возникает, если я раскомментирую строку //filterChain.doFilter(request, response), потому что я получаю 405. Эта строка должна быть раскомментирована для цепочка фильтров для полного завершения и получения тела ответа с содержимым.
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain)
throws IOException, ServletException {
UsernamePasswordAuthenticationToken authentication = getAuthentication(request);
if (authentication == null) {
filterChain.doFilter(request, response);
return;
}
SecurityContextHolder.getContext().setAuthentication(authentication);
**//filterChain.doFilter(request, response);**
}
Function in the controller:
@GetMapping("/foo")
@ResponseStatus(code = HttpStatus.OK)
public MyObject retrieve(@RequestBody MyModel obj) {
//code here is never called
}
For reference, this is my security config:
@Override
protected void configure(final HttpSecurity http) throws Exception {
http.cors().and().csrf().disable().authorizeRequests()
.antMatchers(HttpMethod.POST, "/bar").permitAll()
.anyRequest().authenticated().and().addFilter(new AnotherFilter(authenticationManager()))
.addFilter(new JwtAuthorizationFilter(authenticationManager()))
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
What Am I doing wrong?