【问题标题】:CAS 6.1 - State Parameter null with Pac4JCAS 6.1 - Pac4J 的状态参数为空
【发布时间】:2020-04-26 19:15:57
【问题描述】:

我已经使用 LDAP/AD 和数据库设置了 CAS,它可以工作。现在我想添加 Keycloak,但我得到了一个关于状态的异常。

Caused by: org.pac4j.core.exception.TechnicalException: State parameter is different from the one sent in authentication request. Session expired or possible threat of cross-site request forgery

为了测试我添加了谷歌,但出现了类似的问题。

DEBUG [org.pac4j.oauth.credentials.extractor.OAuth20CredentialsExtractor] - <sessionState: null / stateParameter: Optional[TST-1-v1va-S-4rLb45kax1568WxwP5aX-q2X]>
INFO [org.pac4j.oauth.client.Google2Client] - <Failed to retrieve or validate credentials: State parameter mismatch: session expired or possible threat of cross-site request forgery>

我可以在日志中看到 keyloak/google 的成功身份验证,这意味着 keycloak/google 原则上工作。问题接缝是,在重定向回 CAS 之后,会话已经结束。上下文中的会话存储是空的。因此,状态为空,无法匹配到 TST。当我在 pac4j 中设置 withState = false 时,一切正常,但我想使用状态来保证安全。

在这个question in a pac4j google group,有人遇到了同样的问题,因为他没有使用标准端口,我也是。但是更改为 80/443 并没有为我解决问题。我在 localhost 上使用自签名 ssl 证书在 tomcat 9 中运行。

还有其他建议吗?

编辑
我几乎可以肯定,问题出在外部tomcat上。但到目前为止,我还没有找到关于如何正确设置外部 tomcat 的工作文档。欢迎提出建议。

更新
cas-server-support-oauth-webflow 这样的接缝正在破坏 pac4j 网络流。如果我删除此依赖项,它将起作用。不知道这是一个错误还是应该以这种方式工作。如果没有 OAuth-Webflow,我将无法获得 Ldap/数据库的 access_token。

【问题讨论】:

    标签: keycloak google-oauth cas pac4j apereo


    【解决方案1】:

    我遇到了同样的问题,并设法使用v6.2.0-RC2 版本的 cas 处理它。 添加后

    cas.authn.pac4j.replicateSessions=false
    

    进入我的etc/cas/config/cas.properties,它为我解决了问题。

    来自https://github.com/apereo/cas/blob/v6.2.0-RC2/docs/cas-server-documentation/configuration/Configuration-Properties.md#pac4j-delegated-authn

    # cas.authn.pac4j.typedIdUsed=false
    # cas.authn.pac4j.principalAttributeId=
    # cas.authn.pac4j.name=
    # cas.authn.pac4j.order=
    # cas.authn.pac4j.lazyInit=true
    # cas.authn.pac4j.replicateSessions=true
    

    来自https://github.com/apereo/cas/blob/v6.2.0-RC2/api/cas-server-core-api-configuration-model/src/main/java/org/apereo/cas/configuration/model/support/pac4j/Pac4jDelegatedAuthenticationProperties.java#L58

     /**
     * Indicates whether profiles and other session data,
     * collected as part of pac4j flows and requests
     * that are kept by the container session, should be replicated
     * across the cluster using CAS and its own ticket registry.
     * Without this option, profile data and other related
     * pieces of information should be manually replicated
     * via means and libraries outside of CAS.
     */
     private boolean replicateSessions = true;
    

    警告 - 此属性的默认值为 true,不建议将集群更改为 false

    【讨论】:

      猜你喜欢
      • 2020-03-02
      • 1970-01-01
      • 2020-07-08
      • 2020-07-10
      • 2021-12-22
      • 2021-01-05
      • 1970-01-01
      • 1970-01-01
      • 2019-04-07
      相关资源
      最近更新 更多