-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #447 from guardian/drop-play-v2.7
Drop support for Play v2.7
- Loading branch information
Showing
7 changed files
with
70 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
java corretto-11.0.22.7.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.gu.play.secretrotation | ||
|
||
import java.time.Clock | ||
import java.time.Clock.systemUTC | ||
|
||
import play.api.http._ | ||
import play.api.mvc._ | ||
import play.api.mvc.request.{DefaultRequestFactory, RequestFactory} | ||
import play.api.{BuiltInComponentsFromContext, Configuration} | ||
|
||
|
||
trait RotatingSecretComponents extends BuiltInComponentsFromContext { | ||
|
||
val secretStateSupplier: SnapshotProvider | ||
|
||
override def configuration: Configuration = { | ||
val nonRotatingSecretOnlyUsedToSatisfyConfigChecks = secretStateSupplier.snapshot().secrets.active | ||
|
||
super.configuration.withFallback(Configuration("play.http.secret.key" -> nonRotatingSecretOnlyUsedToSatisfyConfigChecks)) | ||
} | ||
|
||
override lazy val requestFactory: RequestFactory = | ||
RotatingSecretComponents.requestFactoryFor(secretStateSupplier, httpConfiguration) | ||
} | ||
|
||
object RotatingSecretComponents { | ||
def requestFactoryFor(snapshotProvider: SnapshotProvider, hc: HttpConfiguration): RequestFactory = | ||
new DefaultRequestFactory( | ||
new DefaultCookieHeaderEncoding(hc.cookies), | ||
new RotatingKeySessionCookieBaker(hc.session, snapshotProvider), | ||
new RotatingKeyFlashCookieBaker(hc.flash, snapshotProvider) | ||
) | ||
|
||
|
||
trait RotatingSecretCookieCodec extends CookieDataCodec { | ||
val snapshotProvider: SnapshotProvider | ||
val jwtConfiguration: JWTConfiguration | ||
|
||
implicit val c: Clock = systemUTC() | ||
|
||
private def jwtCodecFor(secret: String) = DefaultJWTCookieDataCodec(SecretConfiguration(secret), jwtConfiguration) | ||
|
||
override def encode(data: Map[String, String]): String = | ||
jwtCodecFor(snapshotProvider.snapshot().secrets.active).encode(data) | ||
|
||
override def decode(data: String): Map[String, String] = { | ||
snapshotProvider.snapshot().decode[Map[String, String]](jwtCodecFor(_).decode(data), _.nonEmpty).getOrElse(Map.empty) | ||
} | ||
} | ||
|
||
class RotatingKeySessionCookieBaker( | ||
val config: SessionConfiguration, | ||
val snapshotProvider: SnapshotProvider) extends SessionCookieBaker with RotatingSecretCookieCodec { | ||
override val jwtConfiguration: JWTConfiguration = config.jwt | ||
} | ||
|
||
class RotatingKeyFlashCookieBaker( | ||
val config: FlashConfiguration, | ||
val snapshotProvider: SnapshotProvider) extends FlashCookieBaker with RotatingSecretCookieCodec { | ||
override val jwtConfiguration: JWTConfiguration = config.jwt | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../play-v27/RotatingSecretComponents.scala | ||
../play-v28/RotatingSecretComponents.scala |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../play-v27/RotatingSecretComponents.scala | ||
../play-v28/RotatingSecretComponents.scala |