【发布时间】:2014-06-03 09:43:55
【问题描述】:
我正在使用 Play 框架 2.2.x 和 SecureSocial 并且为了测试,我正在尝试覆盖超类中的方法。实际上,我在使用来自安全社交的测试帮助程序类时遇到了编译错误,我无法弄清楚,因为我对 Scala 并不那么熟悉。
我不明白为什么我的 ide 方法被正确覆盖但是当我编译时出现错误。我知道 scala 与 ides 的集成度不是很好,但我看不出为什么覆盖不正确。
/**
* This is the secure social class and method I am trying to override.
I have left the other methods out for clarity. The problem method is the doAuth method
**/
包securesocial.core
import providers.utils.RoutesHelper
import play.api.mvc.{SimpleResult, AnyContent, Request}
import play.api.{Play, Application, Plugin}
import concurrent.{Await, Future}
import play.api.libs.ws.Response
abstract class IdentityProvider(application: Application) extends Plugin with Registrable {
/**
* Subclasses need to implement the authentication logic. This method needs to return
* a User object that then gets passed to the fillProfile method
*
* @param request
* @return Either a Result or a User
* This is the method I am having trouble trying to override
*/
def doAuth()(implicit request: Request[AnyContent]):Either[SimpleResult, SocialUser]
}
这是我的类和 doAuth() 覆盖 打包测试包
import play.api.Logger
import securesocial.core._
import play.api.mvc.{Result, Request}
import securesocial.core.IdentityId
class AlwaysValidIdentityProvider(app:play.api.Application) extends IdentityProvider(app){
val logger = Logger("securesocial.stubs.AlwaysValidIdentityProvider")
def authMethod: AuthenticationMethod = AuthenticationMethod("naive")
override def doAuth()(implicit request: Request[play.api.mvc.AnyContent]): Either[Result, SocialUser] ={
val userId = request.body.toString
val r =Right(SocialUserGenerator.socialUserGen(IdentityId(userId, id), authMethod).sample.get)
r
}
def fillProfile(user: SocialUser): SocialUser = {
user
}
def id: String = "naive"
}
我得到的错误是:如您所见,它认为我没有覆盖任何内容。
[error] /Users/zola/Development/play/receipt-manager/rm-play/test/testkit/AlwaysValidIdentityProvider.scala:8: class AlwaysValidIdentityProvider needs to be abstract, since method doAuth in class IdentityProvider of type [A]()(implicit request: play.api.mvc.Request[A])Either[play.api.mvc.Result,securesocial.core.SocialUser] is not defined
[error] class AlwaysValidIdentityProvider(app:play.api.Application) extends IdentityProvider(app){
[error] ^
[error] /Users/zola/Development/play/receipt-manager/rm-play/test/testkit/AlwaysValidIdentityProvider.scala:13: method doAuth overrides nothing.
[error] Note: the super classes of class AlwaysValidIdentityProvider contain the following, non final members named doAuth:
[error] def doAuth[A]()(implicit request: play.api.mvc.Request[A]): Either[play.api.mvc.Result,securesocial.core.SocialUser]
[error] override def doAuth()(implicit request: Request[play.api.mvc.AnyContent]): Either[Result, SocialUser] ={
[error] ^
[error] two errors found
【问题讨论】:
-
不是因为返回类型不同吗?例如。
Result和SimpleResult.
标签: scala playframework securesocial