我正在尝试创建Environment
inSilhouette
但无法创建。我已经定义了Identity
andAuthenticator
如下
trait SessionEnv extends Env {
type I = User
type A = SessionAuthenticator
}
接下来,我想我必须创建Environment
. 为此,我编写了以下代码,但我坚持,因为我不明白如何传递Environment
'sapply
方法预期的不同参数
环境伴生对象的应用方法有签名
def apply[E <: Env](
identityServiceImpl: IdentityService[E#I],
authenticatorServiceImpl: AuthenticatorService[E#A],
requestProvidersImpl: Seq[RequestProvider],
eventBusImpl: EventBus
我知道我必须提供IdentityService
. 我已经这样做了
class UserService @Inject()(userDao:UsersRepository) extends IdentityService[User] {...}
用户定义如下
case class UserProfile(
loginInfo:LoginInfo,
confirmed: Boolean,
email:Option[String],
firstName: Option[String],
lastName: Option[String],
passwordInfo:Option[PasswordInfo]
//oauth1Info: Option[OAuth1Info],
//avatarUrl: Option[String]) {
)
//representation of a user. A user has an Id and a profile
case class User (id:UUID, profile:UserProfile)
但是对于应用所需的其他值,我应该传递什么-authenticatorServiceImpl:AuthenticatorService[E#A],requestProvidersImpl:Seq[RequestProvider],eventBusImpl:EventBus
val sessionEnv = com.mohiva.play.silhouette.api.Environment[SessionEnv](new UserService(userRepository),????)
另外,我想我不必使用Guice
,因为我正在使用编译时注入。那是对的吗?
更新我从更改SessionAuthenticatorService
为CookieAuthenticatorService
尝试一些在线可用的代码。
似乎我对Silhouette
提供一些默认实现的理解并不完全正确。我以为我可以简单地使用中SessionAuthenticatorService
定义的伴随对象,https://github.com/mohiva/play-silhouette/blob/master/silhouette/app/com/mohiva/play/silhouette/impl/authenticators/SessionAuthenticator.scala
但事实并非如此。查看在 中创建的一些代码ScalaModule
,似乎我必须自己创建所需的对象,但我需要在我的 AppLoader 类(用于编译时 DI)而不是 ScalaModule(用于运行时 DI)中创建。但是,我仍然没有解决问题。我不知道如何创建signer
所需的CookieAuthenticatorService
val config = configuration.underlying.asInstanceOf[CookieAuthenticatorSettings]("silhouette.authenticator")
val fingerprintGenerator = new DefaultFingerprintGenerator(false)
val idGenerator = new SecureRandomIDGenerator()
val clock:Clock = Clock()
val authenticatorService: AuthenticatorService[CookieAuthenticator] = new CookieAuthenticatorService(config,None,,,fingerprintGenerator, idGenerator,clock) //STILL NEED TO FIND OUT HOW TO CREATE Signer AND CookieHeaderEncoding required by CookieAuthenticator service
val cookieEnv = com.mohiva.play.silhouette.api.Environment[CookieEnv](userIdentityService ,authenticatorService,Seq(),EventBus())