Spring - Brak Authentication w ErrorController

0
@Controller
public class MyErrorController implements ErrorController {

    private UserService userService;
    @Autowired
    public MyErrorController(UserService userService)
    {
        this.userService = userService;
    }
    @RequestMapping("/error")
    public ModelAndView handleError(ModelAndView modelAndView, HttpServletRequest request, Authentication authentication, RedirectAttributes redirectAttributes) {
        Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);

        if(status != null)
        {
[...]

Hej.
Mam problem. We wszystkich kontrolerach z Authentication authentication, po zalogowaniu zmienna nie jest nullem.
W kontrolerze MyErrorController jest nullem mimo że wcześniej się logowałem.
Jak temu zapobiec?

0

Możliwe ze pod tym endpointem nie masz skonfigurowanego Spring Security i nie ma filtra ktory wrzucilby to "Authentication" do twojej metody

0

Wiecie co, porównałem kontrolery i jedyną różnicą oprócz tego że MyErrorController implementował ErrorController a inne kontrolery nie implementowały niczego, to było @RequestMapping("/error") a w innych miałem @GetMapping / @PostMapping.
Zmiana tego spowodowała że zmienna authentication nie jest już nullem.

1 użytkowników online, w tym zalogowanych: 0, gości: 1