0

Ist eine Möglichkeit, Spring Security zu konfigurieren, um Hash-Fragmente in einer einzelnen Seite Anwendungen (mit Vaadin 7 Framework gebaut) richtig zu verstehen?Spring Security Umleitung URL und einzelne Seite Hash-Fragmente

Nach erfolgreicher Anmeldung muss ich meine Benutzer auf eine richtige Seite mit Hash-Fragmenten umleiten, aber Spring Security zerstört den ursprünglichen Pfad.

Antwort

0

durch folgenden Trick Fest (ich benutze ThymeLeaf als Template-Engine):

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> 
    <head> 
     <title>Login</title> 

     <script th:inline="javascript"> 
      function getLoginAction(form){ 
       var hash = unescape(self.document.location.hash.substring(1)); 
       form.action = [[@{/login}]] + '#' + hash; 
       return true; 
      } 
     </script> 

    </head> 
    <body> 
     <h3>Please login</h3> 
     <p th:if="${param.error}"> 
      Bad Credentials: 
     </p> 
     <form th:action="@{/login}" method="POST" onsubmit="getLoginAction(this);"> 
      User Name : <input type="text" name="username"/> <br/><br/> 
      Password: <input type="password" name="password"/> <br/><br/> 
      <input type='checkbox' name="remember-me"/>Remember Me? <br/><br/> 
      <input type="submit" value="Login"/> 
     </form> 
    </body> 
</html> 
1

Sie können den Hash-Teil in Ihrem Login-Formular bringen, und den Hash zurück nach erfolgreicher Anmeldung senden.


Bringen Sie mit Login-Formular Vorlage Hash-Teil:

<form name='login_form' action="/perform_login" method='POST' onsubmit="getHashPart()"> 
    <table> 
     <tr> 
      <td>User:</td> 
      <td><input type='text' name='username' value=''></td> 
     </tr> 
     <tr> 
      <td>Password:</td> 
      <td><input type='password' name='password'/></td> 
     </tr> 
     <input type="hidden" name="hashPart" value=""/> 
     <tr> 
      <td><input name="submit" type="submit" value="submit"/></td> 
     </tr> 
    </table> 
</form> 

<script type="text/javascript"> 
    var getHashPart = function() { 
     login_form.hashPart.value = location.hash; 
    } 
</script> 

eine MyAuthenticationSuccessHandler erstellen:

public class MyAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler { 
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) 
     throws ServletException, IOException { 
     String hashPart = request.getParameter("hashPart"); 
     if (hashPart == null || hashPart.trim().equals("")) { 
      super.onAuthenticationSuccess(request, response, authentication); 
     } else { 
      this.getRedirectStrategy().sendRedirect(request, response, "/" + hashPart); 
     } 
    } 
} 

Setzen Sie Ihre Handler in SecurityConfig:

 http 
      ...... 
      .and() 
      .formLogin() 
      .loginPage("/login") 
      .loginProcessingUrl("/perform_login") 
      .successHandler(myAuthenticationSuccessHandler)