2012-01-23 11 views
2

私はPlay! 3つの展開を持つフレームワークHerokuプロジェクト。 1つは私の開発マシン、1つはHerokuのベータ版、もう1つはHeroku版です。次のように彼らのHTTPとHTTPSのURLは以下のとおりです。Https再生フレームワークでHerokuのリダイレクトとログインクッキー

   DEV      BETA         PRODUCTION  
HTTP URL | http://localhost:9000 http://domain-beta.herokuapps.com http://www.domain.com 
HTTPS URL | https://localhost:9443 https://domain-beta.herokuapps.com https://secure.domain.com 
HTTPS Type | My cert     Piggyback (using Heroku's cert)  Hostname-based SSL (using my cert) 

私もHTTPSを必要とするため、バックHTTPにリダイレクトするための方法(助けをthis postへの感謝を)持っているクラスHttpsRequiredを持っています。

public class HttpsRequired extends Controller { 
    /** Called before every request to ensure that HTTPS is used. */ 
    @Before 
    public static void redirectToHttps() { 
     //if it's not secure, but Heroku has already done the SSL processing then it might actually be secure after all 
     if (!request.secure && request.headers.get("x-forwarded-proto") != null) { 
      request.secure = request.headers.get("x-forwarded-proto").values.contains("https"); 
     } 

     //redirect if it's not secure 
     if (!request.secure) { 
      String url = redirectHostHttps() + request.url; 
      System.out.println("Redirecting to secure: " + url); 
      redirect(url); 
     } 
    } 

    /** Renames the host to be https://, handles both Heroku and local testing. */ 
    @Util 
    public static String redirectHostHttps() { 
     if (Play.id.equals("dev")) { 
      String[] pieces = request.host.split(":"); 
      String httpsPort = (String) Play.configuration.get("https.port"); 
      return "https://" + pieces[0] + ":" + httpsPort; 
     } else { 
      if (request.host.endsWith("domain.com")) { 
       return "https://secure.domain.com"; 
      } else { 
       return "https://" + request.host; 
      } 
     } 
    } 

    /** Renames the host to be https://, handles both Heroku and local testing. */ 
    @Util 
    public static String redirectHostNotHttps() { 
     if (Play.id.equals("dev")) { 
      String[] pieces = request.host.split(":"); 
      String httpPort = (String) Play.configuration.get("http.port"); 
      return "http://" + pieces[0] + ":" + httpPort; 
     } else { 
      if (request.host.endsWith("domain.com")) { 
       return "http://www.domain.com"; 
      } else { 
       return "http://" + request.host; 
      } 
     } 
    } 
} 

私はそれが実行される前に、すべてのパスワードが暗号化された提出されることを保証するために、HttpsRequired.redirectToHttps()を呼び出すためにSecure.login()を修正。その後、私のSecurity.onAuthenticated()では、私は標準HTTP上のホームページにリダイレクトします。

これは開発者とベータ版のデプロイメントには効果的ですが、本番環境ではすべてのHTTPリクエストがHTTPSログインページにリダイレクトされます。 HTTPSでサイト全体を使用することはできますが、通常のHTTPも使用したいと思っています。

私のすべてのページは、メンバー専用として保護されており、ユーザーは@With(Secure.class)アノテーションを使用してログインする必要があります。私はそれがwww.domain.comの代わりにsecure.domain.comで起こるという事実に関連していなければならないと思っています。

secure.domain.comで作成したログインCookieを変更してwww.domain.comで動作させる方法はありますか?

答えて

3

デフォルトのCookieドメインの設定については、ドキュメントを参照してください。

http://www.playframework.org/documentation/1.2.4/configuration#application.defaultCookieDomain

それはあなたがすべてのサブドメイン間で動作するようにクッキーを設定する方法について説明します。

application.defaultCookieDomain

は、サブドメイン間のセッション/クッキーの共有を可能にします。たとえば、 には、「.example.com」で終わるすべてのドメインでCookieを有効にします(例: )。 foo.example.comとbar.example.com:

application.defaultCookieDomain=.example.com

+0

うーん。これは、ログインクッキーのための私の問題を修正しましたが、今、私は、HerokuのHTTPS上で動作していないvalidation.keep()の新しい問題を抱えています。新しい質問[ここ](http://stackoverflow.com/questions/9166129/play-framework-on-heroku-validation-keep-isnt-working-over-https)を作成しました。 –

関連する問題