加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 如何使用Play Silhouette实现无状态cookie身份验证?

发布时间:2020-12-16 18:14:17 所属栏目:安全 来源:网络整理
导读:以下链接表示您可以将CookieAuthenticator用作无状态或有状态. http://silhouette.mohiva.com/docs/authenticator 但我看不到任何选项可以在下面的链接做出选择. http://silhouette.mohiva.com/v3.0/docs/config-authenticators#cookieauthenticator 我已经
以下链接表示您可以将CookieAuthenticator用作无状态或有状态.

http://silhouette.mohiva.com/docs/authenticator

但我看不到任何选项可以在下面的链接做出选择.

http://silhouette.mohiva.com/v3.0/docs/config-authenticators#cookieauthenticator

我已经复制了以下示例的实现.这是无国籍还是有状态的?如果有状态我如何实现无状态身份验证?

https://github.com/mohiva/play-silhouette-seed

解决方法

这一切都是正确的.

查看github上的CookieAuthenticator.scala源代码:https://github.com/mohiva/play-silhouette/blob/master/silhouette/app/com/mohiva/play/silhouette/impl/authenticators/CookieAuthenticator.scala

/**
 * The service that handles the cookie authenticator.
 *
 * @param settings The cookie settings.
 * @param repository The repository to persist the authenticator. Set it to None to use a stateless approach.
 * @param fingerprintGenerator The fingerprint generator implementation.
 * @param idGenerator The ID generator used to create the authenticator ID.
 * @param clock The clock implementation.
 * @param executionContext The execution context to handle the asynchronous operations.
 */
class CookieAuthenticatorService(
  settings: CookieAuthenticatorSettings,repository: Option[AuthenticatorRepository[CookieAuthenticator]],fingerprintGenerator: FingerprintGenerator,idGenerator: IDGenerator,clock: Clock)(implicit val executionContext: ExecutionContext)
  extends AuthenticatorService[CookieAuthenticator]

因此,您只需要在定义的存储库中创建CookieAuthenticatorService.

在您的示例中,您可以找到一个字符串

new CookieAuthenticatorService(config,None,fingerprintGenerator,idGenerator,clock)

此处的存储库参数为None,因此CookieAuthenticator是无状态的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读