我已经建立了带有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都有标记的成功的auth,这意味着keycloak/google原则上起作用。问题在于,在重定向回CAS之后,会话已经结束。上下文中的会话存储为空。因此,状态为null,不能与TST匹配。当我在withState = false中设置pac4j时,一切都可以工作,但我希望使用状态来实现安全。
在这个pac4j google组中的问题中,有人遇到了同样的问题,因为他没有使用标准端口,我也是这样做的。但是改到80/443并不能解决我的问题。我在带有本地主机上自签名ssl证书的tomcat 9中运行。
还有其他建议吗?
编辑
我几乎可以肯定,问题是来自外部的猫。但到目前为止,我还没有找到关于如何正确设置外部tomcat的工作文档。欢迎你提出建议。
更新
像cas-server-support-oauth-webflow这样的接缝正在破坏pac4j流。如果我删除了这个依赖项,它就能工作。不知道是个窃听器还是应该是那样的。没有OAuth,我就无法获得用于Ldap/数据库的access_token。
发布于 2020-02-03 16:38:05
我也遇到了同样的问题,并设法用v6.2.0-RC2版本的cas来处理它。加后
cas.authn.pac4j.replicateSessions=false在我的etc/cas/config/cas.properties中,它为我解决了问题。
# 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 /**
* 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://stackoverflow.com/questions/59659637
复制相似问题