播放 2.6 Silhouette compose SecuredAction
Play 2.6 Silhouette compose SecuredAction
我正在尝试做一些与 this 非常相似的事情。 ContextRequest
和 ContextAction
。我有一个来自 Silhouette
的 securedRequest
,我想写一个 Action
读一个 cookie
我设置的
不同之处在于我从 Silhouette Identity
扩展了 User
DataSourceRequest
class DataSourceRequest[DefaultEnv, B](
val dataSource: Option[String],
val securedRequest: SecuredRequest[DefaultEnv, B]
) extends WrappedRequest[B](securedRequest.request) {
def user: User = securedRequest.identity
def requestV: Request[B] = securedRequest.request
}
DataSourceAction
class DataSourceAction @Inject()
(val parser: BodyParsers.Default)(implicit val executionContext: ExecutionContext)
extends ActionRefiner[({ type R[B] = SecuredRequest[DefaultEnv, B] })#R, ({ type R[B] = DataSourceRequest[DefaultEnv, B] })#R] {
override protected def refine[A](securedRequest: SecuredRequest[DefaultEnv, A]) = Future.successful {
try {
Right(new DataSourceRequest[DefaultEnv, A](
securedRequest.session.get("dataSource").getOrElse("dataSourceMissing"),
securedRequest
))
} catch {
case _: Exception => Left(Results.NotFound)
}
}
}
DefaultEnv
trait DefaultEnv extends Env {
type I = User
type A = CookieAuthenticator
}
我无法获得 User
因为
(Note that com.mohiva.play.silhouette.api.Identity does not match models.User: class User in package entities is a subclass of trait Identity in package api, but method parameter types must match exactly.)
我知道我可能缺少包装纸。
尝试为您的 Env
提供上下文绑定,如下所示:
class DataSourceRequest[Env <: DefaultEnv, B](
val dataSource: Option[String],
val securedRequest: SecuredRequest[Env, B]
) extends WrappedRequest[B](securedRequest.request) {
def user: User = securedRequest.identity
def requestV: Request[B] = securedRequest.request
}
我在拉取请求中添加了一些应该做同样事情的功能https://github.com/mohiva/play-silhouette-seed/pull/118
我正在尝试做一些与 this 非常相似的事情。 ContextRequest
和 ContextAction
。我有一个来自 Silhouette
的 securedRequest
,我想写一个 Action
读一个 cookie
我设置的
不同之处在于我从 Silhouette Identity
User
DataSourceRequest
class DataSourceRequest[DefaultEnv, B](
val dataSource: Option[String],
val securedRequest: SecuredRequest[DefaultEnv, B]
) extends WrappedRequest[B](securedRequest.request) {
def user: User = securedRequest.identity
def requestV: Request[B] = securedRequest.request
}
DataSourceAction
class DataSourceAction @Inject()
(val parser: BodyParsers.Default)(implicit val executionContext: ExecutionContext)
extends ActionRefiner[({ type R[B] = SecuredRequest[DefaultEnv, B] })#R, ({ type R[B] = DataSourceRequest[DefaultEnv, B] })#R] {
override protected def refine[A](securedRequest: SecuredRequest[DefaultEnv, A]) = Future.successful {
try {
Right(new DataSourceRequest[DefaultEnv, A](
securedRequest.session.get("dataSource").getOrElse("dataSourceMissing"),
securedRequest
))
} catch {
case _: Exception => Left(Results.NotFound)
}
}
}
DefaultEnv
trait DefaultEnv extends Env {
type I = User
type A = CookieAuthenticator
}
我无法获得 User
因为
(Note that com.mohiva.play.silhouette.api.Identity does not match models.User: class User in package entities is a subclass of trait Identity in package api, but method parameter types must match exactly.)
我知道我可能缺少包装纸。
尝试为您的 Env
提供上下文绑定,如下所示:
class DataSourceRequest[Env <: DefaultEnv, B](
val dataSource: Option[String],
val securedRequest: SecuredRequest[Env, B]
) extends WrappedRequest[B](securedRequest.request) {
def user: User = securedRequest.identity
def requestV: Request[B] = securedRequest.request
}
我在拉取请求中添加了一些应该做同样事情的功能https://github.com/mohiva/play-silhouette-seed/pull/118