§セッションクッキーの設定
Playは、ブラウザのセッションクッキーを使用してセッションを保存します。プログラミングを行う際には、通常Scala APIまたはJava APIを通じてセッションにアクセスしますが、便利な設定があります。
セッションとフラッシュクッキーはJSON Web Token(JWT)形式で保存されます。エンコーディングはPlayにとって透過的ですが、セッションクッキーに活用できるJWTの便利なプロパティがあり、`application.conf`で設定できます。JWTは通常HTTPヘッダー値で使用されますが、ここではアクティブではありません。さらに、JWTはシークレットを使用して署名されますが、Playによって暗号化されることはありません。
§有効期限以前のサポート
セッションクッキーが作成されると、JWTの「発行日時」`iat`と「有効期限以前」`nbf`のクレームはクッキー作成時に設定されます。これにより、現在の時刻より前にクッキーが受け入れられるのを防ぎます。
§セッションタイムアウト/有効期限
デフォルトでは、セッションに技術的なタイムアウトはありません。ユーザーがWebブラウザを閉じると期限切れになります。特定のアプリケーションで機能的なタイムアウトが必要な場合は、`application.conf`でキー`play.http.session.maxAge`を設定してセッションクッキーの最大年齢を設定します。これにより、`play.http.session.jwt.expiresAfter`にも同じ値が設定されます。`maxAge`プロパティはブラウザからクッキーを削除し、JWT `exp`クレームがクッキーに設定され、指定された期間後に無効になります。
§URLエンコードクッキーエンコーディング
セッションクッキーはJWTクッキーエンコーディングを使用します。必要に応じて、`application.conf`ファイルで`play.api.mvc.LegacyCookiesModule`に切り替えることで、URLエンコードクッキーエンコーディングに戻すことができます。
play.modules.disabled+="play.api.mvc.CookiesModule"
play.modules.enabled+="play.api.mvc.LegacyCookiesModule"
§セッション設定
デフォルトのセッション設定は以下のとおりです。
# Session configuration
session = {
# The cookie name
cookieName = "PLAY_SESSION"
# Whether the secure attribute of the cookie should be set to true
secure = false
# The max age to set on the cookie.
# If null, the cookie expires when the user closes their browser.
# An important thing to note, this only sets when the browser will discard the cookie.
maxAge = null
# Whether the HTTP only attribute of the cookie should be set to true
httpOnly = true
# The value of the SameSite attribute of the cookie. Set to null for no SameSite attribute.
# Possible values are "lax", "strict" and "none". If misconfigured it's set to null.
sameSite = "lax"
# The domain to set on the session cookie
# If null, does not set a domain on the session cookie.
domain = null
# The session path
# Must start with /.
path = ${play.http.context}
jwt {
# The JWT signature algorithm to use on the session cookie
# uses 'alg' https://tools.ietf.org/html/rfc7515#section-4.1.1
signatureAlgorithm = "HS256"
# The time after which the session is automatically invalidated.
# Use 'exp' https://tools.ietf.org/html/rfc7519#section-4.1.4
expiresAfter = ${play.http.session.maxAge}
# The amount of clock skew to accept between servers when performing date checks
# If you have NTP or roughtime synchronizing between servers, you can enhance
# security by tightening this value.
clockSkew = 5 minutes
# The claim key under which all user data is stored in the JWT.
dataClaim = "data"
}
}
次へ: JDBC接続プールの設定
このドキュメントに誤りを見つけましたか?このページのソースコードはこちらにあります。ドキュメントガイドラインを読んだ後、プルリクエストを自由に送ってください。質問やアドバイスがありますか?コミュニティフォーラムでコミュニティとの会話を開始してください。