StackOverflowError bei authenticationManager

krgewb

Top Contributor
Ich habe diese Methode
Java:
private UserBean setUserData(final LoginResult login, UserBean userBean, HttpSession httpSession, HttpServletResponse response) {

    httpSession.setAttribute("PHPSESSID", login.getSessionId());
    Cookie phpCookie = new Cookie("PHPSESSID", login.getSessionId());
    phpCookie.setPath("/");
    response.addCookie(phpCookie);

    try {
        if (login.getLogin()) {
            httpSession.setAttribute("ALARM-FROM", "0");
            userBean.setPassword("not_set");
            userBean.setLanguage("deu");
            userBean.setAvailableLanguages(new ArrayList<>());
            userBean.getAvailableLanguages().add(new LanguageBean("deu"));
            userBean.setPhone("123456789");
            httpSession.setAttribute("USER_BEAN", userBean);
            UsernamePasswordAuthenticationToken authReq = new UsernamePasswordAuthenticationToken(userBean.getNickname(), "");
            Authentication auth = authenticationManager.authenticate(authReq);
            SecurityContext sc = SecurityContextHolder.getContext();
            sc.setAuthentication(auth);
            httpSession.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, sc);
            userBean.getRightControllerBean().addRight("x", "server", ConHelper.PROTOKOLL + ConHelper.IP);
            return userBean;
        } else {
            logger.info("credentials not valid");
        }
        httpSession.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, null);
        return null;
    } catch (Exception e) {
        logger.error("exception. " + e.getMessage() + " / " + e.getCause());
    }

    return null;
}
Anscheinend kommt es bis zu der Zeile
Java:
UsernamePasswordAuthenticationToken authReq = new UsernamePasswordAuthenticationToken(userBean.getNickname(), credentials);
Wegen der Zeile
Code:
Authentication auth = authenticationManager.authenticate(authReq);
passiert eine unhandled Exception.
Da steht:
Code:
2023-11-15 11:51:44.351 [http-nio-8080-exec-9] ERROR c.a.v.b.c.GlobalExceptionHandler - Unhandled exception occurred
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.StackOverflowError

Früher hat es funktioniert. Damals haben wir aber eine andere library verwendet. Die Interfaces Authentication und AuthenticationManager waren in spring-security-core:4.2.3:RELEASE. Jetzt verwenden wir spring-security-core:5.5.0.
 
Zuletzt bearbeitet:

Robert Zenz

Top Contributor
Du hast irgendwo eine endlose Rekursion, vermutlich (und ds ist jetzt nur geraten) ruft authenticationManager.authenticate irgendwann wieder setUserData auf, und damit geht es immer so weiter bis kein Platz mehr am Stapel ist.

Du musst dir die Stapelspur der Ausnahme ansehen damit du die genaue Schleife die da entsteht erkennen kannst.
 

Neue Themen


Oben