これは以前の質問ですが、このトピックの私の最近の研究では、問題が一般的であり、依然として存在することが判明しました(特にバックエンドセキュリティを備えた最新のAngularJSフロントエンドアプリケーションの場合)。私はあなたと私の解決策を共有したいと思います。ログインページ
、例えば、/login.html、</body>
タグの前に次のコードを配置:
<script type="text/javascript">
var hash = window.location.hash;
document.cookie="hashPart=" + window.btoa(hash);
</script>
注(1):btoa()関数は、IEで動作します> = 10(http://www.w3schools.com/jsref/met_win_btoa.asp)、古いブラウザではjQueryと同等の機能を使用します。
注(2):URLの#部分の暗号化には、クッキー値の文字列に格納できない特殊文字が含まれている必要があります。
onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
AuthenticationSuccessHandler
インターフェイスを実装するクラスのメソッドをサーバー側から変更する必要があります。
私の場合は、SavedRequestAwareAuthenticationSuccessHandler
クラスを拡張し、元のコードを使用してonAuthenticationSuccess
メソッドをオーバーライドするだけです。次に、要求からhashPartのCookie値を取得し、それをデコードし、解決済みのリダイレクトURLに追加します。以下の私のコードフラグメント:https://stackoverflow.com/a/21100458/3076403
私はあなたのコメントや、この問題に対する他のソリューションを楽しみにしています:で説明したように
@Override
public void onAuthenticationSuccess(HttpServletRequest request,
HttpServletResponse response, Authentication authentication)
throws ServletException, IOException {
// ... copy/paste original implementation here, until ...
// Use the DefaultSavedRequest URL
String targetUrl = savedRequest.getRedirectUrl();
for (Cookie cookie : req.getCookies()) {
if (cookie.getName().equals("hashPart")) {
targetUrl += new String(Base64Utils.decodeFromString(cookie.getValue()));
cookie.setMaxAge(0); // clear cookie as no longer needed
response.addCookie(cookie);
break;
}
}
getRedirectStrategy().sendRedirect(request, response, targetUrl);
}
最後に、ちょうど、あなたの春のセキュリティ設定にあなたの成功のハンドラクラスを注入。
あなたはパスの例を提供することができます –
/path/to/page /と#/ path/to/page – nKognito
[サーバー側でハッシュを使用することはできません](http:// stackoverflow。 com/questions/317760/how-to-get-url-hash-from-server-side)を参照してください。 – Xaerxess