首页 > 解决方案 > 由于隐式参数错误,删除身份验证信息失败

问题描述

我正在使用 Silhouette 来管理我的 Play 应用程序中的身份验证。注册,登录和授权工作正常。但是,当尝试注销(= 删除)用户帐户时,删除相应的身份验证信息会失败。

特别是,以下行会引发异常:

authInfoRepository.remove(LoginInfo(credentialsProvider.id, username))

authInfoRepository是一个注入的AuthInfoRepository,它被配置为一个DelegableAuthInfoRepository

例外:

com.mohiva.play.silhouette.api.exceptions.ConfigurationException: Cannot remove auth info of type: class scala.runtime.Nothing$; Please configure the DAO for this type
at com.mohiva.play.silhouette.persistence.repositories.DelegableAuthInfoRepository.remove(DelegableAuthInfoRepository.scala:115)
[...]

查看有问题的方法,它需要一个隐式参数implicit tag: ClassTag[T]。那个最终以某种方式结束Nothing,在我看来这是错误的,但我不完全理解发生了什么,或者预期会发生什么。

标签: scalaplayframeworksilhouette

解决方案


为什么隐式ClassTag参数甚至相关?

ClassTag是相关的,因为remove期望这样的隐含:https ://github.com/mohiva/play-silhouette/blob/master/silhouette-persistence/src/main/scala/com/mohiva/play/silhouette/persistence/repositories/DelegableAuthInfoRepository.scala #L104-L118

我是否需要手动将ClassTag对象放入正确的上下文以避免Nothing被推断?

我猜反之亦然,您应该指定T(没有这样的指定,T现在推断为Nothing)并且会找到适当的隐式。

尝试以下选项之一:

authInfoRepository.remove[CasInfo](LoginInfo(credentialsProvider.id, username))
authInfoRepository.remove[OAuth1Info](LoginInfo(credentialsProvider.id, username))
authInfoRepository.remove[OAuth2Info](LoginInfo(credentialsProvider.id, username))
authInfoRepository.remove[OpenIDInfo](LoginInfo(credentialsProvider.id, username))
authInfoRepository.remove[PasswordInfo](LoginInfo(credentialsProvider.id, username))

推荐阅读