我正在尝试做与this类似的事情。 ContextRequest
和ContextAction
。我有一个来自securedRequest
的{{1}},我想撰写一个Silhouette
来阅读我设置的Action
。
区别在于我从剪影cookie
扩展了User
Identity
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
}
,因为
(请注意com.mohiva.play.silhouette.api.Identity与模型不匹配。用户:类包实体中的用户是包api中特征标识的子类,但是方法参数类型必须完全匹配。)>
我知道我可能缺少包装纸。
答案 0 :(得分:1)
尝试提供绑定到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
}
答案 1 :(得分:0)
我在请求请求中添加了一些功能,这些功能应该执行相同的操作https://github.com/mohiva/play-silhouette-seed/pull/118