2012-02-23 16 views
1

私はSpring Security 3.0 SSO風の組み込みSpringアプリケーションと、自分のSSOサーバに対して認証する外部PHPアプリケーションを持っています。Spring Security 3.0:認証後のGET要求

ユーザーがこのアプリケーションにログインすると、私は彼/彼女をPHPアプリケーションでも認証したいと思います。

....私は、PHPのためのサインインに対して、 "GET" リクエストを作成した後、認証ハンドラで

public class CustomAuthenticationHandler extends SavedRequestAwareAuthenticationSuccessHandler { 

@Override 
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { 

    DefaultHttpClient httpclient = new DefaultHttpClient(); 
    try { 
     HttpGet httpget = new HttpGet("http://localhost/phpapp/signin"); 
     httpget.setHeader("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:10.0.2) Gecko/20100101 Firefox/10.0.2"); 
     httpget.setHeader("Connection", "keep-alive"); 
     httpget.setHeader("Referer", "http://localhost:8080/;jsessionid="+request.getSession().getId()); 
     httpget.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); 
     httpget.setHeader("Accept-Language", "en-gb,en;q=0.5"); 
     httpget.setHeader("Accept-Encoding", "gzip, deflate"); 
     httpget.setHeader("Cookie", "JSESSIONID="+request.getSession().getId()); 

     HttpResponse res = httpclient.execute(httpget); 

    } finally { 
     httpclient.getConnectionManager().shutdown(); 
    } 
} 
} 

は、だから私はこれをしませんでしたアプリ。 実行されると、要求本体に戻り、ユーザーのような「ログインページ」はログに記録されません。現在認証されたJSESSIONIDとして

httpget.setHeader("Referer", "http://localhost:8080/;jsessionid="+request.getSession().getId()); 

を:私は使用に注意してください。

しかし、私は同じリンクを貼り付けてください:http://localhost/phpapp/signin通常のhrefのリンクとして、認証後にそれをクリックして正常に動作します。

なぜフィルタで同じ種類のリクエストが動作しないのでしょうか?

答えて

0

Cookieのパスに関連している可能性があります。両方のアプリがhttp://localhost/phpapp/で動作していない限り、Cookieはサブドメイン、ドメイン、パス、ポートに結びついているため、問題が発生します。あなたは、クッキーのパスまたはポート要素を設定しないようにSpringを修正することができます。つまり、localhostに結びつけるだけです。

しかし、アプリ間でプロキシクッキーを使用しようとするよりも、実際のシングルサインオンシステムのような別のアプローチを採用することを強くお勧めします。

関連する問題