CAS 6.1-Pac4J

我已经使用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

为了进行测试,我添加了Google,但是发生了类似的问题。

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之后,会话已经结束。上下文中的会话存储为空。因此,状态为null,无法与TST匹配。当我在pac4j中设置withState = false时,一切正常,但是我想使用状态来提高安全性。

在此question in a pac4j google group中,有人遇到了相同的问题,因为他没有使用标准端口,而我也这样做。但是更改为80/443并不能解决我的问题。我正在使用本地主机上具有自签名ssl证书的tomcat 9中运行。

还有其他建议吗?

修改
我几乎可以肯定,问题来自外部tomcat。但是到目前为止,我还没有找到有关如何正确设置外部tomcat的有效文档。公开征求意见。

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

gaochong0908 回答:CAS 6.1-Pac4J

我遇到了同样的问题,并设法使用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

本文链接:https://www.f2er.com/2799365.html

大家都在问