This repository has been archived by the owner on Sep 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
72 additions
and
104 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
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
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,64 +1,45 @@ | ||
package controllers | ||
|
||
import com.mohiva.play.silhouette.api.Env | ||
import org.slf4j.Marker | ||
import play.api.MarkerContext | ||
import play.api.i18n.MessagesApi | ||
import play.api.mvc._ | ||
import utils.auth.DefaultEnv | ||
|
||
trait MyStuff | ||
|
||
case object ReallyMyStuff extends MyStuff | ||
|
||
trait MyRequestHeader extends MessagesRequestHeader with PreferredMessagesProvider { | ||
def myStuff: MyStuff | ||
} | ||
// Allow this request to be used as a marker context | ||
trait MyRequestHeader extends MessagesRequestHeader with PreferredMessagesProvider with MarkerContext | ||
|
||
class MyRequest[B]( | ||
val myStuff: MyStuff, | ||
request: Request[B], | ||
messagesApi: MessagesApi, | ||
) extends MessagesRequest[B](request, messagesApi) with MyRequestHeader | ||
messagesApi: MessagesApi | ||
) extends MessagesRequest[B](request, messagesApi) with MyRequestHeader { | ||
// Stubbed out here, but see marker context docs | ||
// https://www.playframework.com/documentation/2.8.x/ScalaLogging#Using-Markers-and-Marker-Contexts | ||
def marker: Option[Marker] = None | ||
} | ||
|
||
// Should be OOTB here | ||
trait MySecuredRequestHeader[E <: Env] extends RequestHeader { | ||
def identity: E#I | ||
def authenticator: E#A | ||
// XXX this should extend SecuredRequestHeader[DefaultEnv] here but not OOTB | ||
trait MySecuredRequestHeader extends RequestHeader { | ||
def identity: DefaultEnv#I | ||
def authenticator: DefaultEnv#A | ||
} | ||
|
||
class MySecuredRequest [E <: Env, B]( | ||
class MySecuredRequest[B]( | ||
request: Request[B], | ||
myStuff: MyStuff, | ||
messagesApi: MessagesApi, | ||
val identity: E#I, | ||
val authenticator: E#A | ||
) extends MyRequest(myStuff, request, messagesApi) with MySecuredRequestHeader[E] | ||
|
||
// Should be able to use an OOTB user aware request header | ||
trait MyUserAwareRequestHeader[E <: Env] extends RequestHeader { | ||
def identity: Option[E#I] | ||
def authenticator: Option[E#A] | ||
val identity: DefaultEnv#I, | ||
val authenticator: DefaultEnv#A, | ||
) extends MyRequest(request, messagesApi) with MySecuredRequestHeader | ||
|
||
// XXX this should extend UserAwareRequestHeader[DefaultEnv] here but not OOTB | ||
trait MyUserAwareRequestHeader extends RequestHeader { | ||
def identity: Option[DefaultEnv#I] | ||
def authenticator: Option[DefaultEnv#A] | ||
} | ||
|
||
class MyUserAwareRequest[E <: Env, B]( | ||
class MyUserAwareRequest[B]( | ||
request: Request[B], | ||
myStuff: MyStuff, | ||
messagesApi: MessagesApi, | ||
val identity: Option[E#I], | ||
val authenticator: Option[E#A] | ||
) extends MyRequest(myStuff, request, messagesApi) with MyUserAwareRequestHeader[E] | ||
|
||
|
||
object Foo { | ||
import com.mohiva.play.silhouette.api.actions.{SecuredRequest => OrigSecuredRequest} | ||
|
||
// Can't treat MyRequest as instance of SecuredRequest even though they both | ||
// return identity & authentiator, must lose info and instantiate new request | ||
// Note also that we're returning instance and there is no interface | ||
// so can't do this: | ||
// | ||
// def createInstance[E <: Env, A](request: MySecuredRequest[E, A]): SecuredRequest[E, A] = | ||
// request.asInstanceOf[SecuredRequest[E,A]] | ||
// | ||
def createInstance[E <: Env, A](request: MySecuredRequest[E, A]): OrigSecuredRequest[E, A] = { | ||
OrigSecuredRequest(request.identity, request.authenticator, request) | ||
} | ||
} | ||
val identity: Option[DefaultEnv#I], | ||
val authenticator: Option[DefaultEnv#A] | ||
) extends MyRequest(request, messagesApi) with MyUserAwareRequestHeader |
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
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
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
Oops, something went wrong.