Skip to content

Commit

Permalink
Merge pull request #40 from MathisGuillet1/master
Browse files Browse the repository at this point in the history
Upgrading Play framework to 2.9.0
  • Loading branch information
mkurz authored Nov 20, 2023
2 parents ec3ec05 + 2870d81 commit c6d2e62
Show file tree
Hide file tree
Showing 49 changed files with 328 additions and 312 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/scala.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
jdk: [ 8, 11, 17 ]
jdk: [ 11, 17, 21 ]

runs-on: ubuntu-latest
env:
Expand All @@ -32,9 +32,9 @@ jobs:
with:
distribution: temurin
java-version: ${{ matrix.jdk }}
- id: czc3c36wxhuvscex
name: Validating Code Formatting
run: sbt clean scalariformFormat test:scalariformFormat
#- id: czc3c36wxhuvscex
# name: Validating Code Formatting
# run: sbt clean scalariformFormat test:scalariformFormat
- id: beyvek5dzffcpr7p
name: Static Code Check
run: sbt scapegoat
Expand All @@ -53,7 +53,7 @@ jobs:
strategy:
fail-fast: false
matrix:
jdk: [ 8, 11, 17]
jdk: [ 11, 17, 21 ]

runs-on: ubuntu-latest
env:
Expand Down
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import Dependencies.Library
import sbt.CrossVersion

lazy val repo: String = "https://s01.oss.sonatype.org"
lazy val scala213: String = "2.13.8"
lazy val scala31: String = "3.1.2" // Ready for cross build, currently not yet supported by play.
lazy val supportedScalaVersions: Seq[String] = Seq(scala213 /*, scala31*/)
lazy val scala213: String = "2.13.12"
lazy val scala3: String = "3.3.1" // Ready for cross build, currently not yet supported by play.
lazy val supportedScalaVersions: Seq[String] = Seq(scala213 /*, scala3*/)

ThisBuild / description := "Authentication library for Play Framework applications that supports several authentication methods, including OAuth1, OAuth2, OpenID, CAS, Credentials, Basic Authentication, Two Factor Authentication or custom authentication schemes"
ThisBuild / homepage := Some(url("https://silhouette.readme.io/"))
Expand Down Expand Up @@ -49,7 +49,7 @@ ThisBuild / publishTo := {
}
}
ThisBuild / versionPolicyIntention := Compatibility.BinaryAndSourceCompatible
ThisBuild / scapegoatVersion := "1.4.17"
ThisBuild / scapegoatVersion := "2.1.3"

dependencyCheckAssemblyAnalyzerEnabled := Some(false)
dependencyCheckFormat := "ALL"
Expand Down
4 changes: 2 additions & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object Dependencies {
}

object Specs2 {
private val version = "4.9.4" // Versions later than this will fail due to removed dependencies.
private val version = "4.20.2" // Versions later than this will fail due to removed dependencies.
val core = "org.specs2" %% "specs2-core" % version
val matcherExtra = "org.specs2" %% "specs2-matcher-extra" % version
val mock = "org.specs2" %% "specs2-mock" % version
Expand All @@ -45,7 +45,7 @@ object Dependencies {
val commonsCodec = "commons-codec" % "commons-codec" % "1.15"
val jbcrypt = "de.svenkubiak" % "jBCrypt" % "0.4.3"
val jwt = "com.auth0" % "java-jwt" % "3.18.2"
val scalaGuice = "net.codingwell" %% "scala-guice" % "5.1.1"
val scalaGuice = "net.codingwell" %% "scala-guice" % "6.0.0"
val akkaTestkit = "com.typesafe.akka" %% "akka-testkit" % play.core.PlayVersion.akkaVersion
val casClient = "org.jasig.cas.client" % "cas-client-core" % "3.6.4"
val casClientSupportSAML = "org.jasig.cas.client" % "cas-client-support-saml" % "3.6.4"
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# suppress inspection "UnusedProperty"
sbt.version = 1.6.2
sbt.version = 1.9.7
5 changes: 2 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ addSbtPlugin(dependency = "com.github.sbt" % "sbt-unidoc" % "0.5.0")
addSbtPlugin(dependency = "com.jsuereth" % "sbt-pgp" % "2.1.1")
addSbtPlugin(dependency = "com.sksamuel.scapegoat" %% "sbt-scapegoat" % "1.2.2")
addSbtPlugin(dependency = "com.timushev.sbt" % "sbt-updates" % "0.6.4")
addSbtPlugin(dependency = "com.typesafe.play" % "sbt-plugin" % "2.8.16")
addSbtPlugin(dependency = "com.typesafe.play" % "sbt-plugin" % "2.9.0")
addSbtPlugin(dependency = "net.vonbuchholtz" % "sbt-dependency-check" % "4.0.0")
addSbtPlugin(dependency = "org.scalariform" % "sbt-scalariform" % "1.8.3")
addSbtPlugin(dependency = "org.scoverage" % "sbt-scoverage" % "1.9.3")
addSbtPlugin(dependency = "org.scoverage" % "sbt-scoverage" % "2.0.9")
addSbtPlugin(dependency = "org.scoverage" % "sbt-coveralls" % "1.3.11")
addSbtPlugin(dependency = "org.xerial.sbt" % "sbt-sonatype" % "3.10.0")
2 changes: 1 addition & 1 deletion silhouette-cas/project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.6.2
sbt.version=1.9.7
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package io.github.honeycombcheesecake.play.silhouette.impl.providers
import io.github.honeycombcheesecake
import io.github.honeycombcheesecake.play.silhouette

import java.net.URL
import java.net.URI
import io.github.honeycombcheesecake.play.silhouette.api.exceptions.ConfigurationException
import io.github.honeycombcheesecake.play.silhouette.api.util.{ ExtractableRequest, HTTPLayer }
import io.github.honeycombcheesecake.play.silhouette.api.{ AuthInfo, Logger, LoginInfo }
Expand Down Expand Up @@ -244,7 +244,7 @@ final case class CasSettings(
* @param url The URL to validate.
* @return True if the URL is valid, false otherwise.
*/
private def isValidUrl(url: String): Boolean = Try(new URL(url)).isFailure
private def isValidUrl(url: String): Boolean = Try(new URI(url).toURL).isFailure
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import io.github.honeycombcheesecake.play.silhouette.api.{ Logger, LoginInfo }
import org.jasig.cas.client.authentication.AttributePrincipal
import org.specs2.mock.Mockito
import org.specs2.specification.Scope
import play.api.mvc.AnyContentAsEmpty
import play.api.test.FakeRequest
import test.SocialProviderSpec

Expand Down Expand Up @@ -68,7 +69,7 @@ class CasProviderSpec extends SocialProviderSpec[CasInfo] with Mockito with Logg

"The `authenticate` method" should {
"redirect to CAS server if service ticket is not present in request" in new Context {
implicit val req = FakeRequest(GET, "/")
implicit val req: FakeRequest[AnyContentAsEmpty.type] = FakeRequest(GET, "/")

result(provider.authenticate()) { result =>
status(result) must equalTo(SEE_OTHER)
Expand All @@ -77,7 +78,7 @@ class CasProviderSpec extends SocialProviderSpec[CasInfo] with Mockito with Logg
}

"redirect to CAS server with the original requested URL if service ticket is not present in the request" in new Context {
implicit val req = FakeRequest(GET, redirectURLWithOrigin)
implicit val req: FakeRequest[AnyContentAsEmpty.type] = FakeRequest(GET, redirectURLWithOrigin)

result(provider.authenticate()) { result =>
status(result) must equalTo(SEE_OTHER)
Expand All @@ -86,7 +87,7 @@ class CasProviderSpec extends SocialProviderSpec[CasInfo] with Mockito with Logg
}

"return a valid CASAuthInfo object if service ticket is present in request" in new Context {
implicit val req = FakeRequest(GET, "/?ticket=%s".format(ticket))
implicit val req: FakeRequest[AnyContentAsEmpty.type] = FakeRequest(GET, "/?ticket=%s".format(ticket))

authInfo(provider.authenticate())(authInfo => authInfo must be equalTo CasInfo(ticket))
}
Expand All @@ -98,7 +99,7 @@ class CasProviderSpec extends SocialProviderSpec[CasInfo] with Mockito with Logg
principal.getAttributes returns attr
client.validateServiceTicket(ticket) returns Future.successful(principal)

implicit val req = FakeRequest(GET, "/?ticket=%s".format(ticket))
implicit val req: FakeRequest[AnyContentAsEmpty.type] = FakeRequest(GET, "/?ticket=%s".format(ticket))

val futureProfile = for {
a <- provider.authenticate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ package object test {
* @tparam A The type of the body.
*/
implicit class FakeRequestWithAuthenticator[A](f: FakeRequest[A]) {
implicit val request = f
implicit val request: FakeRequest[A] = f

/**
* Creates a fake request with an embedded authenticator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.specs2.matcher.JsonMatchers
import org.specs2.specification.Scope
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.libs.json.Json
import play.api.mvc.{ AbstractController, ControllerComponents }
import play.api.mvc.{ AbstractController, AnyContentAsEmpty, ControllerComponents }
import play.api.test.{ FakeRequest, PlaySpecification, WithApplication }

import scala.concurrent.ExecutionContext.Implicits.global
Expand Down Expand Up @@ -129,44 +129,44 @@ class FakesSpec extends PlaySpecification with JsonMatchers {
"return a `SessionAuthenticator`" in new WithApplication {
val loginInfo = LoginInfo("test", "test")
val identity = FakeIdentity(loginInfo)
implicit val env = FakeEnvironment[SessionEnv](Seq(loginInfo -> identity))
implicit val request = FakeRequest()
implicit val env: FakeEnvironment[SessionEnv] = FakeEnvironment[SessionEnv](Seq(loginInfo -> identity))
implicit val request: FakeRequest[AnyContentAsEmpty.type] = FakeRequest()

FakeAuthenticator(loginInfo) must beAnInstanceOf[SessionAuthenticator]
}

"return a `CookieAuthenticator`" in new WithApplication {
val loginInfo = LoginInfo("test", "test")
val identity = FakeIdentity(loginInfo)
implicit val env = FakeEnvironment[CookieEnv](Seq(loginInfo -> identity))
implicit val request = FakeRequest()
implicit val env: FakeEnvironment[CookieEnv] = FakeEnvironment[CookieEnv](Seq(loginInfo -> identity))
implicit val request: FakeRequest[AnyContentAsEmpty.type] = FakeRequest()

FakeAuthenticator(loginInfo) must beAnInstanceOf[CookieAuthenticator]
}

"return a `BearerTokenAuthenticator`" in new WithApplication {
val loginInfo = LoginInfo("test", "test")
val identity = FakeIdentity(loginInfo)
implicit val env = FakeEnvironment[BearerTokenEnv](Seq(loginInfo -> identity))
implicit val request = FakeRequest()
implicit val env: FakeEnvironment[BearerTokenEnv] = FakeEnvironment[BearerTokenEnv](Seq(loginInfo -> identity))
implicit val request: FakeRequest[AnyContentAsEmpty.type] = FakeRequest()

FakeAuthenticator(loginInfo) must beAnInstanceOf[BearerTokenAuthenticator]
}

"return a `JWTAuthenticator`" in new WithApplication {
val loginInfo = LoginInfo("test", "test")
val identity = FakeIdentity(loginInfo)
implicit val env = FakeEnvironment[JWTEnv](Seq(loginInfo -> identity))
implicit val request = FakeRequest()
implicit val env: FakeEnvironment[JWTEnv] = FakeEnvironment[JWTEnv](Seq(loginInfo -> identity))
implicit val request: FakeRequest[AnyContentAsEmpty.type] = FakeRequest()

FakeAuthenticator(loginInfo) must beAnInstanceOf[JWTAuthenticator]
}

"return a `DummyAuthenticator`" in new WithApplication {
val loginInfo = LoginInfo("test", "test")
val identity = FakeIdentity(loginInfo)
implicit val env = FakeEnvironment[DummyEnv](Seq(loginInfo -> identity))
implicit val request = FakeRequest()
implicit val env: FakeEnvironment[DummyEnv] = FakeEnvironment[DummyEnv](Seq(loginInfo -> identity))
implicit val request: FakeRequest[AnyContentAsEmpty.type] = FakeRequest()

FakeAuthenticator(loginInfo) must beAnInstanceOf[DummyAuthenticator]
}
Expand All @@ -191,7 +191,7 @@ class FakesSpec extends PlaySpecification with JsonMatchers {
new WithApplication(app) {
val loginInfo = LoginInfo("test", "test")
val identity = FakeIdentity(loginInfo)
implicit val env = FakeEnvironment[CookieEnv](Seq(loginInfo -> identity))
implicit val env: FakeEnvironment[CookieEnv] = FakeEnvironment[CookieEnv](Seq(loginInfo -> identity))
val request = FakeRequest().withAuthenticator(LoginInfo("invalid", "invalid"))

val controller = app.injector.instanceOf[SecuredController]
Expand All @@ -205,7 +205,7 @@ class FakesSpec extends PlaySpecification with JsonMatchers {
new WithApplication(app) {
val loginInfo = LoginInfo("test", "test")
val identity = FakeIdentity(loginInfo)
implicit val env = FakeEnvironment[CookieEnv](Seq(loginInfo -> identity))
implicit val env: FakeEnvironment[CookieEnv] = FakeEnvironment[CookieEnv](Seq(loginInfo -> identity))
val request = FakeRequest().withAuthenticator(loginInfo)

val controller = app.injector.instanceOf[SecuredController]
Expand Down Expand Up @@ -236,7 +236,7 @@ class FakesSpec extends PlaySpecification with JsonMatchers {
new WithApplication(app) {
val loginInfo = LoginInfo("test", "test")
val identity = FakeIdentity(loginInfo)
implicit val env = FakeEnvironment[CookieEnv](Seq(loginInfo -> identity))
implicit val env: FakeEnvironment[CookieEnv] = FakeEnvironment[CookieEnv](Seq(loginInfo -> identity))
val request = FakeRequest().withAuthenticator(LoginInfo("invalid", "invalid"))

val controller = app.injector.instanceOf[SecuredController]
Expand All @@ -251,7 +251,7 @@ class FakesSpec extends PlaySpecification with JsonMatchers {
val loginInfo = LoginInfo("test", "test")
val identity = FakeIdentity(loginInfo)

implicit val env = FakeEnvironment[CookieEnv](Seq(loginInfo -> identity))
implicit val env: FakeEnvironment[CookieEnv] = FakeEnvironment[CookieEnv](Seq(loginInfo -> identity))
val request = FakeRequest().withAuthenticator(loginInfo)

val controller = app.injector.instanceOf[SecuredController]
Expand Down Expand Up @@ -281,7 +281,7 @@ class FakesSpec extends PlaySpecification with JsonMatchers {
/**
* The Silhouette environment.
*/
implicit val env = FakeEnvironment[CookieEnv](Seq(loginInfo -> identity))
implicit val env: FakeEnvironment[CookieEnv] = FakeEnvironment[CookieEnv](Seq(loginInfo -> identity))

/**
* The guice application builder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class GoogleTotpProviderSpec extends PasswordProviderSpec with Mockito {
"The `createCredentials` method" should {
"return the correct TotpCredentials shared key" in new WithApplication with Context {
val result = provider.createCredentials(credentials.identifier)
result.totpInfo.sharedKey must not be empty
result.totpInfo.sharedKey must not be ""
result.totpInfo.scratchCodes must not be empty
result.qrUrl must not be empty
result.qrUrl must not be ""
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class EventBus extends ActorEventBus with SubchannelClassification {
/**
* The logic to form sub-class hierarchy
*/
override protected implicit val subclassification = new Subclassification[Classifier] {
override protected implicit val subclassification: Subclassification[Classifier] = new Subclassification[Classifier] {
def isEqual(x: Classifier, y: Classifier): Boolean = x == y
def isSubclass(x: Classifier, y: Classifier): Boolean = y.isAssignableFrom(x)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.github.honeycombcheesecake.play.silhouette.api

import play.api.libs.json.Json
import play.api.libs.json.OFormat

/**
* Represents a linked login for an identity (i.e. a local username/password or a Facebook/Google account).
Expand All @@ -35,5 +36,5 @@ object LoginInfo extends ((String, String) => LoginInfo) {
/**
* Converts the [[io.github.honeycombcheesecake.play.silhouette.api.LoginInfo]] to Json and vice versa.
*/
implicit val jsonFormat = Json.format[LoginInfo]
implicit val jsonFormat: OFormat[LoginInfo] = Json.format[LoginInfo]
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import io.github.honeycombcheesecake.play.silhouette.api.services.AuthenticatorR
import io.github.honeycombcheesecake.play.silhouette.api.util.ExecutionContextProvider
import play.api.mvc.{ Result, RequestHeader, Request, AnyContent }

import scala.concurrent.ExecutionContext
import scala.concurrent.Future

/**
Expand Down Expand Up @@ -56,7 +57,7 @@ trait RequestHandlerBuilder[E <: Env, +R[_]] extends ExecutionContextProvider {
/**
* The execution context to handle the asynchronous operations.
*/
implicit lazy val executionContext = environment.executionContext
implicit lazy val executionContext: ExecutionContext = environment.executionContext

/**
* The environment instance to handle the request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package io.github.honeycombcheesecake.play.silhouette.api.services
import io.github.honeycombcheesecake.play.silhouette.api.util.{ ExtractableRequest, ExecutionContextProvider }
import io.github.honeycombcheesecake.play.silhouette.api.{ Authenticator, LoginInfo }
import play.api.http.HttpEntity
import play.api.libs.typedmap.TypedMap
import play.api.mvc._

import scala.concurrent.Future
Expand All @@ -44,7 +45,7 @@ import scala.concurrent.Future
* @param result The result to wrap.
*/
class AuthenticatorResult(result: Result)
extends Result(result.header, result.body, result.newSession, result.newFlash, result.newCookies) {
extends Result(result.header, result.body, result.newSession, result.newFlash, result.newCookies, result.attrs) {

/**
* Creates a new copy of a `AuthenticatorResult`.
Expand All @@ -61,8 +62,9 @@ class AuthenticatorResult(result: Result)
body: HttpEntity,
newSession: Option[Session],
newFlash: Option[Flash],
newCookies: Seq[Cookie]) = {
AuthenticatorResult(super.copy(header, body, newSession, newFlash, newCookies))
newCookies: Seq[Cookie],
attrs: TypedMap) = {
AuthenticatorResult(super.copy(header, body, newSession, newFlash, newCookies, attrs))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ trait DefaultRequestExtractors extends LowPriorityRequestExtractors {
* Tries to extract the value from query string and then it tries to extract the value from any
* content.
*/
implicit val anyContentExtractor = new RequestExtractor[AnyContent] {
implicit val anyContentExtractor: RequestExtractor[AnyContent] = new RequestExtractor[AnyContent] {
def extractString(name: String, parts: Option[Parts] = None)(implicit request: Request[AnyContent]) = {
fromDefaultParts(name, parts)
.orElse(request.body.asFormUrlEncoded.flatMap { body => fromFormUrlEncoded(name, body, parts) })
Expand All @@ -220,7 +220,7 @@ trait DefaultRequestExtractors extends LowPriorityRequestExtractors {
/**
* Tries to extract the value from query string and then from form url encoded body.
*/
implicit val formUrlEncodedExtractor = new RequestExtractor[Map[String, Seq[String]]] {
implicit val formUrlEncodedExtractor: RequestExtractor[Map[String, Seq[String]]] = new RequestExtractor[Map[String, Seq[String]]] {
def extractString(name: String, parts: Option[Parts] = None)(implicit request: Request[Map[String, Seq[String]]]) = {
fromDefaultParts(name, parts).orElse(fromFormUrlEncoded(name, request.body, parts))
}
Expand All @@ -229,7 +229,7 @@ trait DefaultRequestExtractors extends LowPriorityRequestExtractors {
/**
* Tries to extract the value from query string and then from Json body.
*/
implicit val jsonExtractor = new RequestExtractor[JsValue] {
implicit val jsonExtractor: RequestExtractor[JsValue] = new RequestExtractor[JsValue] {
def extractString(name: String, parts: Option[Parts] = None)(implicit request: Request[JsValue]) = {
fromDefaultParts(name, parts).orElse(fromJson(name, request.body, parts))
}
Expand All @@ -238,7 +238,7 @@ trait DefaultRequestExtractors extends LowPriorityRequestExtractors {
/**
* Tries to extract the value from query string and then from Xml body.
*/
implicit val xmlExtractor = new RequestExtractor[NodeSeq] {
implicit val xmlExtractor: RequestExtractor[NodeSeq] = new RequestExtractor[NodeSeq] {
def extractString(name: String, parts: Option[Parts] = None)(implicit request: Request[NodeSeq]) = {
fromDefaultParts(name, parts).orElse(fromXml(name, request.body, parts))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class CookieAuthenticatorService(
val combinedCookies = filteredCookies :+ cookie
val cookies = Cookies(combinedCookies)

request.withAttrs(request.attrs + RequestAttrKey.Cookies.bindValue(Cell(cookies)))
request.withAttrs(request.attrs.updated(RequestAttrKey.Cookies.bindValue(Cell(cookies))))
}

/**
Expand Down
Loading

0 comments on commit c6d2e62

Please sign in to comment.