2017-01-16 5 views
0

Wir haben unsere Anwendung von Spring & Hibernate 3.x auf 4.x aktualisiert. Das Problem ist, dass AuthenticationException.getAuthentication() jetzt veraltet ist. Kann jemand eine Alternative dazu vorschlagen? Unten ist der Code, den wir verwendet haben:Ersatz für AuthenticationException.getAuthentication();

public ModelAndView init(HttpServletRequest request, HttpServletResponse response){ 
    AuthenticationException exception = (AuthenticationException)request.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION); 

    Authentication loginAuthentication = exception.getAuthentication(); 

    //Set the user name for the change password screen 
    return new ModelAndView("common/changePassword", "userName", loginAuthentication.getPrincipal()); 
} 

mir jemand auf den Ersatz für diese verweisen. Nicht viel ist online verfügbar.

+0

See [Was die Ersetzung von AuthenticationException.getAuthentication ist() in Spring4.0.3] (http://stackoverflow.com/q/39524178/1553851) – shmosel

+0

geprüft Bereits auf diesen Link, keine Lösung gibt – Sid

+0

'SecurityContextHolder .getContext(). getAuthentication() 'und' SecurityContextHolder.getContext(). setAuthentication (Authentication) '. – manish

Antwort

0

Wenn das folgende Codeelement im Fall von AuthenticationException ausgeführt wird, bedeutet dies, dass der Benutzername und das Kennwort, die Sie vom Anmeldeformular gesendet haben, weiterhin im HttpServletRequest verfügbar sind. Also ich denke du kannst den Benutzernamen von dort bekommen.

public ModelAndView init(HttpServletRequest request, HttpServletResponse response){ 
    AuthenticationException exception = (AuthenticationException)request.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION); 

    String username = request.getParameter("<Name of your username parameter>"); 

    //Set the user name for the change password screen 
    return new ModelAndView("common/changePassword", "userName", username); 
}