scala - 由于隐式参数错误,删除身份验证信息失败
问题描述
我正在使用 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
,在我看来这是错误的,但我不完全理解发生了什么,或者预期会发生什么。
- 应该如何
AuthInfoRepository#remove
正确称呼?我是否需要手动将ClassTag
对象放入正确的上下文以避免Nothing
被推断? - 为什么隐式
ClassTag
参数甚至相关?
解决方案
为什么隐式
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))
推荐阅读
- python - Python - 简单的 for 循环无法按预期工作(使用请求模块)
- ruby-on-rails - 带有接受单选按钮的嵌套属性
- c - 配置 $(CC) 以在包含可以安全删除时发出警告
- angular - ngOnChanges 没有被触发
- authorization - Postman 上的授权类型 Bearer Token
- parse-platform - 有没有办法限制查询中对象返回的键?
- javascript - 查找隐藏的父元素jQuery
- java - Java 正则表达式匹配范围内的数字
- c# - 使用 Prism 时如何允许 WPF 为 Window 控件解析 ContentTemplate?
- javascript - 如何使用角度动画始终将其向一个方向移动?